X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=alloc.c;h=cd67c38e239f005091946fcd2aab72b3cad4895c;hb=10cd7a3ea637ebb98f4aea0e8142fed4505f6223;hp=349da9f24e6dbc85101f99fcc3645ff8077f1c51;hpb=2344eb51e123a29ed29ed03e6b4d56190d8d7c43;p=debian%2Felilo diff --git a/alloc.c b/alloc.c index 349da9f..cd67c38 100644 --- a/alloc.c +++ b/alloc.c @@ -1,6 +1,9 @@ /* * Copyright (C) 2001-2003 Hewlett-Packard Co. * Contributed by Stephane Eranian + * Contributed by Fenghua Yu + * Contributed by Bibo Mao + * Contributed by Chandramouli Narayanan * * This file is part of the ELILO, the EFI Linux boot loader. * @@ -100,15 +103,15 @@ alloc(UINTN size, EFI_MEMORY_TYPE type) 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 "]", size, tmp, tmp+size)); +#endif return tmp; } @@ -127,9 +130,9 @@ alloc_pages(UINTN pgcnt, EFI_MEMORY_TYPE type, EFI_ALLOCATE_TYPE where, VOID *ad return NULL; } - status = BS->AllocatePages(where, type , pgcnt, &tmp); + status = uefi_call_wrapper(BS->AllocatePages, 4, where, type , pgcnt, &tmp); if (EFI_ERROR(status)) { - VERB_PRT(1, (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 */ @@ -137,7 +140,7 @@ alloc_pages(UINTN pgcnt, EFI_MEMORY_TYPE type, EFI_ALLOCATE_TYPE where, VOID *ad alloc_add(addr, pgcnt, ALLOC_PAGES); - DBG_PRT((L"allocator: allocated %d pages @0x%lx\n", pgcnt, tmp)); + DBG_PRT((L"allocator: allocated %d pages @" PTR_FMT, pgcnt, tmp)); return addr; } @@ -155,17 +158,18 @@ free(VOID *addr) if (p->addr == addr) goto found; } /* not found */ - VERB_PRT(1, (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", 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) @@ -191,13 +195,13 @@ free_all(VOID) 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, 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; @@ -209,6 +213,27 @@ free_all(VOID) } } +INTN +alloc_kmem_anywhere(VOID **start_addr, UINTN pgcnt) +{ + void * tmp; + /* + * During "AllocateAnyPages" *start_addr will be ignored. + * Therefore we can safely subvert it to reuse this function with + * an alloc_kmem_anyhwere_below() semantic... + */ + tmp = alloc_pages(pgcnt, EfiLoaderData, + (*start_addr) ? AllocateMaxAddress : AllocateAnyPages, + *start_addr); + if (tmp == NULL) return -1; + + kmem_addr = tmp; + kmem_pgcnt = pgcnt; + *start_addr = tmp; + + return 0; +} + INTN alloc_kmem(VOID *start_addr, UINTN pgcnt) { @@ -223,13 +248,17 @@ 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)", 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)", kmem_addr, kmem_pgcnt)); +#endif } VOID