diff mbox

[v2,2/5] pmm: add a way to test whether memory is in FSEG

Message ID 1373211589-8097-3-git-send-email-mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin July 7, 2013, 3:42 p.m. UTC
Will be handy for looking for RSDP.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 src/pmm.c  | 24 ++++++++++++++++++------
 src/util.h |  1 +
 2 files changed, 19 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/src/pmm.c b/src/pmm.c
index 8f993fd..8bd8983 100644
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -120,15 +120,23 @@  addSpace(struct zone_s *zone, void *start, void *end)
 
 // Search all zones for an allocation obtained from allocSpace()
 static struct allocinfo_s *
+findAllocInZone(struct zone_s *zone, void *data)
+{
+    struct allocinfo_s *info;
+    hlist_for_each_entry(info, &zone->head, node)
+        if (info->data == data)
+            return info;
+    return NULL;
+}
+
+static struct allocinfo_s *
 findAlloc(void *data)
 {
     int i;
-    for (i=0; i<ARRAY_SIZE(Zones); i++) {
-        struct allocinfo_s *info;
-        hlist_for_each_entry(info, &Zones[i]->head, node) {
-            if (info->data == data)
-                return info;
-        }
+    for (i = 0; i < ARRAY_SIZE(Zones); i++) {
+        struct allocinfo_s *info = findAllocInZone(Zones[i], data);
+        if (info)
+            return info;
     }
     return NULL;
 }
@@ -241,6 +249,10 @@  pmm_find(u32 handle)
     return NULL;
 }
 
+int pmm_test_fseg(void *data)
+{
+    return !!findAllocInZone(&ZoneFSeg, data);
+}
 
 /****************************************************************
  * 0xc0000-0xf0000 management
diff --git a/src/util.h b/src/util.h
index 7b50c38..44e1c1a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -378,6 +378,7 @@  void malloc_init(void);
 void malloc_prepboot(void);
 void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
 int pmm_free(void *data);
+int pmm_test_fseg(void *data);
 void pmm_init(void);
 void pmm_prepboot(void);
 #define PMM_DEFAULT_HANDLE 0xFFFFFFFF