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