Home | History | Annotate | Line # | Download | only in altboot
globals.h revision 1.6
      1 /* $NetBSD: globals.h,v 1.6 2011/02/14 06:21:29 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_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_COMMAND_STATUS_REG		0x04
     84 #define  PCI_VENDOR(id)			((id) & 0xffff)
     85 #define  PCI_PRODUCT(id)		(((id) >> 16) & 0xffff)
     86 #define  PCI_VENDOR_INVALID		0xffff
     87 #define  PCI_DEVICE(v,p)		((v) | ((p) << 16))
     88 #define PCI_CLASS_REG			0x08
     89 #define  PCI_CLASS_PPB			0x0604
     90 #define  PCI_CLASS_ETH			0x0200
     91 #define  PCI_CLASS_IDE			0x0101
     92 #define  PCI_CLASS_RAID			0x0104
     93 #define  PCI_CLASS_SATA			0x0106
     94 #define  PCI_CLASS_MISCSTORAGE		0x0180
     95 #define  PCI_CLASS_USB			0x0c03
     96 #define PCI_BHLC_REG			0x0c
     97 #define  PCI_HDRTYPE_TYPE(r)		(((r) >> 16) & 0x7f)
     98 #define  PCI_HDRTYPE_MULTIFN(r)		((r) & (0x80 << 16))
     99 
    100 /*
    101  * "Map B" layout
    102  *
    103  * practice direct mode configuration scheme with CONFIG_ADDR
    104  * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
    105  */
    106 #define PCI_MEMBASE	0x80000000	/* PCI memory space */
    107 #define PCI_MEMLIMIT	0xfbffffff	/* EUMB is next to this */
    108 #define PCI_IOBASE	0x00001000	/* reserves room for southbridge */
    109 #define PCI_IOLIMIT	0x000fffff
    110 #define PCI_XIOBASE	0xfe000000	/* ISA/PCI io space */
    111 #define CONFIG_ADDR	0xfec00000
    112 #define CONFIG_DATA	0xfee00000
    113 
    114 /* cache ops */
    115 void _wb(uint32_t, uint32_t);
    116 void _wbinv(uint32_t, uint32_t);
    117 void _inv(uint32_t, uint32_t);
    118 
    119 /* heap */
    120 void *allocaligned(size_t, size_t);
    121 
    122 /* NIF support */
    123 int net_open(struct open_file *, ...);
    124 int net_close(struct open_file *);
    125 int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
    126 
    127 int netif_init(void *);
    128 int netif_open(void *);
    129 int netif_close(int);
    130 
    131 #define NIF_DECL(xxx) \
    132     int xxx ## _match(unsigned, void *); \
    133     void * xxx ## _init(unsigned, void *); \
    134     int xxx ## _send(void *, char *, unsigned); \
    135     int xxx ## _recv(void *, char *, unsigned, unsigned)
    136 
    137 NIF_DECL(fxp);
    138 NIF_DECL(tlp);
    139 NIF_DECL(rge);
    140 NIF_DECL(skg);
    141 
    142 /* DSK support */
    143 int dskdv_init(void *);
    144 
    145 int dsk_open(struct open_file *, ...);
    146 int dsk_close(struct open_file *);
    147 int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
    148 struct fs_ops *dsk_fsops(struct open_file *);
    149 
    150 /* status */
    151 #define ATA_STS_BUSY		0x80
    152 #define ATA_STS_DRDY		0x40
    153 #define ATA_STS_ERR 		0x01
    154 /* command */
    155 #define ATA_CMD_IDENT		0xec
    156 #define ATA_CMD_READ		0x20
    157 #define ATA_CMD_READ_EXT	0x24
    158 #define ATA_CMD_SETF		0xef
    159 /* device */
    160 #define ATA_DEV_LBA		0xe0
    161 #define ATA_DEV_OBS		0x90
    162 /* control */
    163 #define ATA_DREQ		0x08
    164 #define ATA_SRST		0x04
    165 
    166 #define ATA_XFER		0x03
    167 #define XFER_PIO4		0x0c
    168 #define XFER_PIO0		0x08
    169 
    170 struct dvata_chan {
    171 	uint32_t cmd, ctl, alt, dma;
    172 };
    173 #define _DAT	0	/* RW */
    174 #define _ERR	1	/* R */
    175 #define _FEA	1	/* W */
    176 #define _NSECT	2	/* RW */
    177 #define _LBAL	3	/* RW */
    178 #define _LBAM	4	/* RW */
    179 #define _LBAH	5	/* RW */
    180 #define _DEV	6	/* W */
    181 #define _STS	7	/* R */
    182 #define _CMD	7	/* W */
    183 
    184 struct dkdev_ata {
    185 	unsigned tag;
    186 	uint32_t bar[6];
    187 	struct dvata_chan chan[4];
    188 	int presense[4];
    189 	char *iobuf;
    190 };
    191 
    192 struct disk {
    193 	char xname[8];
    194 	void *dvops;
    195 	unsigned unittag;
    196 	uint16_t ident[128];
    197 	uint64_t nsect;
    198 	uint64_t first;
    199 	void *dlabel;
    200 	int part;
    201 	void *fsops;
    202 	int (*lba_read)(struct disk *, int64_t, int, void *);
    203 };
    204 
    205 int spinwait_unbusy(struct dkdev_ata *, int, int, const char **);
    206 int perform_atareset(struct dkdev_ata *, int);
    207 int satapresense(struct dkdev_ata *, int);
    208