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