From acfdfd647b574e4e41b68e189327c38385463c69 Mon Sep 17 00:00:00 2001 From: Jake Burkholder Date: Sat, 23 Feb 2002 03:36:04 +0000 Subject: [PATCH] Add OF_claim_virt() and OF_release_phys(). Submitted by: tmm --- sys/boot/ofw/libofw/openfirm.c | 70 ++++++++++++++++++++++++++++++++++ sys/boot/ofw/libofw/openfirm.h | 2 + 2 files changed, 72 insertions(+) diff --git a/sys/boot/ofw/libofw/openfirm.c b/sys/boot/ofw/libofw/openfirm.c index 3970d95eddd..bb2dd20d448 100644 --- a/sys/boot/ofw/libofw/openfirm.c +++ b/sys/boot/ofw/libofw/openfirm.c @@ -705,6 +705,45 @@ OF_claim(void *virt, u_int size, u_int align) return (void *)args.baseaddr; } +/* Allocate an area of physical memory */ +vm_offset_t +OF_claim_virt(vm_offset_t virt, size_t size, int align) +{ + static struct { + cell_t name; + cell_t nargs; + cell_t nret; + cell_t method; + cell_t ihandle; + cell_t align; + cell_t size; + cell_t virt; + cell_t status; + cell_t ret; + } args = { + (cell_t)"call-method", + 5, + 2, + (cell_t)"claim", + 0, + 0, + 0, + 0, + 0, /* ret */ + 0, + }; + + args.ihandle = mmu; + args.align = align; + args.size = size; + args.virt = virt; + + if (openfirmware(&args) == -1) + return (vm_offset_t)-1; + + return (vm_offset_t)args.ret; +} + /* Allocate an area of physical memory */ void * OF_alloc_phys(size_t size, int align) @@ -766,6 +805,37 @@ OF_release(void *virt, u_int size) openfirmware(&args); } +/* Release an area of physical memory. */ +void +OF_release_phys(vm_offset_t phys, u_int size) +{ + static struct { + cell_t name; + cell_t nargs; + cell_t nret; + cell_t method; + cell_t ihandle; + cell_t size; + cell_t phys_hi; + cell_t phys_lo; + } args = { + (cell_t)"call-method", + 5, + 0, + (cell_t)"release", + 0, + 0, + 0, + 0 + }; + + args.ihandle = memory; + args.phys_hi = (u_int32_t)(phys >> 32); + args.phys_lo = (u_int32_t)phys; + args.size = size; + openfirmware(&args); +} + /* * Control transfer functions. */ diff --git a/sys/boot/ofw/libofw/openfirm.h b/sys/boot/ofw/libofw/openfirm.h index 90e9d9ed408..86c39b080e4 100644 --- a/sys/boot/ofw/libofw/openfirm.h +++ b/sys/boot/ofw/libofw/openfirm.h @@ -105,8 +105,10 @@ int OF_seek(ihandle_t, u_quad_t); /* Memory functions */ void *OF_claim(void *, u_int, u_int); +vm_offset_t OF_claim_virt(vm_offset_t, size_t, int); void *OF_alloc_phys(size_t, int); void OF_release(void *, u_int); +void OF_release_phys(vm_offset_t, u_int); /* Control transfer functions */ void OF_boot(char *);