Skip to contentSkip to conversation

x86: Use a custom name for the Intel Graphics Stolen reservation

PATCH New Chris Wilson 1 participant 3 messages Jul 25, 2013

Subsystems (5)
DRM drivers x86 Intel i915 PCI +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 x86: Use a custom name for the Intel Graphics Stolen reservation

By giving the stolen a region a unique type and name, we then insert it into the iomem_resource as a known resource. This clear identifies it to the user when printing the e820 map (and later the iomem resources), and exposes it to the driver for later use.

v2: Also need to add the string to a second id-to-name switch

---
 arch/x86/include/uapi/asm/e820.h |  2 ++
 arch/x86/kernel/e820.c           |  5 +++++
 arch/x86/kernel/early-quirks.c   | 12 ++----------
 3 files changed, 9 insertions(+), 10 deletions(-)
arch/x86/include/uapi/asm/e820.h +2 -0
index bbae024..72384ce 100644
@@ -38,6 +38,8 @@
 #define E820_NVS	4
 #define E820_UNUSABLE	5
 
+#define E820_STOLEN_IGFX 6
+#define E820_STOLEN_IGFX_STRING "Intel Graphics Stolen"
 
 /*
  * reserved RAM used by kernel itself
arch/x86/kernel/e820.c +5 -0
index d32abea..3918f4d3 100644
@@ -149,6 +149,10 @@ static void __init e820_print_type(u32 type)
 	case E820_UNUSABLE:
 		printk(KERN_CONT "unusable");
 		break;
+
+	case E820_STOLEN_IGFX:
+		printk(KERN_CONT E820_STOLEN_IGFX_STRING);
+		break;
 	default:
 		printk(KERN_CONT "type %u", type);
 		break;
@@ -915,6 +919,7 @@ static inline const char *e820_type_to_string(int e820_type)
 	case E820_ACPI:	return "ACPI Tables";
 	case E820_NVS:	return "ACPI Non-volatile Storage";
 	case E820_UNUSABLE:	return "Unusable memory";
+	case E820_STOLEN_IGFX: return E820_STOLEN_IGFX_STRING;
 	default:	return "reserved";
 	}
 }
arch/x86/kernel/early-quirks.c +2 -10
index bff8a6f..27b6d17 100644
@@ -350,18 +350,10 @@ static void __init intel_graphics_stolen(int num, int slot, int func)
 			size = stolen_size(num, slot, func);
 			start = intel_stolen_base(num, slot, func);
 			if (size && start)
-				goto found;
-			else
-				break;
+				e820_add_region(start, size, E820_STOLEN_IGFX);
+			return;
 		}
 	}
-
-	/* No match or invalid data, don't bother reserving */
-	return;
-found:
-	/* Mark this space as reserved */
-	e820_add_region(start, size, E820_RESERVED);
-	return;
 }
 
 #define QFLAG_APPLY_ONCE 	0x1
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/3 resource: Introduce lookup_resource_by_name()

This is useful for drivers to find a resource inserted by, for example, an early PCI quirk.

v2: We need to recurse through the resource tree as the named region we are looking for may be a grandchild of the root node.

---
 include/linux/ioport.h |  2 ++
 kernel/resource.c      | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
include/linux/ioport.h +2 -0
index 89b7c24..acad72f 100644
@@ -158,6 +158,8 @@ extern int allocate_resource(struct resource *root, struct resource *new,
 						       resource_size_t),
 			     void *alignf_data);
 struct resource *lookup_resource(struct resource *root, resource_size_t start);
+struct resource *lookup_resource_by_name(struct resource *root,
+					 const char *name);
 int adjust_resource(struct resource *res, resource_size_t start,
 		    resource_size_t size);
 resource_size_t resource_alignment(struct resource *res);
kernel/resource.c +30 -0
index 3f285dc..c6dd827 100644
@@ -624,6 +624,36 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start)
 	return res;
 }
 
+static struct resource *__lookup_resource_by_name(struct resource *res,
+						  const char *name)
+{
+	while (res) {
+		struct resource *child;
+
+		if (strcmp(res->name, name) == 0)
+			return res;
+
+		child = __lookup_resource_by_name(res->child, name);
+		if (child)
+			return child;
+
+		res = res->sibling;
+	}
+
+	return NULL;
+}
+
+struct resource *lookup_resource_by_name(struct resource *root, const char *name)
+{
+	struct resource *res;
+
+	read_lock(&resource_lock);
+	res = __lookup_resource_by_name(root->child, name);
+	read_unlock(&resource_lock);
+
+	return res;
+}
+
 /*
  * Insert a resource into the resource tree. If successful, return NULL,
  * otherwise return the conflicting resource (compare to __request_resource())
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 3/3 drm/i915: Lookup stolen region reserved during early PCI quirk processing

In reply to 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.

---
 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(-)
drivers/char/agp/intel-gtt.c +8 -85
index b8e2014..586efed 100644
@@ -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 *bridge_pdev, struct pci_dev *gpu_pdev,
 }
 EXPORT_SYMBOL(intel_gmch_probe);
 
-void intel_gtt_get(size_t *gtt_total, size_t *stolen_size,
+void intel_gtt_get(size_t *gtt_total,
 		   phys_addr_t *mappable_base, unsigned long *mappable_end)
 {
 	*gtt_total = intel_private.gtt_total_entries << PAGE_SHIFT;
-	*stolen_size = intel_private.stolen_size;
 	*mappable_base = intel_private.gma_bus_addr;
 	*mappable_end = intel_private.gtt_mappable_entries << PAGE_SHIFT;
 }
drivers/gpu/drm/i915/i915_drv.h +1 -2
index ae36612..ec14124 100644
@@ -513,7 +513,6 @@ struct i915_address_space {
  */
 struct i915_gtt {
 	struct i915_address_space base;
-	size_t stolen_size;		/* Total size of stolen memory */
 
 	unsigned long mappable_end;	/* End offset that we can CPU map */
 	struct io_mapping *mappable;	/* Mapping to our CPU mappable region */
@@ -528,7 +527,7 @@ struct i915_gtt {
 
 	/* global gtt ops */
 	int (*gtt_probe)(struct drm_device *dev, size_t *gtt_total,
-			  size_t *stolen, phys_addr_t *mappable_base,
+			  phys_addr_t *mappable_base,
 			  unsigned long *mappable_end);
 };
 #define gtt_total_entries(gtt) ((gtt).base.total >> PAGE_SHIFT)
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -13
index 3b639a9..1294cee 100644
@@ -784,16 +784,8 @@ static inline unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
 	return snb_gmch_ctl << 20;
 }
 
-static inline size_t gen6_get_stolen_size(u16 snb_gmch_ctl)
-{
-	snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT;
-	snb_gmch_ctl &= SNB_GMCH_GMS_MASK;
-	return snb_gmch_ctl << 25; /* 32 MB units */
-}
-
 static int gen6_gmch_probe(struct drm_device *dev,
 			   size_t *gtt_total,
-			   size_t *stolen,
 			   phys_addr_t *mappable_base,
 			   unsigned long *mappable_end)
 {
@@ -820,7 +812,6 @@ static int gen6_gmch_probe(struct drm_device *dev,
 	pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
 	gtt_size = gen6_get_total_gtt_size(snb_gmch_ctl);
 
-	*stolen = gen6_get_stolen_size(snb_gmch_ctl);
 	*gtt_total = (gtt_size / sizeof(gen6_gtt_pte_t)) << PAGE_SHIFT;
 
 	/* For Modern GENs the PTEs and register space are split in the BAR */
@@ -853,7 +844,6 @@ static void gen6_gmch_remove(struct i915_address_space *vm)
 
 static int i915_gmch_probe(struct drm_device *dev,
 			   size_t *gtt_total,
-			   size_t *stolen,
 			   phys_addr_t *mappable_base,
 			   unsigned long *mappable_end)
 {
@@ -866,7 +856,7 @@ static int i915_gmch_probe(struct drm_device *dev,
 		return -EIO;
 	}
 
-	intel_gtt_get(gtt_total, stolen, mappable_base, mappable_end);
+	intel_gtt_get(gtt_total, mappable_base, mappable_end);
 
 	dev_priv->gtt.do_idle_maps = needs_idle_maps(dev_priv->dev);
 	dev_priv->gtt.base.clear_range = i915_ggtt_clear_range;
@@ -902,7 +892,7 @@ int i915_gem_gtt_init(struct drm_device *dev)
 			gtt->base.pte_encode = gen6_pte_encode;
 	}
 
-	ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size,
+	ret = gtt->gtt_probe(dev, &gtt->base.total,
 			     &gtt->mappable_base, &gtt->mappable_end);
 	if (ret)
 		return ret;
@@ -913,7 +903,6 @@ int i915_gem_gtt_init(struct drm_device *dev)
 	DRM_INFO("Memory usable by graphics device = %zdM\n",
 		 gtt->base.total >> 20);
 	DRM_DEBUG_DRIVER("GMADR size = %ldM\n", gtt->mappable_end >> 20);
-	DRM_DEBUG_DRIVER("GTT stolen size = %zdM\n", gtt->stolen_size >> 20);
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_stolen.c +14 -56

105 lines not on this page · raw message

include/drm/intel-gtt.h +1 -1
index b08bdad..c0b5602 100644
@@ -3,7 +3,7 @@
 #ifndef _DRM_INTEL_GTT_H
 #define	_DRM_INTEL_GTT_H
 
-void intel_gtt_get(size_t *gtt_total, size_t *stolen_size,
+void intel_gtt_get(size_t *gtt_total,
 		   phys_addr_t *mappable_base, unsigned long *mappable_end);
 
 int intel_gmch_probe(struct pci_dev *bridge_pdev, struct pci_dev *gpu_pdev,
Signature · 1 line
1.8.3.2