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