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