#if !defined(PCI_H) && defined(CONFIG_PCI)
#define PCI_H
#include "pci_ids.h"
#define PCI_COMMAND_IO 0x1
#define PCI_COMMAND_MEM 0x2
#define PCI_COMMAND_MASTER 0x4
#define PCI_LATENCY_TIMER 0x0d
#define PCI_COMMAND_SPECIAL 0x8
#define PCI_COMMAND_INVALIDATE 0x10
#define PCI_COMMAND_VGA_PALETTE 0x20
#define PCI_COMMAND_PARITY 0x40
#define PCI_COMMAND_WAIT 0x80
#define PCI_COMMAND_SERR 0x100
#define PCI_COMMAND_FAST_BACK 0x200
#define PCIBIOS_PCI_FUNCTION_ID 0xb1XX
#define PCIBIOS_PCI_BIOS_PRESENT 0xb101
#define PCIBIOS_FIND_PCI_DEVICE 0xb102
#define PCIBIOS_FIND_PCI_CLASS_CODE 0xb103
#define PCIBIOS_GENERATE_SPECIAL_CYCLE 0xb106
#define PCIBIOS_READ_CONFIG_BYTE 0xb108
#define PCIBIOS_READ_CONFIG_WORD 0xb109
#define PCIBIOS_READ_CONFIG_DWORD 0xb10a
#define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b
#define PCIBIOS_WRITE_CONFIG_WORD 0xb10c
#define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d
#define PCI_VENDOR_ID 0x00
#define PCI_DEVICE_ID 0x02
#define PCI_COMMAND 0x04
#define PCI_STATUS 0x06
#define PCI_STATUS_CAP_LIST 0x10
#define PCI_STATUS_66MHZ 0x20
#define PCI_STATUS_UDF 0x40
#define PCI_STATUS_FAST_BACK 0x80
#define PCI_STATUS_PARITY 0x100
#define PCI_STATUS_DEVSEL_MASK 0x600
#define PCI_STATUS_DEVSEL_FAST 0x000
#define PCI_STATUS_DEVSEL_MEDIUM 0x200
#define PCI_STATUS_DEVSEL_SLOW 0x400
#define PCI_STATUS_SIG_TARGET_ABORT 0x800
#define PCI_STATUS_REC_TARGET_ABORT 0x1000
#define PCI_STATUS_REC_MASTER_ABORT 0x2000
#define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000
#define PCI_STATUS_DETECTED_PARITY 0x8000
#define PCI_REVISION 0x08
#define PCI_REVISION_ID 0x08
#define PCI_CLASS_REVISION 0x08
#define PCI_CLASS_CODE 0x0b
#define PCI_SUBCLASS_CODE 0x0a
#define PCI_HEADER_TYPE 0x0e
#define PCI_HEADER_TYPE_NORMAL 0
#define PCI_HEADER_TYPE_BRIDGE 1
#define PCI_HEADER_TYPE_CARDBUS 2
#define PCI_CARDBUS_CIS 0x28
#define PCI_SUBSYSTEM_VENDOR_ID 0x2c
#define PCI_SUBSYSTEM_ID 0x2e
#define PCI_BASE_ADDRESS_0 0x10
#define PCI_BASE_ADDRESS_1 0x14
#define PCI_BASE_ADDRESS_2 0x18
#define PCI_BASE_ADDRESS_3 0x1c
#define PCI_BASE_ADDRESS_4 0x20
#define PCI_BASE_ADDRESS_5 0x24
#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
#define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00
#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02
#define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04
#ifndef PCI_BASE_ADDRESS_IO_MASK
#define PCI_BASE_ADDRESS_IO_MASK (~0x03)
#endif
#ifndef PCI_BASE_ADDRESS_MEM_MASK
#define PCI_BASE_ADDRESS_MEM_MASK (~0x0f)
#endif
#define PCI_BASE_ADDRESS_SPACE_IO 0x01
#define PCI_ROM_ADDRESS 0x30
#define PCI_ROM_ADDRESS_ENABLE 0x01
#define PCI_CAPABILITY_LIST 0x34
#define PCI_INTERRUPT_LINE 0x3c
#define PCI_INTERRUPT_PIN 0x3d
#define PCI_PRIMARY_BUS 0x18
#define PCI_SECONDARY_BUS 0x19
#define PCI_SUBORDINATE_BUS 0x1a
#define PCI_SEC_LATENCY_TIMER 0x1b
#define PCI_IO_BASE 0x1c
#define PCI_IO_LIMIT 0x1d
#define PCI_IO_RANGE_TYPE_MASK 0x0f
#define PCI_IO_RANGE_TYPE_16 0x00
#define PCI_IO_RANGE_TYPE_32 0x01
#define PCI_IO_RANGE_MASK ~0x0f
#define PCI_SEC_STATUS 0x1e
#define PCI_MEMORY_BASE 0x20
#define PCI_MEMORY_LIMIT 0x22
#define PCI_MEMORY_RANGE_TYPE_MASK 0x0f
#define PCI_MEMORY_RANGE_MASK ~0x0f
#define PCI_PREF_MEMORY_BASE 0x24
#define PCI_PREF_MEMORY_LIMIT 0x26
#define PCI_PREF_RANGE_TYPE_MASK 0x0f
#define PCI_PREF_RANGE_TYPE_32 0x00
#define PCI_PREF_RANGE_TYPE_64 0x01
#define PCI_PREF_RANGE_MASK ~0x0f
#define PCI_PREF_BASE_UPPER32 0x28
#define PCI_PREF_LIMIT_UPPER32 0x2c
#define PCI_IO_BASE_UPPER16 0x30
#define PCI_IO_LIMIT_UPPER16 0x32
#define PCI_ROM_ADDRESS1 0x38
#define PCI_BRIDGE_CONTROL 0x3e
#define PCI_BRIDGE_CTL_PARITY 0x01
#define PCI_BRIDGE_CTL_SERR 0x02
#define PCI_BRIDGE_CTL_NO_ISA 0x04
#define PCI_BRIDGE_CTL_VGA 0x08
#define PCI_BRIDGE_CTL_MASTER_ABORT 0x20
#define PCI_BRIDGE_CTL_BUS_RESET 0x40
#define PCI_BRIDGE_CTL_FAST_BACK 0x80
#define PCI_CB_CAPABILITY_LIST 0x14
#define PCI_CAP_LIST_ID 0
#define PCI_CAP_ID_PM 0x01
#define PCI_CAP_ID_AGP 0x02
#define PCI_CAP_ID_VPD 0x03
#define PCI_CAP_ID_SLOTID 0x04
#define PCI_CAP_ID_MSI 0x05
#define PCI_CAP_ID_CHSWP 0x06
#define PCI_CAP_LIST_NEXT 1
#define PCI_CAP_FLAGS 2
#define PCI_CAP_SIZEOF 4
#define PCI_PM_PMC 2
#define PCI_PM_CAP_VER_MASK 0x0007
#define PCI_PM_CAP_PME_CLOCK 0x0008
#define PCI_PM_CAP_RESERVED 0x0010
#define PCI_PM_CAP_DSI 0x0020
#define PCI_PM_CAP_AUX_POWER 0x01C0
#define PCI_PM_CAP_D1 0x0200
#define PCI_PM_CAP_D2 0x0400
#define PCI_PM_CAP_PME 0x0800
#define PCI_PM_CAP_PME_MASK 0xF800
#define PCI_PM_CAP_PME_D0 0x0800
#define PCI_PM_CAP_PME_D1 0x1000
#define PCI_PM_CAP_PME_D2 0x2000
#define PCI_PM_CAP_PME_D3 0x4000
#define PCI_PM_CAP_PME_D3cold 0x8000
#define PCI_PM_CTRL 4
#define PCI_PM_CTRL_STATE_MASK 0x0003
#define PCI_PM_CTRL_PME_ENABLE 0x0100
#define PCI_PM_CTRL_DATA_SEL_MASK 0x1e00
#define PCI_PM_CTRL_DATA_SCALE_MASK 0x6000
#define PCI_PM_CTRL_PME_STATUS 0x8000
#define PCI_PM_PPB_EXTENSIONS 6
#define PCI_PM_PPB_B2_B3 0x40
#define PCI_PM_BPCC_ENABLE 0x80
#define PCI_PM_DATA_REGISTER 7
#define PCI_PM_SIZEOF 8
#define PCI_AGP_VERSION 2
#define PCI_AGP_RFU 3
#define PCI_AGP_STATUS 4
#define PCI_AGP_STATUS_RQ_MASK 0xff000000
#define PCI_AGP_STATUS_SBA 0x0200
#define PCI_AGP_STATUS_64BIT 0x0020
#define PCI_AGP_STATUS_FW 0x0010
#define PCI_AGP_STATUS_RATE4 0x0004
#define PCI_AGP_STATUS_RATE2 0x0002
#define PCI_AGP_STATUS_RATE1 0x0001
#define PCI_AGP_COMMAND 8
#define PCI_AGP_COMMAND_RQ_MASK 0xff000000
#define PCI_AGP_COMMAND_SBA 0x0200
#define PCI_AGP_COMMAND_AGP 0x0100
#define PCI_AGP_COMMAND_64BIT 0x0020
#define PCI_AGP_COMMAND_FW 0x0010
#define PCI_AGP_COMMAND_RATE4 0x0004
#define PCI_AGP_COMMAND_RATE2 0x0002
#define PCI_AGP_COMMAND_RATE1 0x0001
#define PCI_AGP_SIZEOF 12
#define PCI_SID_ESR 2
#define PCI_SID_ESR_NSLOTS 0x1f
#define PCI_SID_ESR_FIC 0x20
#define PCI_SID_CHASSIS_NR 3
#define PCI_MSI_FLAGS 2
#define PCI_MSI_FLAGS_64BIT 0x80
#define PCI_MSI_FLAGS_QSIZE 0x70
#define PCI_MSI_FLAGS_QMASK 0x0e
#define PCI_MSI_FLAGS_ENABLE 0x01
#define PCI_MSI_RFU 3
#define PCI_MSI_ADDRESS_LO 4
#define PCI_MSI_ADDRESS_HI 8
#define PCI_MSI_DATA_32 8
#define PCI_MSI_DATA_64 12
#define PCI_SLOT(devfn) ((devfn) >> 3)
#define PCI_FUNC(devfn) ((devfn) & 0x07)
#define BIOS32_SIGNATURE (('_' << 0) + ('3' << 8) + ('2' << 16) + ('_' << 24))
#define PCI_SIGNATURE (('P' << 0) + ('C' << 8) + ('I' << 16) + (' ' << 24))
#define PCI_SERVICE (('$' << 0) + ('P' << 8) + ('C' << 16) + ('I' << 24))
union bios32 {
struct {
unsigned long signature;
unsigned long entry;
unsigned char revision;
unsigned char length;
unsigned char checksum;
unsigned char reserved[5];
} fields;
char chars[16];
};
struct pci_device;
struct dev;
typedef int (*pci_probe_t)(struct dev *, struct pci_device *);
struct pci_device {
uint32_t class;
uint16_t vendor, dev_id;
const char *name;
unsigned int membase;
unsigned int ioaddr;
unsigned int romaddr;
unsigned char irq;
unsigned char devfn;
unsigned char bus;
unsigned char use_specified;
const struct pci_driver *driver;
};
extern void scan_pci_bus(int type, struct pci_device *dev);
extern void find_pci(int type, struct pci_device *dev);
extern int pcibios_read_config_byte(unsigned int bus, unsigned int device_fn, unsigned int where, uint8_t *value);
extern int pcibios_write_config_byte (unsigned int bus, unsigned int device_fn, unsigned int where, uint8_t value);
extern int pcibios_read_config_word(unsigned int bus, unsigned int device_fn, unsigned int where, uint16_t *value);
extern int pcibios_write_config_word (unsigned int bus, unsigned int device_fn, unsigned int where, uint16_t value);
extern int pcibios_read_config_dword(unsigned int bus, unsigned int device_fn, unsigned int where, uint32_t *value);
extern int pcibios_write_config_dword(unsigned int bus, unsigned int device_fn, unsigned int where, uint32_t value);
extern unsigned long pcibios_bus_base(unsigned int bus);
extern void adjust_pci_device(struct pci_device *p);
static inline int
pci_read_config_byte(struct pci_device *dev, unsigned int where, uint8_t *value)
{
return pcibios_read_config_byte(dev->bus, dev->devfn, where, value);
}
static inline int
pci_write_config_byte(struct pci_device *dev, unsigned int where, uint8_t value)
{
return pcibios_write_config_byte(dev->bus, dev->devfn, where, value);
}
static inline int
pci_read_config_word(struct pci_device *dev, unsigned int where, uint16_t *value)
{
return pcibios_read_config_word(dev->bus, dev->devfn, where, value);
}
static inline int
pci_write_config_word(struct pci_device *dev, unsigned int where, uint16_t value)
{
return pcibios_write_config_word(dev->bus, dev->devfn, where, value);
}
static inline int
pci_read_config_dword(struct pci_device *dev, unsigned int where, uint32_t *value)
{
return pcibios_read_config_dword(dev->bus, dev->devfn, where, value);
}
static inline int
pci_write_config_dword(struct pci_device *dev, unsigned int where, uint32_t value)
{
return pcibios_write_config_dword(dev->bus, dev->devfn, where, value);
}
extern unsigned long pci_bar_start(struct pci_device *dev, unsigned int bar);
extern unsigned long pci_bar_size(struct pci_device *dev, unsigned int bar);
extern int pci_find_capability(struct pci_device *dev, int cap);
struct pci_id {
unsigned short vendor, dev_id;
const char *name;
};
struct dev;
struct pci_driver {
int type;
const char *name;
pci_probe_t probe;
struct pci_id *ids;
int id_count;
unsigned short class;
};
#define PCI_ROM(VENDOR_ID, DEVICE_ID, IMAGE, DESCRIPTION) \
{ VENDOR_ID, DEVICE_ID, IMAGE, }
#endif