2 #include <sys/pci_hba.h>
5 pci_setup_msi(struct pci_device* device, int vector)
7 // Dest: APIC#0, Physical Destination, No redirection
8 u32_t msi_addr = (__APIC_BASE_PADDR);
10 // Edge trigger, Fixed delivery
11 u32_t msi_data = vector;
14 device->cspace_base, PCI_MSI_ADDR(device->msi_loc), msi_addr);
16 pci_reg_t reg1 = pci_read_cspace(device->cspace_base, device->msi_loc);
17 pci_reg_t msg_ctl = reg1 >> 16;
19 int offset = !!(msg_ctl & MSI_CAP_64BIT) * 4;
20 pci_write_cspace(device->cspace_base,
21 PCI_MSI_DATA(device->msi_loc, offset),
24 if ((msg_ctl & MSI_CAP_MASK)) {
26 device->cspace_base, PCI_MSI_MASK(device->msi_loc, offset), 0);
29 // manipulate the MSI_CTRL to allow device using MSI to request service.
30 reg1 = (reg1 & 0xff8fffff) | 0x10000;
31 pci_write_cspace(device->cspace_base, device->msi_loc, reg1);