kexts: pci: create generic devices for all pci devices found during scan
This commit is contained in:
@@ -1,32 +1,33 @@
|
||||
#ifndef SOCKS_PCI_H_
|
||||
#define SOCKS_PCI_H_
|
||||
|
||||
#include <socks/device.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PCI_VENDOR_ID 0x00 // 2
|
||||
#define PCI_DEVICE_ID 0x02 // 2
|
||||
#define PCI_COMMAND 0x04 // 2
|
||||
#define PCI_STATUS 0x06 // 2
|
||||
#define PCI_REVISION_ID 0x08 // 1
|
||||
#define PCI_REG_VENDOR_ID 0x00 // 2
|
||||
#define PCI_REG_DEVICE_ID 0x02 // 2
|
||||
#define PCI_REG_COMMAND 0x04 // 2
|
||||
#define PCI_REG_STATUS 0x06 // 2
|
||||
#define PCI_REG_REVISION_ID 0x08 // 1
|
||||
|
||||
#define PCI_PROG_IF 0x09 // 1
|
||||
#define PCI_SUBCLASS 0x0a // 1
|
||||
#define PCI_CLASS 0x0b // 1
|
||||
#define PCI_CACHE_LINE_SIZE 0x0c // 1
|
||||
#define PCI_LATENCY_TIMER 0x0d // 1
|
||||
#define PCI_HEADER_TYPE 0x0e // 1
|
||||
#define PCI_BIST 0x0f // 1
|
||||
#define PCI_BAR0 0x10 // 4
|
||||
#define PCI_BAR1 0x14 // 4
|
||||
#define PCI_BAR2 0x18 // 4
|
||||
#define PCI_BAR3 0x1C // 4
|
||||
#define PCI_BAR4 0x20 // 4
|
||||
#define PCI_BAR5 0x24 // 4
|
||||
#define PCI_REG_PROG_IF 0x09 // 1
|
||||
#define PCI_REG_SUBCLASS 0x0a // 1
|
||||
#define PCI_REG_CLASS 0x0b // 1
|
||||
#define PCI_REG_CACHE_LINE_SIZE 0x0c // 1
|
||||
#define PCI_REG_LATENCY_TIMER 0x0d // 1
|
||||
#define PCI_REG_HEADER_TYPE 0x0e // 1
|
||||
#define PCI_REG_BIST 0x0f // 1
|
||||
#define PCI_REG_BAR0 0x10 // 4
|
||||
#define PCI_REG_BAR1 0x14 // 4
|
||||
#define PCI_REG_BAR2 0x18 // 4
|
||||
#define PCI_REG_BAR3 0x1C // 4
|
||||
#define PCI_REG_BAR4 0x20 // 4
|
||||
#define PCI_REG_BAR5 0x24 // 4
|
||||
|
||||
#define PCI_INTERRUPT_LINE 0x3C // 1
|
||||
#define PCI_INTERRUPT_PIN 0x3D
|
||||
#define PCI_REG_INTERRUPT_LINE 0x3C // 1
|
||||
#define PCI_REG_INTERRUPT_PIN 0x3D
|
||||
|
||||
#define PCI_SECONDARY_BUS 0x19 // 1
|
||||
#define PCI_REG_SECONDARY_BUS 0x19 // 1
|
||||
|
||||
#define PCI_HEADER_TYPE_DEVICE 0
|
||||
#define PCI_HEADER_TYPE_BRIDGE 1
|
||||
@@ -40,7 +41,29 @@
|
||||
|
||||
#define PCI_NONE 0xFFFF
|
||||
|
||||
typedef void (*pci_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *arg);
|
||||
#define PCI_SUBSYSTEM_KEXT_ID "net.doorstuck.socks.pci"
|
||||
|
||||
#define PCI_DEVICE_ID(vid, did) { .pci_vendor_id = (vid), .pci_device_id = (did) }
|
||||
#define PCI_DEVICE_ID_INVALID { .pci_vendor_id = PCI_NONE, .pci_device_id = PCI_NONE }
|
||||
|
||||
struct pci_device_id {
|
||||
uint16_t pci_vendor_id;
|
||||
uint16_t pci_device_id;
|
||||
};
|
||||
|
||||
struct pci_device {
|
||||
struct pci_device_id pci_id;
|
||||
unsigned int pci_bus, pci_slot, pci_func;
|
||||
};
|
||||
|
||||
struct pci_driver {
|
||||
struct driver pci_base;
|
||||
struct queue_entry pci_head;
|
||||
const struct pci_device_id *pci_target_devices;
|
||||
|
||||
kern_status_t(*probe)(struct pci_driver *, struct device *);
|
||||
kern_status_t(*remove)(struct pci_driver *, struct device *);
|
||||
};
|
||||
|
||||
static inline int pci_get_bus(uint32_t device)
|
||||
{
|
||||
@@ -67,8 +90,20 @@ static inline uint32_t pci_box_device(int bus, int slot, int func)
|
||||
return (uint32_t)((bus << 16) | (slot << 8) | func);
|
||||
}
|
||||
|
||||
extern struct pci_driver *pci_driver_create(struct kext *self, const char *name, const struct pci_device_id *device_ids);
|
||||
extern kern_status_t pci_driver_destroy(struct pci_driver *driver);
|
||||
extern kern_status_t pci_driver_register(struct pci_driver *driver);
|
||||
extern kern_status_t pci_driver_unregister(struct pci_driver *driver);
|
||||
static inline struct driver *pci_driver_base(struct pci_driver *driver)
|
||||
{
|
||||
return &driver->pci_base;
|
||||
}
|
||||
|
||||
extern uint32_t pci_read_field(uint32_t device, int field, int size);
|
||||
extern void pci_write_field(uint32_t device, int field, int size, uint32_t value);
|
||||
extern uint16_t pci_find_type(uint32_t dev);
|
||||
|
||||
extern uint32_t pci_device_read_field(struct device *dev, int field, int size);
|
||||
extern void pci_device_write_field(struct device *dev, int field, int size, uint32_t value);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user