Implement serial logging. Finish modularizing power management.
[monolithium.git] / kernel / include / pci.h
index e27058ba8c9ccb82fe1bd6355f302329dcb93a3d..29c1d55b3b1bb18ffcf8993fc724c828a5666b80 100644 (file)
 #include <common.h>
 #include <sdk/list.h>
 
+#define PCI_FIELD_REG(h, p) (OFFSET_OF(h, p) >> 2)
+#define PCI_FIELD_BIT_OFFSET(h, p) ((OFFSET_OF(h, p) & 3) << 3)
+#define PCI_FIELD_SIZE_MASK(h, p) ((sizeof(((h*)NULL)->p) == 1) ? 0xFF : ((sizeof(((h*)NULL)->p) == 2) ? 0xFFFF : 0xFFFFFFFF))
+#define PCI_FIELD_MASK(h, p) (PCI_FIELD_SIZE_MASK(h, p) << PCI_FIELD_BIT_OFFSET(h, p))
+#define PCI_READ_VALUE(d, h, p) ((pci_read((d), PCI_FIELD_REG(h, p)) >> PCI_FIELD_BIT_OFFSET(h, p)) & PCI_FIELD_SIZE_MASK(h, p))
+#define PCI_WRITE_VALUE(d, h, p, v) pci_write((d),                      \
+                                              PCI_FIELD_REG(h, p),      \
+                                              (((v) << PCI_FIELD_BIT_OFFSET(h, p)) & PCI_FIELD_MASK(h, p)) \
+                                              | (pci_read((d), PCI_FIELD_REG(h, p)) & ~PCI_FIELD_MASK(h, p)))
+
 #pragma pack(push, 1)
 
 typedef struct
@@ -99,6 +109,7 @@ enum
     PCI_NETWORK_DEVICE,
     PCI_DISPLAY_DEVICE,
     PCI_MULTIMEDIA_DEVICE,
+    PCI_MEMORY_DEVICE,
     PCI_BRIDGE_DEVICE,
     PCI_COMMUNICATION_DEVICE,
     PCI_PERIPHERAL_DEVICE,