summaryrefslogtreecommitdiff
path: root/com32/include/sys/pci.h
blob: 3b07ae7cb8e6b0569cb5c1505cc789eea89782b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef _SYS_PCI_H
#define _SYS_PCI_H

#include <inttypes.h>
#include <sys/io.h>

#define MAX_PCI_FUNC      8
#define MAX_PCI_DEVICES  32
#define MAX_PCI_BUSES   256

typedef uint32_t pciaddr_t;

/* a structure for extended pci information */
struct pci_dev_info {
	char     vendor_name[255];
	char     product_name[255];
	char	 linux_kernel_module[64];
};

/* a struct to represent a pci device */
struct pci_device {
	uint16_t vendor;
	uint16_t product;
	uint16_t sub_vendor;
	uint16_t sub_product;
	uint8_t  revision;
	struct pci_dev_info *pci_dev_info;
};

struct pci_bus {
	uint16_t id;
	struct pci_device *pci_device[MAX_PCI_DEVICES];
	uint8_t pci_device_count;
};

struct pci_device_list {
	struct pci_device pci_device[MAX_PCI_DEVICES];
	uint8_t count;
};

struct pci_bus_list {
	struct pci_bus pci_bus[MAX_PCI_BUSES];
	uint8_t count;
};

struct match {
  struct match *next;
  uint32_t did;
  uint32_t did_mask;
  uint32_t sid;
  uint32_t sid_mask;
  uint8_t rid_min, rid_max;
  char *filename;
};

static inline pciaddr_t pci_mkaddr(uint32_t bus, uint32_t dev,
				   uint32_t func, uint32_t reg)
{
  return 0x80000000 | ((bus & 0xff) << 16) | ((dev & 0x1f) << 11) |
    ((func & 0x07) << 8) | (reg & 0xff);
}

enum pci_config_type {
  PCI_CFG_NONE          = -1,	/* badness */
  PCI_CFG_AUTO		= 0,	/* autodetect */
  PCI_CFG_TYPE1		= 1,
  PCI_CFG_TYPE2		= 2,
  PCI_CFG_BIOS          = 3,
};

enum pci_config_type pci_set_config_type(enum pci_config_type);

uint8_t pci_readb(pciaddr_t);
uint16_t pci_readw(pciaddr_t);
uint32_t pci_readl(pciaddr_t);
void pci_writeb(uint8_t, pciaddr_t);
void pci_writew(uint16_t, pciaddr_t);
void pci_writel(uint32_t, pciaddr_t);

extern int pci_scan(struct pci_bus_list *pci_bus_list, struct pci_device_list *pci_device_list);
extern struct match * find_pci_device(struct pci_device_list *pci_device_list, struct match *list);
extern void get_name_from_pci_ids(struct pci_device_list *pci_device_list);
extern void get_module_name_from_pci_ids(struct pci_device_list *pci_device_list);
#endif /* _SYS_PCI_H */