mtrr: only add prefetchable resources as WRCOMB for VGA devices

Be more conservative and only add VGA devices' prefetchable
resources as write-combining in the address space. Previously
all prefetchable memory was added as a write-combining memory
type. Some hardware incorrectly advertises its BAR as
prefetchable when it shouldn't be.

A new memranges_add_resources_filter() function is added
to provide additional filtering on device and resource.

Change-Id: I3fc55b90d8c5b694c5aa9e2f34db1b4ef845ce10
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/5169
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Tested-by: build bot (Jenkins)
diff --git a/src/lib/memrange.c b/src/lib/memrange.c
index 7fb6ef7..a85bc01 100644
--- a/src/lib/memrange.c
+++ b/src/lib/memrange.c
@@ -252,6 +252,7 @@
 struct collect_context {
 	struct memranges *ranges;
 	unsigned long tag;
+	memrange_filter_t filter;
 };
 
 static void collect_ranges(void *gp, struct device *dev, struct resource *res)
@@ -261,12 +262,14 @@
 	if (res->size == 0)
 		return;
 
-	memranges_insert(ctx->ranges, res->base, res->size, ctx->tag);
+	if (ctx->filter == NULL || ctx->filter(dev, res))
+		memranges_insert(ctx->ranges, res->base, res->size, ctx->tag);
 }
 
-void memranges_add_resources(struct memranges *ranges,
-                                 unsigned long mask, unsigned long match,
-                                 unsigned long tag)
+void memranges_add_resources_filter(struct memranges *ranges,
+                                    unsigned long mask, unsigned long match,
+                                    unsigned long tag,
+                                    memrange_filter_t filter)
 {
 	struct collect_context context;
 
@@ -276,9 +279,17 @@
 
 	context.ranges = ranges;
 	context.tag = tag;
+	context.filter = filter;
 	search_global_resources(mask, match, collect_ranges, &context);
 }
 
+void memranges_add_resources(struct memranges *ranges,
+                             unsigned long mask, unsigned long match,
+                             unsigned long tag)
+{
+	memranges_add_resources_filter(ranges, mask, match, tag, NULL);
+}
+
 void memranges_init(struct memranges *ranges,
                     unsigned long mask, unsigned long match,
                     unsigned long tag)