1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
typedef struct BD BD;
typedef struct CPMdev CPMdev;
typedef struct GTimer GTimer;
typedef struct I2Cdev I2Cdev;
typedef struct PCMconftab PCMconftab;
typedef struct PCMmap PCMmap;
typedef struct PCMslot PCMslot;
typedef struct Ring Ring;
/*
* MPC800 series IO structures
*/
enum
{
/* interrupt vectors (SIU and CPM) */
VectorPIC= 0, /* level 0 to level 7, assigned by software */
/* vector assignments are determined by the assignments here */
PITlevel= 2,
CPIClevel= 4,
PCMCIAio= 5,
PCMCIAstatus= 6,
RTClevel= 7,
VectorIRQ= VectorPIC+8, /* IRQ0 to IRQ7 */
VectorCPIC= VectorIRQ+8, /* 32 CPM interrupts: 0 (error) to 0x1F (PC15) */
MaxVector= VectorCPIC+32,
};
/*
* these are defined to keep the interface compatible with other
* architectures, but only BUSUNKNOWN is currently used
*/
#define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
#define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
#define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
#define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
#define BUSTYPE(tbdf) ((tbdf)>>24)
#define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
#define BUSUNKNOWN (-1)
/*
* Buffer Descriptors and IO Rings
*/
struct BD {
ushort status;
ushort length;
ulong addr;
};
BD* bdalloc(int);
void bdfree(BD*, int);
void dumpbd(char*, BD*, int);
enum {
/* Rx BDs, bits common to all protocols */
BDEmpty= 1<<15,
BDWrap= 1<<13,
BDInt= 1<<12,
BDLast= 1<<11,
BDFirst= 1<<10,
/* Tx BDs */
BDReady= 1<<15,
/* BDWrap, BDInt, BDLast */
};
struct Ring {
BD* rdr; /* receive descriptor ring */
void* rrb; /* receive ring buffers */
int rdrx; /* index into rdr */
int nrdre; /* length of rdr */
BD* tdr; /* transmit descriptor ring */
Block** txb; /* corresponding transmit ring buffers */
int tdrh; /* host index into tdr */
int tdri; /* interface index into tdr */
int ntdre; /* length of tdr */
int ntq; /* pending transmit requests */
};
#define NEXT(x, l) (((x)+1)%(l))
#define PREV(x, l) (((x) == 0) ? (l)-1: (x)-1)
#define HOWMANY(x, y) (((x)+((y)-1))/(y))
#define ROUNDUP(x, y) (HOWMANY((x), (y))*(y))
int ioringinit(Ring*, int, int, int);
/*
* CPM
*/
enum {
/* commands */
InitRxTx = 0,
InitRx = 1,
InitTx = 2,
EnterHunt= 3,
StopTx= 4,
GracefulStopTx = 5,
InitIDMA = 5,
RestartTx = 6,
CloseRxBD = 7,
SetGroupAddr = 8,
SetTimer = 8,
GCITimeout = 9,
GCIAbort = 10,
StopIDMA = 11,
StartDSP = 12,
ArmIDMA = 13,
InitDSP = 13,
USBCmd = 15,
/* bgcr */
BaudEnable = 1<<16,
/* sicr */
CLK1 = 4, /* SCC1,2 */
CLK2 = 5,
CLK3 = 6,
CLK4 = 7,
CLK5 = CLK1, /* SCC3,4 */
CLK6 = CLK2,
CLK7 = CLK3,
CLK8 = CLK4,
/* logical channel IDs mapped to channel ID by cpm.c */
CPnone = 0,
CPscc1,
CPscc2,
CPscc3,
CPscc4,
CPsmc1,
CPsmc2,
CPdsp1,
CPdsp2,
CPidma1,
CPidma2,
CPtimer,
CPspi,
CPi2c,
CPmax,
};
struct CPMdev {
int id; /* CPM channel number */
int irq; /* CPIC interrupt number */
int rbase; /* register offset in IO mem */
int pbase; /* parameter offset in IO mem */
void* regs; /* kernel address of registers */
void* param; /* kernel address of parameters */
};
CPMdev* cpmdev(int);
void cpmop(CPMdev*, int, int);
void* cpmalloc(int, int);
void cpmfree(void*, int);
IMM* ioplock(void);
void iopunlock(void);
int cpmidopen(int, void*);
void cpmidclose(int);
void sccnmsi(int, int, int);
void sccxstop(CPMdev*);
void smcnmsi(int, int);
void smcxstop(CPMdev*);
/*
* CPM timers
*/
enum {
/* timer modes */
CaptureRise= 1<<6,
CaptureFall= 2<<6,
CaptureEdge= 3<<6,
TimerToggle= 1<<5, /* toggle TOUTx* pin */
TimerORI= 1<<4, /* Output Reference Interrupt */
TimerRestart= 1<<3,
TimerSclk= 1<<1,
TimerSclk16= 2<<1,
TimerTIN= 3<<1, /* clock by falling edge of TINx */
TimerGate= 1<<0, /* TGATE1* controls timer */
/* timer events */
TimerREF= 1<<1,
TimerCAP= 1<<0
};
struct GTimer{
int x;
int inuse;
int event;
ushort* tmr;
ushort* trr;
ushort* tcr;
ushort* tcn;
ushort* ter;
void* arg;
void (*interrupt)(Ureg*, void*, GTimer*);
};
GTimer* gtimer(ushort, ushort, void (*)(Ureg*,void*,GTimer*), void*);
void gtimerset(GTimer*, ushort, int);
void gtimerstart(GTimer*);
void gtimerstop(GTimer*);
void gtimerfree(GTimer*);
/*
* the structures below follow hardware/firmware layouts in the 8xx manuals:
* mind the data types, offsets and alignment
*/
/*
* basic IO controller parameters (SMC and SCC)
*/
typedef struct IOCparam IOCparam;
struct IOCparam {
ushort rbase;
ushort tbase;
uchar rfcr;
uchar tfcr;
ushort mrblr;
ulong rstate;
ulong rptr;
ushort rbptr;
ushort rcnt;
ulong rtmp;
ulong tstate;
ulong tptr;
ushort tbptr;
ushort tcnt;
ulong ttmp;
};
typedef struct SCCparam SCCparam;
struct SCCparam {
IOCparam;
ulong rcrc;
ulong tcrc;
};
typedef struct SCC SCC;
struct SCC {
ulong gsmrl;
ulong gsmrh;
ushort psmr;
uchar rsvscc0[2];
ushort todr;
ushort dsr;
ushort scce;
uchar rsvscc1[2];
ushort sccm;
uchar rsvscc3;
uchar sccs;
ushort irmode;
ushort irsip;
};
typedef struct SMC SMC;
struct SMC {
uchar pad1[2];
ushort smcmr;
uchar pad2[2];
uchar smce;
uchar pad3[3];
uchar smcm;
uchar pad4[5];
};
typedef struct SPI SPI;
struct SPI {
ushort spmode;
uchar res1[4];
uchar spie;
uchar res2[3];
uchar spim;
uchar res3[2];
uchar spcom;
uchar res4[10];
};
typedef struct USB USB;
struct USB { /* 823 only */
uchar usmod;
uchar usadr;
uchar uscom;
uchar rsvu1;
ushort usep[4];
uchar rsvu2[4];
ushort usber;
uchar rsvu3[2];
ushort usbmr;
uchar rsvu4;
uchar usbs;
uchar rsvu5[8];
};
typedef struct IMM IMM;
struct IMM {
struct { /* general SIU */
ulong siumcr;
ulong sypcr;
uchar rsv0[0xE-0x8];
ushort swsr;
ulong sipend;
ulong simask;
ulong siel;
uchar sivec;
uchar padv[3];
ulong tesr;
uchar rsv1[0x30-0x24];
ulong sdcr;
uchar rsv2[0x80-0x34];
};
struct { /* PCMCIA */
struct {
ulong base;
ulong option;
} pcmr[8];
uchar rsv3[0xe0-0xc0];
ulong pgcr[2];
ulong pscr;
uchar rsv4[0xf0-0xec];
ulong pipr;
uchar rsv5[4];
ulong per;
uchar rsv6[4];
};
struct { /* MEMC */
struct {
ulong base;
ulong option;
} memc[8];
uchar rsv7a[0x24];
ulong mar;
ulong mcr;
uchar rsv7b[4];
ulong mamr;
ulong mbmr;
ushort mstat;
ushort mptpr;
ulong mdr;
uchar rsv7c[0x80];
};
struct { /* system integration timers */
ushort tbscr;
uchar rsv8a[2];
ulong tbrefu;
ulong tbrefl;
uchar rsv8b[0x14];
ushort rtcsc;
uchar rsv8c[2];
ulong rtc;
ulong rtsec;
ulong rtcal;
uchar rsv8d[0x10];
ushort piscr;
ushort rsv8e;
ulong pitc;
ulong pitr;
uchar rsv8f[0x34];
};
struct { /* 280: clocks and resets */
ulong sccr;
ulong plprcr;
ulong rsr;
uchar rsv9[0x300-0x28c];
};
struct { /* 300: system integration timers keys */
ulong tbscrk;
ulong tbrefuk;
ulong tbreflk;
ulong tbk;
uchar rsv10a[0x10];
ulong rtcsck;
ulong rtck;
ulong rtseck;
ulong rtcalk;
uchar rsv10b[0x10];
ulong piscrk;
ulong pitck;
uchar rsv10c[0x38];
};
struct { /* 380: clocks and resets keys */
ulong sccrk;
ulong plprcrk;
ulong rsrk;
uchar rsv11[0x800-0x38C];
};
struct { /* 800: video controller */
ushort vccr;
ushort pad11a;
uchar vsr;
uchar pad11b;
uchar vcmr;
uchar pad11c;
ulong vbcb;
ulong pad11d;
ulong vfcr0;
ulong vfaa0;
ulong vfba0;
ulong vfcr1;
ulong vfaa1;
ulong vfba1;
uchar rsv11a[0x840-0x828];
};
struct { /* 840: LCD */
ulong lccr;
ulong lchcr;
ulong lcvcr;
ulong rsv11b;
ulong lcfaa;
ulong lcfba;
uchar lcsr;
uchar rsv11c[0x860-0x859];
};
struct { /* 860: I2C */
uchar i2mod;
uchar rsv12a[3];
uchar i2add;
uchar rsv12b[3];
uchar i2brg;
uchar rsv12c[3];
uchar i2com;
uchar rsv12d[3];
uchar i2cer;
uchar rsv12e[3];
uchar i2cmr;
uchar rsv12[0x900-0x875];
};
struct { /* 900: DMA */
uchar rsv13[4];
ulong sdar;
uchar sdsr;
uchar pad1[3];
uchar sdmr;
uchar pad2[3];
uchar idsr1;
uchar pad3[3];
uchar idmr1;
uchar pad4[3];
uchar idsr2;
uchar pad5[3];
uchar idmr2;
uchar pad6[0x930-0x91D];
};
struct { /* CPM interrupt control */
ushort civr;
uchar pad7[0x940-0x932];
ulong cicr;
ulong cipr;
ulong cimr;
ulong cisr;
};
struct { /* input/output port */
ushort padir;
ushort papar;
ushort paodr;
ushort padat;
uchar pad8[8];
ushort pcdir;
ushort pcpar;
ushort pcso;
ushort pcdat;
ushort pcint;
uchar pad9[6];
ushort pddir;
ushort pdpar;
ushort rsv14a;
ushort pddat;
uchar rsv14[0x980-0x978];
};
struct { /* CPM timers */
ushort tgcr;
uchar rsv15a[0x990-0x982];
ushort tmr1;
ushort tmr2;
ushort trr1;
ushort trr2;
ushort tcr1;
ushort tcr2;
ushort tcn1;
ushort tcn2;
ushort tmr3;
ushort tmr4;
ushort trr3;
ushort trr4;
ushort tcr3;
ushort tcr4;
ushort tcn3;
ushort tcn4;
ushort ter1;
ushort ter2;
ushort ter3;
ushort ter4;
uchar rsv15[0x9C0-0x9B8];
};
struct { /* CPM */
ushort cpcr;
uchar res0[2];
ushort rccr;
uchar res1;
uchar rmds;
uchar res2a[4];
ushort rctr1;
ushort rctr2;
ushort rctr3;
ushort rctr4;
uchar res2[2];
ushort rter;
uchar res3[2];
ushort rtmr;
uchar rsv16[0x9F0-0x9DC];
};
union { /* BRG */
struct {
ulong brgc1;
ulong brgc2;
ulong brgc3;
ulong brgc4;
};
ulong brgc[4];
};
uchar skip0[0xAB2-0xA00]; /* USB, SCC, SMC, SPI: address using cpmdev(CP...)->regs */
struct { /* PIP */
ushort pipc; /* not 823 */
ushort ptpr; /* not 823 */
ulong pbdir;
ulong pbpar;
uchar pad10[2];
ushort pbodr;
ulong pbdat;
uchar pad11[0xAE0-0xAC8];
};
struct { /* SI */
ulong simode;
uchar sigmr;
uchar pad12;
uchar sistr;
uchar sicmr;
uchar pad13[4];
ulong sicr;
ulong sirp;
uchar pad14[0xB00-0xAF4];
};
ulong vcram[64];
ushort siram[256];
ushort lcdmap[256];
};
/*
* PCMCIA structures known by both ../port/cis.c and the pcmcia driver
*/
/*
* Map between physical memory space and PCMCIA card memory space.
*/
struct PCMmap {
ulong ca; /* card address */
ulong cea; /* card end address */
ulong isa; /* local virtual address */
int len; /* length of the ISA area */
int attr; /* attribute memory */
int slotno; /* owning slot */
int ref;
};
/*
* a PCMCIA configuration entry
*/
struct PCMconftab
{
int index;
ushort irqs; /* legal irqs */
uchar irqtype;
uchar bit16; /* true for 16 bit access */
uchar nlines;
struct {
ulong start;
ulong len;
PCMmap* map;
} io[16];
int nio;
int vcc;
int vpp1;
int vpp2;
uchar memwait;
ulong maxwait;
ulong readywait;
ulong otherwait;
};
/*
* PCMCIA card slot
*/
struct PCMslot
{
// RWlock;
// Ref ref;
Ref;
void* ctlr; /* controller for this slot */
long memlen; /* memory length */
uchar slotno; /* slot number */
uchar slotshift; /* >> register to meet mask; << mask to meet register */
void *regs; /* i/o registers */
void *mem; /* memory */
void *attr; /* attribute memory */
/* status */
uchar occupied; /* card in the slot */
uchar configed; /* card configured */
uchar busy;
uchar powered;
uchar battery;
uchar wrprot;
uchar enabled;
uchar special;
uchar dsize;
uchar v3_3;
uchar voltage;
/* cis info */
int cisread; /* set when the cis has been read */
char verstr[512]; /* version string */
uchar cpresent; /* config registers present */
ulong caddr; /* relative address of config registers */
int nctab; /* number of config table entries */
PCMconftab ctab[8];
PCMconftab *def; /* default conftab */
/* maps are fixed */
PCMmap memmap;
PCMmap attrmap;
struct {
void (*f)(Ureg*, void*);
void *arg;
} intr;
struct {
void (*f)(void*, int);
void *arg;
} notify;
};
/* ../port/cis.c */
void pcmcisread(PCMslot*);
int pcmcistuple(int, int, int, void*, int);
/* devpcmcia.c */
PCMmap* pcmmap(int, ulong, int, int);
void pcmunmap(int, PCMmap*);
/*
* used by ../port/devi2c.c and i2c.c
*/
struct I2Cdev {
int addr;
int salen; /* length in bytes of subaddress, if used; 0 otherwise */
int tenbit; /* 10-bit addresses */
};
long i2crecv(I2Cdev*, void*, long, ulong);
long i2csend(I2Cdev*, void*, long, ulong);
void i2csetup(int);
|