OsdMemory.c revision 92118
167760Smsmith/*- 269459Smsmith * Copyright (c) 2000 Mitsaru Iwasaki 367760Smsmith * Copyright (c) 2000 Michael Smith 467760Smsmith * Copyright (c) 2000 BSDi 567760Smsmith * All rights reserved. 667760Smsmith * 767760Smsmith * Redistribution and use in source and binary forms, with or without 867760Smsmith * modification, are permitted provided that the following conditions 967760Smsmith * are met: 1067760Smsmith * 1. Redistributions of source code must retain the above copyright 1167760Smsmith * notice, this list of conditions and the following disclaimer. 1267760Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1367760Smsmith * notice, this list of conditions and the following disclaimer in the 1467760Smsmith * documentation and/or other materials provided with the distribution. 1567760Smsmith * 1667760Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1767760Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1867760Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1967760Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2067760Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2167760Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2267760Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2367760Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2467760Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2567760Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2667760Smsmith * SUCH DAMAGE. 2767760Smsmith * 2867760Smsmith * $FreeBSD: head/sys/dev/acpica/Osd/OsdMemory.c 92118 2002-03-12 00:10:40Z peter $ 2967760Smsmith */ 3067760Smsmith 3167760Smsmith/* 3267760Smsmith * 6.2 : Memory Management 3367760Smsmith */ 3467760Smsmith 3567760Smsmith#include "acpi.h" 3667760Smsmith 3767760Smsmith#include <sys/kernel.h> 3867760Smsmith#include <sys/malloc.h> 3967760Smsmith#include <vm/vm.h> 4067760Smsmith#include <vm/pmap.h> 4167760Smsmith 4269776Smsmithstatic MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 4367760Smsmith 4467760Smsmithvoid * 4592118SpeterAcpiOsAllocate(ACPI_SIZE Size) 4667760Smsmith{ 4767760Smsmith return(malloc(Size, M_ACPICA, M_NOWAIT)); 4867760Smsmith} 4967760Smsmith 5067760Smsmithvoid 5167760SmsmithAcpiOsFree (void *Memory) 5267760Smsmith{ 5367760Smsmith free(Memory, M_ACPICA); 5467760Smsmith} 5567760Smsmith 5667760SmsmithACPI_STATUS 5792118SpeterAcpiOsMapMemory (ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length, void **LogicalAddress) 5867760Smsmith{ 5967760Smsmith *LogicalAddress = pmap_mapdev((vm_offset_t)PhysicalAddress, Length); 6067760Smsmith if (*LogicalAddress == NULL) 6167760Smsmith return(AE_BAD_ADDRESS); 6267760Smsmith return(AE_OK); 6367760Smsmith} 6467760Smsmith 6567760Smsmithvoid 6692118SpeterAcpiOsUnmapMemory (void *LogicalAddress, ACPI_SIZE Length) 6767760Smsmith{ 6867760Smsmith pmap_unmapdev((vm_offset_t)LogicalAddress, Length); 6967760Smsmith} 7067760Smsmith 7180071SmsmithACPI_STATUS 7280071SmsmithAcpiOsGetPhysicalAddress(void *LogicalAddress, ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 7380071Smsmith{ 7480071Smsmith /* we can't necessarily do this, so cop out */ 7580071Smsmith return(AE_BAD_ADDRESS); 7680071Smsmith} 7780071Smsmith 7867760Smsmith/* 7967760Smsmith * There is no clean way to do this. We make the charitable assumption 8067760Smsmith * that callers will not pass garbage to us. 8167760Smsmith */ 8267760SmsmithBOOLEAN 8367760SmsmithAcpiOsReadable (void *Pointer, UINT32 Length) 8467760Smsmith{ 8567760Smsmith return(TRUE); 8667760Smsmith} 8767760Smsmith 8867760SmsmithBOOLEAN 8967760SmsmithAcpiOsWritable (void *Pointer, UINT32 Length) 9067760Smsmith{ 9167760Smsmith return(TRUE); 9267760Smsmith} 9367760Smsmith 9480071SmsmithACPI_STATUS 9580071SmsmithAcpiOsReadMemory ( 9680071Smsmith ACPI_PHYSICAL_ADDRESS Address, 9780071Smsmith void *Value, 9880071Smsmith UINT32 Width) 9969459Smsmith{ 10069459Smsmith void *LogicalAddress; 10169459Smsmith 10280071Smsmith if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) { 10380071Smsmith return(AE_NOT_EXIST); 10469459Smsmith } 10569459Smsmith 10680071Smsmith switch (Width) { 10780071Smsmith case 8: 10880071Smsmith *(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress); 10969459Smsmith break; 11080071Smsmith case 16: 11180071Smsmith *(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress); 11269459Smsmith break; 11380071Smsmith case 32: 11480071Smsmith *(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress); 11569459Smsmith break; 11680071Smsmith case 64: 11780071Smsmith *(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress); 11880071Smsmith break; 11980071Smsmith default: 12080071Smsmith /* debug trap goes here */ 12169459Smsmith } 12269459Smsmith 12380071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 12469459Smsmith 12580071Smsmith return(AE_OK); 12669459Smsmith} 12769459Smsmith 12880071SmsmithACPI_STATUS 12980071SmsmithAcpiOsWriteMemory ( 13080071Smsmith ACPI_PHYSICAL_ADDRESS Address, 13187036Smsmith ACPI_INTEGER Value, 13280071Smsmith UINT32 Width) 13369459Smsmith{ 13469459Smsmith void *LogicalAddress; 13569459Smsmith 13680071Smsmith if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) { 13780071Smsmith return(AE_NOT_EXIST); 13869459Smsmith } 13969459Smsmith 14080071Smsmith switch (Width) { 14180071Smsmith case 8: 14269459Smsmith (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 14369459Smsmith break; 14480071Smsmith case 16: 14569459Smsmith (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 14669459Smsmith break; 14780071Smsmith case 32: 14880071Smsmith (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 14969459Smsmith break; 15080071Smsmith case 64: 15180071Smsmith (*(volatile u_int64_t *)LogicalAddress) = Value; 15280071Smsmith break; 15380071Smsmith default: 15480071Smsmith /* debug trap goes here */ 15569459Smsmith } 15669459Smsmith 15780071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 15869459Smsmith 15980071Smsmith return(AE_OK); 16069459Smsmith} 161