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