globals.h revision 1.13 1 /* $NetBSD: globals.h,v 1.13 2011/10/30 21:08:33 phx Exp $ */
2
3 #ifdef DEBUG
4 #define DPRINTF(x) printf x
5 #else
6 #define DPRINTF(x)
7 #endif
8
9 /* clock feed */
10 #ifndef EXT_CLK_FREQ
11 #define EXT_CLK_FREQ 33333333 /* external clock (PCI clock) */
12 #endif
13
14 /* brd type */
15 extern int brdtype;
16 #define BRD_SANDPOINTX2 2
17 #define BRD_SANDPOINTX3 3
18 #define BRD_ENCOREPP1 10
19 #define BRD_KUROBOX 100
20 #define BRD_QNAPTS 101
21 #define BRD_SYNOLOGY 102
22 #define BRD_STORCENTER 103
23 #define BRD_DLINKDSM 104
24 #define BRD_NH230NAS 105
25 #define BRD_UNKNOWN -1
26
27 struct brdprop {
28 const char *family;
29 const char *verbose;
30 int brdtype;
31 uint32_t extclk;
32 char *consname;
33 int consport;
34 int consspeed;
35 void (*setup)(struct brdprop *);
36 void (*brdfix)(struct brdprop *);
37 void (*pcifix)(struct brdprop *);
38 void (*reset)(void);
39 };
40
41 extern uint32_t cpuclock, busclock;
42
43 /* board specific support code */
44 struct brdprop *brd_lookup(int);
45 int tstchar(void);
46 unsigned mpc107memsize(void);
47 void read_mac_from_flash(uint8_t *);
48
49 /* PPC processor ctl */
50 void __syncicache(void *, size_t);
51
52 /* i/o access */
53 void out8(unsigned, unsigned);
54 unsigned in8(unsigned);
55 void out16rb(unsigned, unsigned);
56 void out32rb(unsigned, unsigned);
57 unsigned in16rb(unsigned);
58 unsigned in32rb(unsigned);
59 void iohtole16(unsigned, unsigned);
60 void iohtole32(unsigned, unsigned);
61 unsigned iole32toh(unsigned);
62 unsigned iole16toh(unsigned);
63
64 /* far call would never return */
65 void run(void *, void *, void *, void *, void *);
66
67 /* micro second precision delay */
68 void delay(unsigned);
69
70 /* PCI stuff */
71 struct pcidev {
72 unsigned bdf; /* bus.dev.func */
73 unsigned pvd; /* device ID */
74 void *drv; /* driver */
75 };
76 void pcisetup(void);
77 void pcifixup(void);
78 unsigned pcimaketag(int, int, int);
79 void pcidecomposetag(unsigned, int *, int *, int *);
80 int pcifinddev(unsigned, unsigned, unsigned *);
81 int pcilookup(unsigned, struct pcidev *, int);
82 unsigned pcicfgread(unsigned, int);
83 void pcicfgwrite(unsigned, int, unsigned);
84
85 #define PCI_ID_REG 0x00
86 #define PCI_VENDOR(id) ((id) & 0xffff)
87 #define PCI_PRODUCT(id) (((id) >> 16) & 0xffff)
88 #define PCI_VENDOR_INVALID 0xffff
89 #define PCI_DEVICE(v,p) ((v) | ((p) << 16))
90 #define PCI_COMMAND_STATUS_REG 0x04
91 #define PCI_CLASS_REG 0x08
92 #define PCI_CLASS(v) (((v) >> 16) & 0xffff)
93 #define PCI_SUBCLASS(v) (((v) >> 16) & 0xff)
94 #define PCI_INTERFACE(v) (((v) & 0xff00) >> 8)
95 #define PCI_REVISION(v) ((v) & 0xff)
96 #define PCI_CLASS_PPB 0x0604
97 #define PCI_CLASS_ETH 0x0200
98 #define PCI_CLASS_SCSI 0x0100
99 #define PCI_CLASS_IDE 0x0101
100 #define PCI_CLASS_RAID 0x0104
101 #define PCI_CLASS_SATA 0x0106
102 #define PCI_CLASS_MISCSTORAGE 0x0180
103 #define PCI_CLASS_USB 0x0c03
104 #define PCI_BHLC_REG 0x0c
105 #define PCI_HDRTYPE_TYPE(r) (((r) >> 16) & 0x7f)
106 #define PCI_HDRTYPE_MULTIFN(r) ((r) & (0x80 << 16))
107
108 /*
109 * "Map B" layout
110 *
111 * practice direct mode configuration scheme with CONFIG_ADDR
112 * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
113 */
114 #define PCI_MEMBASE 0x80000000 /* PCI memory space */
115 #define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
116 #define PCI_IOBASE 0x00001000 /* reserves room for southbridge */
117 #define PCI_IOLIMIT 0x000fffff
118 #define PCI_XIOBASE 0xfe000000 /* ISA/PCI io space */
119 #define CONFIG_ADDR 0xfec00000
120 #define CONFIG_DATA 0xfee00000
121
122 /* cache ops */
123 void _wb(uint32_t, uint32_t);
124 void _wbinv(uint32_t, uint32_t);
125 void _inv(uint32_t, uint32_t);
126
127 /* parsing */
128 uint32_t read_hex(const char *);
129
130 /* heap */
131 void *allocaligned(size_t, size_t);
132
133 /* NIF support */
134 int net_open(struct open_file *, ...);
135 int net_close(struct open_file *);
136 int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
137
138 int netif_init(void *);
139 void netif_shutdown_all(void);
140 int netif_open(void *);
141 int netif_close(int);
142
143 #define NIF_DECL(xxx) \
144 int xxx ## _match(unsigned, void *); \
145 void * xxx ## _init(unsigned, void *); \
146 int xxx ## _send(void *, char *, unsigned); \
147 int xxx ## _recv(void *, char *, unsigned, unsigned); \
148 void xxx ## _shutdown(void *)
149
150 NIF_DECL(fxp);
151 NIF_DECL(tlp);
152 NIF_DECL(rge);
153 NIF_DECL(skg);
154 NIF_DECL(stg);
155
156 /* DSK support */
157 int dskdv_init(void *);
158
159 int dsk_open(struct open_file *, ...);
160 int dsk_close(struct open_file *);
161 int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
162 struct fs_ops *dsk_fsops(struct open_file *);
163
164 #define DSK_DECL(xxx) \
165 int xxx ## _match(unsigned, void *); \
166 void * xxx ## _init(unsigned, void *)
167
168 DSK_DECL(pciide);
169 DSK_DECL(siisata);
170
171 /* status */
172 #define ATA_STS_BUSY 0x80
173 #define ATA_STS_DRDY 0x40
174 #define ATA_STS_ERR 0x01
175 /* command */
176 #define ATA_CMD_IDENT 0xec
177 #define ATA_CMD_READ 0x20
178 #define ATA_CMD_READ_EXT 0x24
179 #define ATA_CMD_SETF 0xef
180 /* device */
181 #define ATA_DEV_LBA 0xe0
182 #define ATA_DEV_OBS 0x90
183 /* control */
184 #define ATA_DREQ 0x08
185 #define ATA_SRST 0x04
186
187 #define ATA_XFER 0x03
188 #define XFER_PIO4 0x0c
189 #define XFER_PIO0 0x08
190
191 struct dvata_chan {
192 uint32_t cmd, ctl, alt, dma;
193 };
194 #define _DAT 0 /* RW */
195 #define _ERR 1 /* R */
196 #define _FEA 1 /* W */
197 #define _NSECT 2 /* RW */
198 #define _LBAL 3 /* RW */
199 #define _LBAM 4 /* RW */
200 #define _LBAH 5 /* RW */
201 #define _DEV 6 /* W */
202 #define _STS 7 /* R */
203 #define _CMD 7 /* W */
204
205 struct dkdev_ata {
206 unsigned tag;
207 uint32_t bar[6];
208 struct dvata_chan chan[4];
209 int presense[4];
210 char *iobuf;
211 };
212
213 struct disk {
214 char xname[8];
215 void *dvops;
216 unsigned unittag;
217 uint16_t ident[128];
218 uint64_t nsect;
219 uint64_t first;
220 void *dlabel;
221 int part;
222 void *fsops;
223 int (*lba_read)(struct disk *, int64_t, int, void *);
224 };
225
226 int spinwait_unbusy(struct dkdev_ata *, int, int, const char **);
227 int perform_atareset(struct dkdev_ata *, int);
228 int satapresense(struct dkdev_ata *, int);
229