/*
* Copyright (C) 2001-2003 Hewlett-Packard Co.
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
+ * Contributed by Fenghua Yu <Fenghua.Yu@intel.com>
+ * Contributed by Bibo Mao <bibo.mao@intel.com>
+ * Contributed by Chandramouli Narayanan <mouli@linux.intel.com>
*
* This file is part of the ELILO, the EFI Linux boot loader.
*
if (type == 0) type = EfiLoaderData;
- status = BS->AllocatePool (type, size, &tmp);
+ status = uefi_call_wrapper(BS->AllocatePool, 3, type, size, &tmp);
if (EFI_ERROR(status)) {
- ERR_PRT((L"allocator: AllocatePool(%d, %d, 0x%x) failed (%r)\n", type, size, status));
+ ERR_PRT((L"allocator: AllocatePool(%d, %d) failed (%r)\n", type, size, status));
return NULL;
}
alloc_add(tmp, size, ALLOC_POOL);
-
- DBG_PRT((L"alloc: allocated %d bytes @[0x%lx-0x%lx]\n", size, tmp, tmp+size));
-
+#ifdef DEBUG_MEM
+ DBG_PRT((L"alloc: allocated %d bytes @[" PTR_FMT "-" PTR_FMT "]\n", size, tmp, tmp+size));
+#endif
return tmp;
}
return NULL;
}
- status = BS->AllocatePages(where, type , pgcnt, &tmp);
+ status = uefi_call_wrapper(BS->AllocatePages, 4, where, type , pgcnt, &tmp);
if (EFI_ERROR(status)) {
- ERR_PRT((L"allocator: AllocatePages(%d, %d, %d, 0x%lx) failed (%r)\n", where, type, pgcnt, tmp, status));
+ VERB_PRT(1, Print(L"allocator: AllocatePages(%d, %d, %d, 0x%lx) failed (%r)\n", where, type, pgcnt, tmp, status));
return NULL;
}
/* XXX: will cause warning on IA-32 */
if (p->addr == addr) goto found;
}
/* not found */
- ERR_PRT((L"allocator: invalid free @ 0x%lx\n", addr));
+ VERB_PRT(1, Print(L"allocator: invalid free @ " PTR_FMT "\n", addr));
return;
found:
- DBG_PRT((L"free: %s @0x%lx size=%ld\n",
+#ifdef DEBUG_MEM
+ DBG_PRT((L"free: %s @" PTR_FMT " size=%d\n",
p->type == ALLOC_POOL ? L"Pool": L"Page",
addr, p->size));
-
+#endif
if (p->type == ALLOC_POOL)
- BS->FreePool(addr);
+ uefi_call_wrapper(BS->FreePool, 1, addr);
else
- BS->FreePages((EFI_PHYSICAL_ADDRESS)addr, p->size);
+ uefi_call_wrapper(BS->FreePages, 2, (EFI_PHYSICAL_ADDRESS)addr, p->size);
/* remove from used list */
if (p->next)
alloc_entry_t *tmp;
while(used_allocs) {
-
- DBG_PRT((L"free_all %a @ 0x%lx\n", used_allocs->type == ALLOC_POOL ? "pool" : "pages", used_allocs->addr));
-
+#ifdef DEBUG_MEM
+ DBG_PRT((L"free_all %a @ " PTR_FMT "\n", used_allocs->type == ALLOC_POOL ? "pool" : "pages", used_allocs->addr));
+#endif
if (used_allocs->type == ALLOC_POOL)
- BS->FreePool(used_allocs->addr);
+ uefi_call_wrapper(BS->FreePool, 1, used_allocs->addr);
else
- BS->FreePages((EFI_PHYSICAL_ADDRESS)used_allocs->addr, used_allocs->size);
+ uefi_call_wrapper(BS->FreePages, 2, (EFI_PHYSICAL_ADDRESS)used_allocs->addr, used_allocs->size);
tmp = used_allocs->next;
}
}
+INTN
+alloc_kmem_anywhere(VOID **start_addr, UINTN pgcnt)
+{
+ void * tmp;
+ if ((tmp = alloc_pages(pgcnt, EfiLoaderData, AllocateAnyPages, *start_addr)) == 0) return -1;
+
+ kmem_addr = tmp;
+ kmem_pgcnt = pgcnt;
+ *start_addr = tmp;
+
+ return 0;
+}
+
INTN
alloc_kmem(VOID *start_addr, UINTN pgcnt)
{
VOID
free_kmem(VOID)
{
- DBG_PRT((L"free_kmem before (%lx, %ld)\n", kmem_addr, kmem_pgcnt));
+#ifdef DEBUG_MEM
+ DBG_PRT((L"free_kmem before (" PTR_FMT ", %d)\n", kmem_addr, kmem_pgcnt));
+#endif
if (kmem_addr && kmem_pgcnt != 0) {
free(kmem_addr);
kmem_addr = NULL;
kmem_pgcnt = 0;
}
- DBG_PRT((L"free_kmem after (%lx, %ld)\n", kmem_addr, kmem_pgcnt));
+#ifdef DEBUG_MEM
+ DBG_PRT((L"free_kmem after (" PTR_FMT ", %d)\n", kmem_addr, kmem_pgcnt));
+#endif
}
VOID