Home | History | Annotate | Line # | Download | only in altboot
globals.h revision 1.9
      1 /* $NetBSD: globals.h,v 1.9 2011/03/10 21:11:49 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 int netif_open(void *);
    137 int netif_close(int);
    138 
    139 #define NIF_DECL(xxx) \
    140     int xxx ## _match(unsigned, void *); \
    141     void * xxx ## _init(unsigned, void *); \
    142     int xxx ## _send(void *, char *, unsigned); \
    143     int xxx ## _recv(void *, char *, unsigned, unsigned)
    144 
    145 NIF_DECL(fxp);
    146 NIF_DECL(tlp);
    147 NIF_DECL(rge);
    148 NIF_DECL(skg);
    149 NIF_DECL(stg);
    150 
    151 /* DSK support */
    152 int dskdv_init(void *);
    153 
    154 int dsk_open(struct open_file *, ...);
    155 int dsk_close(struct open_file *);
    156 int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
    157 struct fs_ops *dsk_fsops(struct open_file *);
    158 
    159 #define DSK_DECL(xxx) \
    160     int xxx ## _match(unsigned, void *); \
    161     void * xxx ## _init(unsigned, void *)
    162 
    163 DSK_DECL(pciide);
    164 DSK_DECL(siisata);
    165 
    166 /* status */
    167 #define ATA_STS_BUSY		0x80
    168 #define ATA_STS_DRDY		0x40
    169 #define ATA_STS_ERR 		0x01
    170 /* command */
    171 #define ATA_CMD_IDENT		0xec
    172 #define ATA_CMD_READ		0x20
    173 #define ATA_CMD_READ_EXT	0x24
    174 #define ATA_CMD_SETF		0xef
    175 /* device */
    176 #define ATA_DEV_LBA		0xe0
    177 #define ATA_DEV_OBS		0x90
    178 /* control */
    179 #define ATA_DREQ		0x08
    180 #define ATA_SRST		0x04
    181 
    182 #define ATA_XFER		0x03
    183 #define XFER_PIO4		0x0c
    184 #define XFER_PIO0		0x08
    185 
    186 struct dvata_chan {
    187 	uint32_t cmd, ctl, alt, dma;
    188 };
    189 #define _DAT	0	/* RW */
    190 #define _ERR	1	/* R */
    191 #define _FEA	1	/* W */
    192 #define _NSECT	2	/* RW */
    193 #define _LBAL	3	/* RW */
    194 #define _LBAM	4	/* RW */
    195 #define _LBAH	5	/* RW */
    196 #define _DEV	6	/* W */
    197 #define _STS	7	/* R */
    198 #define _CMD	7	/* W */
    199 
    200 struct dkdev_ata {
    201 	unsigned tag;
    202 	uint32_t bar[6];
    203 	struct dvata_chan chan[4];
    204 	int presense[4];
    205 	char *iobuf;
    206 };
    207 
    208 struct disk {
    209 	char xname[8];
    210 	void *dvops;
    211 	unsigned unittag;
    212 	uint16_t ident[128];
    213 	uint64_t nsect;
    214 	uint64_t first;
    215 	void *dlabel;
    216 	int part;
    217 	void *fsops;
    218 	int (*lba_read)(struct disk *, int64_t, int, void *);
    219 };
    220 
    221 int spinwait_unbusy(struct dkdev_ata *, int, int, const char **);
    222 int perform_atareset(struct dkdev_ata *, int);
    223 int satapresense(struct dkdev_ata *, int);
    224