1 /* 2 * Copyright 2008, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PCI2_H 6 #define _PCI2_H 7 8 9 #include <device_manager.h> 10 #include <PCI.h> 11 12 13 typedef struct pci_device pci_device; 14 15 typedef struct pci_device_module_info { 16 driver_module_info info; 17 18 uint8 (*read_io_8)(pci_device *device, addr_t mappedIOAddress); 19 void (*write_io_8)(pci_device *device, addr_t mappedIOAddress, 20 uint8 value); 21 uint16 (*read_io_16)(pci_device *device, addr_t mappedIOAddress); 22 void (*write_io_16)(pci_device *device, addr_t mappedIOAddress, 23 uint16 value); 24 uint32 (*read_io_32)(pci_device *device, addr_t mappedIOAddress); 25 void (*write_io_32)(pci_device *device, addr_t mappedIOAddress, 26 uint32 value); 27 28 phys_addr_t (*ram_address)(pci_device *device, phys_addr_t physicalAddress); 29 30 uint32 (*read_pci_config)(pci_device *device, uint16 offset, 31 uint8 size); 32 void (*write_pci_config)(pci_device *device, uint16 offset, 33 uint8 size, uint32 value); 34 status_t (*find_pci_capability)(pci_device *device, uint8 capID, 35 uint8 *offset); 36 void (*get_pci_info)(pci_device *device, struct pci_info *info); 37 status_t (*find_pci_extended_capability)(pci_device *device, uint16 capID, 38 uint16 *offset); 39 uint8 (*get_powerstate)(pci_device *device); 40 void (*set_powerstate)(pci_device *device, uint8 state); 41 42 // MSI/MSI-X 43 uint8 (*get_msi_count)(pci_device *device); 44 status_t (*configure_msi)(pci_device *device, 45 uint8 count, 46 uint8 *startVector); 47 status_t (*unconfigure_msi)(pci_device *device); 48 49 status_t (*enable_msi)(pci_device *device); 50 status_t (*disable_msi)(pci_device *device); 51 52 uint8 (*get_msix_count)(pci_device *device); 53 status_t (*configure_msix)(pci_device *device, 54 uint8 count, 55 uint8 *startVector); 56 status_t (*enable_msix)(pci_device *device); 57 58 } pci_device_module_info; 59 60 61 enum { 62 kPciRangeInvalid = 0, 63 kPciRangeIoPort = 1, 64 kPciRangeMmio = 2, 65 kPciRangeMmio64Bit = 1 << 0, 66 kPciRangeMmioPrefetch = 1 << 1, 67 kPciRangeMmioEnd = 6, 68 kPciRangeEnd = 6, 69 }; 70 71 typedef struct pci_resource_range { 72 uint32 type; 73 phys_addr_t host_addr; 74 phys_addr_t pci_addr; 75 uint64 size; 76 } pci_resource_range; 77 78 79 typedef struct pci_controller_module_info { 80 driver_module_info info; 81 82 // read PCI config space 83 status_t (*read_pci_config)(void *cookie, 84 uint8 bus, uint8 device, uint8 function, 85 uint16 offset, uint8 size, uint32 *value); 86 87 // write PCI config space 88 status_t (*write_pci_config)(void *cookie, 89 uint8 bus, uint8 device, uint8 function, 90 uint16 offset, uint8 size, uint32 value); 91 92 status_t (*get_max_bus_devices)(void *cookie, int32 *count); 93 94 status_t (*read_pci_irq)(void *cookie, 95 uint8 bus, uint8 device, uint8 function, 96 uint8 pin, uint8 *irq); 97 98 status_t (*write_pci_irq)(void *cookie, 99 uint8 bus, uint8 device, uint8 function, 100 uint8 pin, uint8 irq); 101 102 status_t (*get_range)(void *cookie, uint32 index, pci_resource_range *range); 103 104 status_t (*finalize)(void *cookie); 105 106 } pci_controller_module_info; 107 108 109 /* Attributes of PCI device nodes */ 110 #define B_PCI_DEVICE_DOMAIN "pci/domain" /* uint32 */ 111 #define B_PCI_DEVICE_BUS "pci/bus" /* uint8 */ 112 #define B_PCI_DEVICE_DEVICE "pci/device" /* uint8 */ 113 #define B_PCI_DEVICE_FUNCTION "pci/function" /* uint8 */ 114 115 #endif /* _PCI2_H */ 116