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