#ifndef _SYS_PCI_IMPL_H
#define _SYS_PCI_IMPL_H
#include <sys/dditypes.h>
#include <sys/memlist.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__i386) || defined(__amd64)
#define PCI_MECHANISM_UNKNOWN -1
#define PCI_MECHANISM_NONE 0
#if defined(__i386) || defined(__amd64)
#define PCI_MECHANISM_1 1
#define PCI_MECHANISM_2 2
#else
#error "Unknown processor type"
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define PCI_FUNC_MASK 0x07
#define PCI_CONFADD 0xcf8
#define PCI_PMC 0xcfb
#define PCI_CONFDATA 0xcfc
#define PCI_CONE 0x80000000
#define PCI_CADDR1(bus, device, function, reg) \
(PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \
| (((function) & 0x7) << 8) | ((reg) & 0xfc))
#define PCI_CSE_PORT 0xcf8
#define PCI_FORW_PORT 0xcfa
#define PCI_CADDR2(device, indx) \
(0xc000 | (((device) & 0xf) << 8) | (indx))
typedef struct pci_acc_cfblk {
uchar_t c_busnum;
uchar_t c_devnum;
uchar_t c_funcnum;
uchar_t c_fill;
} pci_acc_cfblk_t;
struct pci_bus_resource {
struct memlist *io_avail;
struct memlist *io_used;
struct memlist *mem_avail;
struct memlist *mem_used;
struct memlist *pmem_avail;
struct memlist *pmem_used;
struct memlist *bus_avail;
dev_info_t *dip;
void *privdata;
uchar_t par_bus;
uchar_t sub_bus;
uchar_t root_addr;
uchar_t num_cbb;
uchar_t num_bridge;
boolean_t io_reprogram;
boolean_t mem_reprogram;
boolean_t subtractive;
uint64_t mem_size;
uint64_t pmem_size;
uint64_t mem_buffer;
uint_t io_size;
};
extern struct pci_bus_resource *pci_bus_res;
extern struct memlist *pci_memlist_alloc(void);
extern void pci_memlist_free(struct memlist *);
extern void pci_memlist_free_all(struct memlist **);
extern void pci_memlist_insert(struct memlist **, uint64_t, uint64_t);
extern int pci_memlist_remove(struct memlist **, uint64_t, uint64_t);
extern uint64_t pci_memlist_find(struct memlist **, uint64_t, int);
extern uint64_t pci_memlist_find_with_startaddr(struct memlist **, uint64_t,
uint64_t, int);
extern void pci_memlist_dump(struct memlist *);
extern void pci_memlist_subsume(struct memlist **, struct memlist **);
extern void pci_memlist_merge(struct memlist **, struct memlist **);
extern struct memlist *pci_memlist_dup(struct memlist *);
extern int pci_memlist_count(struct memlist *);
#endif
#define PCI_MINOR_NUM(x, y) (((uint_t)(x) << 8) | ((y) & 0xFF))
#define PCI_MINOR_NUM_TO_PCI_DEVNUM(x) ((x) & 0xFF)
#define PCI_MINOR_NUM_TO_INSTANCE(x) ((x) >> 8)
#define PCI_DEVCTL_MINOR 0xFF
#define PCI_TOOL_REG_MINOR_NUM 0xFD
#define PCI_TOOL_INTR_MINOR_NUM 0xFC
#define PCI_SOFT_STATE_CLOSED 0x0
#define PCI_SOFT_STATE_OPEN 0x1
#define PCI_SOFT_STATE_OPEN_EXCL 0x2
#define PCI_MSI_MIN_WORDS 3
#define PCI_PCIX_MIN_WORDS 2
#define PCI_PCIE_MIN_WORDS 5
#define PCI_PMCAP_NDWORDS 2
#define PCI_AGP_NDWORDS 3
#define PCI_SLOTID_NDWORDS 1
#define PCI_MSIX_NDWORDS 3
#define PCI_CAP_SZUNKNOWN 0
#define PCI_HTCAP_SLPRI_NDWORDS 7
#define PCI_HTCAP_HOSTSEC_NDWORDS 6
#define PCI_HTCAP_INTCONF_NDWORDS 2
#define PCI_HTCAP_REVID_NDWORDS 1
#define PCI_HTCAP_UNITID_CLUMP_NDWORDS 3
#define PCI_HTCAP_ECFG_NDWORDS 3
#define PCI_HTCAP_ADDRMAP_NDWORDS PCI_CAP_SZUNKNOWN
#define PCI_HTCAP_MSIMAP_NDWORDS 3
#define PCI_HTCAP_DIRROUTE_NDWORDS 3
#define PCI_HTCAP_VCSET_NDWORDS 3
#define PCI_HTCAP_RETRYMODE_NDWORDS 3
#define PCI_HTCAP_GEN3_NDWORDS 10
#define PCI_HTCAP_FUNCEXT_NDWORDS PCI_CAP_SZUNKNOWN
#define PCI_HTCAP_PM_NDWORDS 2
#define CAP_ID(confhdl, cap_ptr, xspace) \
((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID))
#define NEXT_CAP(confhdl, cap_ptr, xspace) \
((xspace) ? 0 : \
pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR))
extern int pci_resource_setup(dev_info_t *);
extern void pci_resource_destroy(dev_info_t *);
#ifdef __cplusplus
}
#endif
#endif