]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/gpu/drm/i915/i915_gem_stolen.c
drm/i915: Rearrange i915_wait_request() accounting with callers
[karo-tx-linux.git] / drivers / gpu / drm / i915 / i915_gem_stolen.c
index 66be299a1486f4f656ba4e3970249a0e5e909aeb..f4f6d3a48b050c7ee0e23bae53fab4577acc7235 100644 (file)
@@ -92,6 +92,7 @@ void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
 static unsigned long i915_stolen_to_physical(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = to_i915(dev);
+       struct pci_dev *pdev = dev_priv->drm.pdev;
        struct i915_ggtt *ggtt = &dev_priv->ggtt;
        struct resource *r;
        u32 base;
@@ -111,43 +112,54 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
        if (INTEL_INFO(dev)->gen >= 3) {
                u32 bsm;
 
-               pci_read_config_dword(dev->pdev, INTEL_BSM, &bsm);
+               pci_read_config_dword(pdev, INTEL_BSM, &bsm);
 
                base = bsm & INTEL_BSM_MASK;
-       } else if (IS_I865G(dev)) {
+       } else if (IS_I865G(dev_priv)) {
+               u32 tseg_size = 0;
                u16 toud = 0;
+               u8 tmp;
 
-               /*
-                * FIXME is the graphics stolen memory region
-                * always at TOUD? Ie. is it always the last
-                * one to be allocated by the BIOS?
-                */
-               pci_bus_read_config_word(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
+                                        I845_ESMRAMC, &tmp);
+
+               if (tmp & TSEG_ENABLE) {
+                       switch (tmp & I845_TSEG_SIZE_MASK) {
+                       case I845_TSEG_SIZE_512K:
+                               tseg_size = KB(512);
+                               break;
+                       case I845_TSEG_SIZE_1M:
+                               tseg_size = MB(1);
+                               break;
+                       }
+               }
+
+               pci_bus_read_config_word(pdev->bus, PCI_DEVFN(0, 0),
                                         I865_TOUD, &toud);
 
-               base = toud << 16;
+               base = (toud << 16) + tseg_size;
        } else if (IS_I85X(dev)) {
                u32 tseg_size = 0;
                u32 tom;
                u8 tmp;
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
                                         I85X_ESMRAMC, &tmp);
 
                if (tmp & TSEG_ENABLE)
                        tseg_size = MB(1);
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 1),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 1),
                                         I85X_DRB3, &tmp);
                tom = tmp * MB(32);
 
                base = tom - tseg_size - ggtt->stolen_size;
-       } else if (IS_845G(dev)) {
+       } else if (IS_845G(dev_priv)) {
                u32 tseg_size = 0;
                u32 tom;
                u8 tmp;
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
                                         I845_ESMRAMC, &tmp);
 
                if (tmp & TSEG_ENABLE) {
@@ -161,17 +173,17 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
                        }
                }
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
                                         I830_DRB3, &tmp);
                tom = tmp * MB(32);
 
                base = tom - tseg_size - ggtt->stolen_size;
-       } else if (IS_I830(dev)) {
+       } else if (IS_I830(dev_priv)) {
                u32 tseg_size = 0;
                u32 tom;
                u8 tmp;
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
                                         I830_ESMRAMC, &tmp);
 
                if (tmp & TSEG_ENABLE) {
@@ -181,7 +193,7 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
                                tseg_size = KB(512);
                }
 
-               pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0),
+               pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
                                         I830_DRB3, &tmp);
                tom = tmp * MB(32);
 
@@ -192,7 +204,8 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
                return 0;
 
        /* make sure we don't clobber the GTT if it's within stolen memory */
-       if (INTEL_INFO(dev)->gen <= 4 && !IS_G33(dev) && !IS_G4X(dev)) {
+       if (INTEL_GEN(dev_priv) <= 4 && !IS_G33(dev_priv) &&
+           !IS_G4X(dev_priv)) {
                struct {
                        u32 start, end;
                } stolen[2] = {
@@ -202,7 +215,7 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
                u64 ggtt_start, ggtt_end;
 
                ggtt_start = I915_READ(PGTBL_CTL);
-               if (IS_GEN4(dev))
+               if (IS_GEN4(dev_priv))
                        ggtt_start = (ggtt_start & PGTBL_ADDRESS_LO_MASK) |
                                     (ggtt_start & PGTBL_ADDRESS_HI_MASK) << 28;
                else
@@ -258,7 +271,7 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
                 * GEN3 firmware likes to smash pci bridges into the stolen
                 * range. Apparently this works.
                 */
-               if (r == NULL && !IS_GEN3(dev)) {
+               if (r == NULL && !IS_GEN3(dev_priv)) {
                        DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n",
                                  base, base + (uint32_t)ggtt->stolen_size);
                        base = 0;
@@ -425,7 +438,7 @@ int i915_gem_init_stolen(struct drm_device *dev)
        case 3:
                break;
        case 4:
-               if (IS_G4X(dev))
+               if (IS_G4X(dev_priv))
                        g4x_get_stolen_reserved(dev_priv, &reserved_base,
                                                &reserved_size);
                break;
@@ -444,7 +457,7 @@ int i915_gem_init_stolen(struct drm_device *dev)
                break;
        default:
                if (IS_BROADWELL(dev_priv) ||
-                   IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev))
+                   IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
                        bdw_get_stolen_reserved(dev_priv, &reserved_base,
                                                &reserved_size);
                else
@@ -685,7 +698,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
        if (gtt_offset == I915_GTT_OFFSET_NONE)
                return obj;
 
-       vma = i915_gem_obj_lookup_or_create_vma(obj, &ggtt->base);
+       vma = i915_gem_obj_lookup_or_create_vma(obj, &ggtt->base, NULL);
        if (IS_ERR(vma)) {
                ret = PTR_ERR(vma);
                goto err;
@@ -698,24 +711,25 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
         */
        vma->node.start = gtt_offset;
        vma->node.size = size;
-       if (drm_mm_initialized(&ggtt->base.mm)) {
-               ret = drm_mm_reserve_node(&ggtt->base.mm, &vma->node);
-               if (ret) {
-                       DRM_DEBUG_KMS("failed to allocate stolen GTT space\n");
-                       goto err;
-               }
 
-               vma->bound |= GLOBAL_BIND;
-               __i915_vma_set_map_and_fenceable(vma);
-               list_add_tail(&vma->vm_link, &ggtt->base.inactive_list);
+       ret = drm_mm_reserve_node(&ggtt->base.mm, &vma->node);
+       if (ret) {
+               DRM_DEBUG_KMS("failed to allocate stolen GTT space\n");
+               goto err;
        }
 
+       vma->pages = obj->pages;
+       vma->flags |= I915_VMA_GLOBAL_BIND;
+       __i915_vma_set_map_and_fenceable(vma);
+       list_move_tail(&vma->vm_link, &ggtt->base.inactive_list);
+       obj->bind_count++;
+
        list_add_tail(&obj->global_list, &dev_priv->mm.bound_list);
        i915_gem_object_pin_pages(obj);
 
        return obj;
 
 err:
-       drm_gem_object_unreference(&obj->base);
+       i915_gem_object_put(obj);
        return NULL;
 }