refactor: make pci device driver loading passive, pci bus scanner will not load them...
[lunaix-os.git] / lunaix-os / hal / gfxa / vga / vga_pci.c
index baf7fa4f49f8461e07e2d8df2f6888d82c038b48..09476db5efd958f5ad57ef7b13e4286dbb5fe7a1 100644 (file)
@@ -4,6 +4,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 
+#include <hal/gfxm.h>
 #include <hal/pci.h>
 #include <sys/pci_hba.h>
 
 #include <hal/pci.h>
 #include <sys/pci_hba.h>
 
@@ -58,7 +59,7 @@ static u32_t palette[] = {
 #define VGA_REG_OFF 0x0400
 
 static int
 #define VGA_REG_OFF 0x0400
 
 static int
-vga_pci_init(struct device_def* devdef, struct device* pcidev_base)
+vga_pci_bind(struct device_def* devdef, struct device* pcidev_base)
 {
     struct pci_device* pcidev = PCI_DEVICE(pcidev_base);
 
 {
     struct pci_device* pcidev = PCI_DEVICE(pcidev_base);
 
@@ -81,26 +82,36 @@ vga_pci_init(struct device_def* devdef, struct device* pcidev_base)
     struct vga* vga_state =
       vga_new_state(mmio_mapped + VGA_REG_OFF, fb_mapped, FB256K);
     vga_state->reg_ops = vga_default_mmio_ops;
     struct vga* vga_state =
       vga_new_state(mmio_mapped + VGA_REG_OFF, fb_mapped, FB256K);
     vga_state->reg_ops = vga_default_mmio_ops;
-    vga_state->lut.colors = palette;
-    vga_state->lut.len = 256;
-    vga_state->options = VGA_MODE_GFX;
 
 
-    vga_config_rect(vga_state, 640, 360, 60, 0);
+    struct gfxa* vga_gfxa = gfxm_alloc_adapter(vga_state);
+    extern struct gfxa_ops vga_gfxa_ops;
+    vga_gfxa->ops = vga_gfxa_ops;
 
 
-    // TEMP: Test the change of VGA display mode and resolution
-    // vga_reload_config(vga_state);
+    // Preload a VESA-compilant configuration
+    vga_gfxa->disp_info = (struct disp_profile){
+        .mon = { .w_px = 640, .h_px = 480, .freq = 60, .depth = 16 }
+    };
+
+    gfxm_register(vga_gfxa);
 
     return 0;
 }
 
 
     return 0;
 }
 
+static int
+vga_pci_init(struct device_def* def)
+{
+    return pci_bind_definition_all(pcidev_def(def));
+}
+
 #define VGA_PCI_CLASS 0x30000
 
 static struct pci_device_def vga_pci_devdef = {
     .dev_class = VGA_PCI_CLASS,
     .dev_ident = PCI_DEVIDENT(0x1234, 0x1111),
 #define VGA_PCI_CLASS 0x30000
 
 static struct pci_device_def vga_pci_devdef = {
     .dev_class = VGA_PCI_CLASS,
     .dev_ident = PCI_DEVIDENT(0x1234, 0x1111),
-    .ident_mask = -1,
+    .ident_mask = PCI_MATCH_EXACT,
     .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_DISP, DEV_VGA),
     .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_DISP, DEV_VGA),
-                .name = "VGA Generic Driver",
-                .init_for = vga_pci_init }
+                .name = "Generic VGA",
+                .init = vga_pci_init,
+                .bind = vga_pci_bind }
 };
 };
-EXPORT_DEVICE(vga_pci, &vga_pci_devdef.devdef, load_pci_probe);
\ No newline at end of file
+EXPORT_PCI_DEVICE(vga_pci, &vga_pci_devdef, load_onboot);
\ No newline at end of file