|
@@ -576,6 +576,64 @@ int pci_enable_msi(void *header, uint8_t vector, uint32_t processor, uint8_t edg
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief 在已配置好msi寄存器的设备上,使能msi
|
|
|
+ *
|
|
|
+ * @param header 设备头部
|
|
|
+ * @return int 返回码
|
|
|
+ */
|
|
|
+int pci_start_msi(void *header)
|
|
|
+{
|
|
|
+ struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header;
|
|
|
+ uint32_t cap_ptr;
|
|
|
+ uint32_t tmp;
|
|
|
+
|
|
|
+ switch (ptr->HeaderType)
|
|
|
+ {
|
|
|
+ case 0x00: // general device
|
|
|
+ if (!(ptr->Status & 0x10))
|
|
|
+ return E_NOT_SUPPORT_MSI;
|
|
|
+ cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer;
|
|
|
+
|
|
|
+ tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
+
|
|
|
+ if (tmp & 0xff != 0x5)
|
|
|
+ return E_NOT_SUPPORT_MSI;
|
|
|
+
|
|
|
+ // 使能msi
|
|
|
+ tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
+ tmp |= (1 << 16);
|
|
|
+ pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x01: // pci to pci bridge
|
|
|
+ if (!(ptr->Status & 0x10))
|
|
|
+ return E_NOT_SUPPORT_MSI;
|
|
|
+ cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer;
|
|
|
+
|
|
|
+ tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
+
|
|
|
+ if (tmp & 0xff != 0x5)
|
|
|
+ return E_NOT_SUPPORT_MSI;
|
|
|
+
|
|
|
+ //使能msi
|
|
|
+ tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
+ tmp |= (1 << 16);
|
|
|
+ pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 0x02: // pci to card bus bridge
|
|
|
+ return E_NOT_SUPPORT_MSI;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default: // 不应该到达这里
|
|
|
+ return E_WRONG_HEADER_TYPE;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
/**
|
|
|
* @brief 禁用指定设备的msi
|
|
|
*
|
|
@@ -587,8 +645,7 @@ int pci_disable_msi(void *header)
|
|
|
struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header;
|
|
|
uint32_t cap_ptr;
|
|
|
uint32_t tmp;
|
|
|
- uint16_t message_control;
|
|
|
- uint64_t message_addr;
|
|
|
+
|
|
|
switch (ptr->HeaderType)
|
|
|
{
|
|
|
case 0x00: // general device
|
|
@@ -598,8 +655,6 @@ int pci_disable_msi(void *header)
|
|
|
|
|
|
tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
|
|
|
- message_control = (tmp >> 16) & 0xffff;
|
|
|
-
|
|
|
if (tmp & 0xff != 0x5)
|
|
|
return E_NOT_SUPPORT_MSI;
|
|
|
|
|
@@ -617,8 +672,6 @@ int pci_disable_msi(void *header)
|
|
|
|
|
|
tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值
|
|
|
|
|
|
- message_control = (tmp >> 16) & 0xffff;
|
|
|
-
|
|
|
if (tmp & 0xff != 0x5)
|
|
|
return E_NOT_SUPPORT_MSI;
|
|
|
|