[Intel-gfx] [PATCH 3/3] drm/i915: Lookup stolen region reserved during early PCI quirk processing

2013-07-25 Thread Chris Wilson
As we now hook into the early PCI quirk table to earmark the Intel
Graphics Stolen region (inserting it into the iomem_resource) to prevent
it conflicting with any later resource allocations, we can simply walk
the iomem_resource tree and find it for our use. Thereby removing all of
our own code to define the stolen region.

Signed-off-by: Chris Wilson ch...@chris-wilson.co.uk
---
 drivers/char/agp/intel-gtt.c   | 92 +++---
 drivers/gpu/drm/i915/i915_drv.h|  3 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c| 15 +-
 drivers/gpu/drm/i915/i915_gem_stolen.c | 70 ++
 include/drm/intel-gtt.h|  2 +-
 5 files changed, 26 insertions(+), 156 deletions(-)

diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index b8e2014..fe31280 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -343,90 +343,15 @@ static const struct aper_size_info_fixed 
intel_fake_agp_sizes[] = {
 
 static unsigned int intel_gtt_stolen_size(void)
 {
-   u16 gmch_ctrl;
-   u8 rdct;
-   int local = 0;
-   static const int ddt[4] = { 0, 16, 32, 64 };
-   unsigned int stolen_size = 0;
-
-   if (INTEL_GTT_GEN == 1)
-   return 0; /* no stolen mem on i81x */
-
-   pci_read_config_word(intel_private.bridge_dev,
-I830_GMCH_CTRL, gmch_ctrl);
+   struct resource *r;
+   unsigned int stolen_size;
 
-   if (intel_private.bridge_dev-device == PCI_DEVICE_ID_INTEL_82830_HB ||
-   intel_private.bridge_dev-device == PCI_DEVICE_ID_INTEL_82845G_HB) {
-   switch (gmch_ctrl  I830_GMCH_GMS_MASK) {
-   case I830_GMCH_GMS_STOLEN_512:
-   stolen_size = KB(512);
-   break;
-   case I830_GMCH_GMS_STOLEN_1024:
-   stolen_size = MB(1);
-   break;
-   case I830_GMCH_GMS_STOLEN_8192:
-   stolen_size = MB(8);
-   break;
-   case I830_GMCH_GMS_LOCAL:
-   rdct = 
readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
-   stolen_size = (I830_RDRAM_ND(rdct) + 1) *
-   MB(ddt[I830_RDRAM_DDT(rdct)]);
-   local = 1;
-   break;
-   default:
-   stolen_size = 0;
-   break;
-   }
-   } else {
-   switch (gmch_ctrl  I855_GMCH_GMS_MASK) {
-   case I855_GMCH_GMS_STOLEN_1M:
-   stolen_size = MB(1);
-   break;
-   case I855_GMCH_GMS_STOLEN_4M:
-   stolen_size = MB(4);
-   break;
-   case I855_GMCH_GMS_STOLEN_8M:
-   stolen_size = MB(8);
-   break;
-   case I855_GMCH_GMS_STOLEN_16M:
-   stolen_size = MB(16);
-   break;
-   case I855_GMCH_GMS_STOLEN_32M:
-   stolen_size = MB(32);
-   break;
-   case I915_GMCH_GMS_STOLEN_48M:
-   stolen_size = MB(48);
-   break;
-   case I915_GMCH_GMS_STOLEN_64M:
-   stolen_size = MB(64);
-   break;
-   case G33_GMCH_GMS_STOLEN_128M:
-   stolen_size = MB(128);
-   break;
-   case G33_GMCH_GMS_STOLEN_256M:
-   stolen_size = MB(256);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_96M:
-   stolen_size = MB(96);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_160M:
-   stolen_size = MB(160);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_224M:
-   stolen_size = MB(224);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_352M:
-   stolen_size = MB(352);
-   break;
-   default:
-   stolen_size = 0;
-   break;
-   }
-   }
+   r = lookup_resource_by_name(iomem_resource, E820_STOLEN_IGFX_STRING);
 
-   if (stolen_size  0) {
-   dev_info(intel_private.bridge_dev-dev, detected %dK %s 
memory\n,
-  stolen_size / KB(1), local ? local : stolen);
+   if (r) {
+   stolen_size = r-end - r-start + 1;
+   dev_info(intel_private.bridge_dev-dev, detected %dK stolen 
memory\n,
+  stolen_size / KB(1));
} else {
dev_info(intel_private.bridge_dev-dev,
   no pre-allocated video memory detected\n);
@@ -1404,11 +1329,10 @@ int intel_gmch_probe(struct pci_dev 

[Intel-gfx] [PATCH 3/3] drm/i915: Lookup stolen region reserved during early PCI quirk processing

2013-07-25 Thread Chris Wilson
As we now hook into the early PCI quirk table to earmark the Intel
Graphics Stolen region (inserting it into the iomem_resource) to prevent
it conflicting with any later resource allocations, we can simply walk
the iomem_resource tree and find it for our use. Thereby removing all of
our own code to define the stolen region.

Signed-off-by: Chris Wilson ch...@chris-wilson.co.uk
---
 drivers/char/agp/intel-gtt.c   | 93 +++---
 drivers/gpu/drm/i915/i915_drv.h|  3 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c| 15 +-
 drivers/gpu/drm/i915/i915_gem_stolen.c | 70 +
 include/drm/intel-gtt.h|  2 +-
 5 files changed, 26 insertions(+), 157 deletions(-)

diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index b8e2014..586efed 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -343,90 +343,14 @@ static const struct aper_size_info_fixed 
intel_fake_agp_sizes[] = {
 
 static unsigned int intel_gtt_stolen_size(void)
 {
-   u16 gmch_ctrl;
-   u8 rdct;
-   int local = 0;
-   static const int ddt[4] = { 0, 16, 32, 64 };
-   unsigned int stolen_size = 0;
-
-   if (INTEL_GTT_GEN == 1)
-   return 0; /* no stolen mem on i81x */
-
-   pci_read_config_word(intel_private.bridge_dev,
-I830_GMCH_CTRL, gmch_ctrl);
-
-   if (intel_private.bridge_dev-device == PCI_DEVICE_ID_INTEL_82830_HB ||
-   intel_private.bridge_dev-device == PCI_DEVICE_ID_INTEL_82845G_HB) {
-   switch (gmch_ctrl  I830_GMCH_GMS_MASK) {
-   case I830_GMCH_GMS_STOLEN_512:
-   stolen_size = KB(512);
-   break;
-   case I830_GMCH_GMS_STOLEN_1024:
-   stolen_size = MB(1);
-   break;
-   case I830_GMCH_GMS_STOLEN_8192:
-   stolen_size = MB(8);
-   break;
-   case I830_GMCH_GMS_LOCAL:
-   rdct = 
readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
-   stolen_size = (I830_RDRAM_ND(rdct) + 1) *
-   MB(ddt[I830_RDRAM_DDT(rdct)]);
-   local = 1;
-   break;
-   default:
-   stolen_size = 0;
-   break;
-   }
-   } else {
-   switch (gmch_ctrl  I855_GMCH_GMS_MASK) {
-   case I855_GMCH_GMS_STOLEN_1M:
-   stolen_size = MB(1);
-   break;
-   case I855_GMCH_GMS_STOLEN_4M:
-   stolen_size = MB(4);
-   break;
-   case I855_GMCH_GMS_STOLEN_8M:
-   stolen_size = MB(8);
-   break;
-   case I855_GMCH_GMS_STOLEN_16M:
-   stolen_size = MB(16);
-   break;
-   case I855_GMCH_GMS_STOLEN_32M:
-   stolen_size = MB(32);
-   break;
-   case I915_GMCH_GMS_STOLEN_48M:
-   stolen_size = MB(48);
-   break;
-   case I915_GMCH_GMS_STOLEN_64M:
-   stolen_size = MB(64);
-   break;
-   case G33_GMCH_GMS_STOLEN_128M:
-   stolen_size = MB(128);
-   break;
-   case G33_GMCH_GMS_STOLEN_256M:
-   stolen_size = MB(256);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_96M:
-   stolen_size = MB(96);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_160M:
-   stolen_size = MB(160);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_224M:
-   stolen_size = MB(224);
-   break;
-   case INTEL_GMCH_GMS_STOLEN_352M:
-   stolen_size = MB(352);
-   break;
-   default:
-   stolen_size = 0;
-   break;
-   }
-   }
+   struct resource *r;
+   unsigned int stolen_size;
 
-   if (stolen_size  0) {
-   dev_info(intel_private.bridge_dev-dev, detected %dK %s 
memory\n,
-  stolen_size / KB(1), local ? local : stolen);
+   r = lookup_resource_by_name(iomem_resource, E820_STOLEN_IGFX_STRING);
+   if (r) {
+   stolen_size = r-end - r-start + 1;
+   dev_info(intel_private.bridge_dev-dev, detected %dK stolen 
memory\n,
+  stolen_size / KB(1));
} else {
dev_info(intel_private.bridge_dev-dev,
   no pre-allocated video memory detected\n);
@@ -1404,11 +1328,10 @@ int intel_gmch_probe(struct pci_dev