agp: Remove support for Valleyview hardware
[dragonfly.git] / sys / dev / agp / agp_i810.c
index cfe9902..657efff 100644 (file)
 #include <vm/vm.h>
 #include <vm/vm_object.h>
 #include <vm/vm_page.h>
+#include <vm/vm_param.h>
 #include <vm/vm_pageout.h>
 #include <vm/pmap.h>
 
+#include <vm/vm_page2.h>
+
 #include <machine/md_var.h>
 
 #define bus_read_1(r, o) \
@@ -99,8 +102,10 @@ static int agp_sb_get_gtt_total_entries(device_t dev);
 static int agp_gen8_get_gtt_total_entries(device_t dev);
 
 static int agp_i830_install_gatt(device_t dev);
+static int agp_sb_install_gatt(device_t dev);
 
 static void agp_i830_deinstall_gatt(device_t dev);
+static void agp_sb_deinstall_gatt(device_t dev);
 
 static void agp_i915_install_gtt_pte(device_t dev, u_int index,
     vm_offset_t physical, int flags);
@@ -182,7 +187,7 @@ struct agp_i810_softc {
        u_int gtt_mappable_entries;     /* Number of gtt ptes mappable by CPU */
        device_t bdev;                  /* bridge device */
        void *argb_cursor;              /* contigmalloc area for ARGB cursor */
-       struct resource *sc_res[2];
+       struct resource *sc_res[3];
        const struct agp_i810_match *match;
        int sc_flush_page_rid;
        struct resource *sc_flush_page_res;
@@ -339,30 +344,8 @@ static const struct agp_i810_driver agp_i810_sb_driver = {
        .get_stolen_size = agp_sb_get_stolen_size,
        .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
        .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
-       .install_gatt = agp_i830_install_gatt,
-       .deinstall_gatt = agp_i830_deinstall_gatt,
-       .write_gtt = agp_sb_write_gtt,
-       .install_gtt_pte = agp_sb_install_gtt_pte,
-       .sync_gtt_pte = agp_g4x_sync_gtt_pte,
-       .set_aperture = agp_i915_set_aperture,
-       .chipset_flush_setup = agp_i810_chipset_flush_setup,
-       .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
-       .chipset_flush = agp_i810_chipset_flush,
-};
-
-static const struct agp_i810_driver valleyview_gtt_driver = {
-       .chiptype = CHIP_SB,
-       .gen = 7,
-       .busdma_addr_mask_sz = 40,
-       .res_spec = agp_g4x_res_spec,
-       .check_active = agp_sb_check_active,
-       .set_desc = agp_i810_set_desc,
-       .dump_regs = agp_sb_dump_regs,
-       .get_stolen_size = agp_sb_get_stolen_size,
-       .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
-       .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
-       .install_gatt = agp_i830_install_gatt,
-       .deinstall_gatt = agp_i830_deinstall_gatt,
+       .install_gatt = agp_sb_install_gatt,
+       .deinstall_gatt = agp_sb_deinstall_gatt,
        .write_gtt = agp_sb_write_gtt,
        .install_gtt_pte = agp_sb_install_gtt_pte,
        .sync_gtt_pte = agp_g4x_sync_gtt_pte,
@@ -589,11 +572,6 @@ static const struct agp_i810_match {
                .name = "IvyBridge server GT2 IG",
                .driver = &agp_i810_sb_driver
        },
-       {
-               .devid = 0x0f30,
-               .name = "ValleyView",
-               .driver = &valleyview_gtt_driver
-       },
        {
                .devid = 0x0402,
                .name = "Haswell desktop GT1 IG",
@@ -665,6 +643,7 @@ static const struct agp_i810_match {
        {       0x160B, "Broadwell", &broadwell_gtt_driver },
        {       0x160E, "Broadwell", &broadwell_gtt_driver },
        {       0x1616, "Broadwell", &broadwell_gtt_driver },
+       {       0x161E, "Broadwell", &broadwell_gtt_driver },
 
        {       0x160A, "Broadwell", &broadwell_gtt_driver }, /* d */
        {       0x160D, "Broadwell", &broadwell_gtt_driver },
@@ -745,7 +724,7 @@ agp_i810_probe(device_t dev)
 {
        device_t bdev;
        const struct agp_i810_match *match;
-       int err;
+       int err = 0;
 
        if (resource_disabled("agp", device_get_unit(dev)))
                return (ENXIO);
@@ -763,11 +742,13 @@ agp_i810_probe(device_t dev)
        /*
         * checking whether internal graphics device has been activated.
         */
-       err = match->driver->check_active(bdev);
-       if (err != 0) {
-               if (bootverbose)
-                       kprintf("i810: disabled, not probing\n");
-               return (err);
+       if (match->driver->check_active != NULL) {
+               err = match->driver->check_active(bdev);
+               if (err != 0) {
+                       if (bootverbose)
+                               kprintf("i810: disabled, not probing\n");
+                       return (err);
+               }
        }
 
        match->driver->set_desc(dev, match);
@@ -795,9 +776,9 @@ agp_i965_dump_regs(device_t dev)
        device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
            bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
        device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
-           pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
+           pci_read_config(dev, AGP_I855_GCC1, 1));
        device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
-           pci_read_config(sc->bdev, AGP_I965_MSAC, 1));
+           pci_read_config(dev, AGP_I965_MSAC, 1));
 }
 
 static void
@@ -808,7 +789,7 @@ agp_sb_dump_regs(device_t dev)
        device_printf(dev, "AGP_SNB_GFX_MODE: %08x\n",
            bus_read_4(sc->sc_res[0], AGP_SNB_GFX_MODE));
        device_printf(dev, "AGP_SNB_GCC1: 0x%04x\n",
-           pci_read_config(sc->bdev, AGP_SNB_GCC1, 2));
+           pci_read_config(dev, AGP_SNB_GCC1, 2));
 }
 
 static int
@@ -959,7 +940,8 @@ agp_sb_get_stolen_size(device_t dev)
        uint16_t gmch_ctl;
 
        sc = device_get_softc(dev);
-       gmch_ctl = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
+       gmch_ctl = pci_read_config(dev, AGP_SNB_GCC1, 2);
+
        switch (gmch_ctl & AGP_SNB_GMCH_GMS_STOLEN_MASK) {
        case AGP_SNB_GMCH_GMS_STOLEN_32M:
                sc->stolen_size = 32 * 1024 * 1024;
@@ -1022,10 +1004,9 @@ agp_gen8_get_stolen_size(device_t dev)
        int v;
 
        sc = device_get_softc(dev);
-       gcc1 = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
+       gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
        v = (gcc1 >> 8) & 0xFF;
        sc->stolen_size = v * (32L * 1024 * 1024);      /* 32MB increments */
-       kprintf("GTT STOLEN %ld\n", (long)sc->stolen_size);
 
        return 0;
 }
@@ -1146,7 +1127,7 @@ agp_sb_get_gtt_total_entries(device_t dev)
 
        sc = device_get_softc(dev);
 
-       gcc1 = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
+       gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
        switch (gcc1 & AGP_SNB_GTT_SIZE_MASK) {
        default:
        case AGP_SNB_GTT_SIZE_0M:
@@ -1171,7 +1152,7 @@ agp_gen8_get_gtt_total_entries(device_t dev)
 
        sc = device_get_softc(dev);
 
-       gcc1 = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
+       gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
        v = (gcc1 >> 6) & 3;
        if (v)
                v = 1 << v;
@@ -1211,6 +1192,26 @@ agp_i830_install_gatt(device_t dev)
        return (0);
 }
 
+static int
+agp_sb_install_gatt(device_t dev)
+{
+       struct agp_i810_softc *sc;
+       uint32_t pgtblctl;
+
+       sc = device_get_softc(dev);
+
+       /*
+        * The i830 automatically initializes the 128k gatt on boot.
+        * GATT address is already in there, make sure it's enabled.
+        */
+       pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
+       pgtblctl |= 1;
+       bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
+
+       sc->gatt->ag_physical = pgtblctl & ~1;
+       return (0);
+}
+
 static int
 agp_i810_attach(device_t dev)
 {
@@ -1288,6 +1289,20 @@ agp_i830_deinstall_gatt(device_t dev)
        bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
 }
 
+static void
+agp_sb_deinstall_gatt(device_t dev)
+{
+       struct agp_i810_softc *sc;
+       unsigned int pgtblctl;
+
+       sc = device_get_softc(dev);
+       if (sc->sc_res[0]) {
+               pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
+               pgtblctl &= ~1;
+               bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
+       }
+}
+
 static int
 agp_i810_detach(device_t dev)
 {
@@ -1383,7 +1398,7 @@ agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
        struct agp_i810_softc *sc;
 
        sc = device_get_softc(dev);
-       bus_write_4(sc->sc_res[1], index * 4, pte);
+       bus_write_4(sc->sc_res[0], index * 4, pte);
 }
 
 static void
@@ -2145,11 +2160,14 @@ intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
 void intel_gtt_get(size_t *gtt_total, size_t *stolen_size,
                   phys_addr_t *mappable_base, unsigned long *mappable_end)
 {
+       struct agp_info ainfo;
+
        intel_private.base = agp_intel_gtt_get(intel_agp);
 
        *gtt_total = intel_private.base.gtt_total_entries << PAGE_SHIFT;
        *stolen_size = intel_private.base.stolen_size;
-       *mappable_base = intel_private.base.gma_bus_addr;
+       agp_get_info(intel_agp, &ainfo);
+       *mappable_base = ainfo.ai_aperture_base;
        *mappable_end = intel_private.base.gtt_mappable_entries << PAGE_SHIFT;
 }