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