OsdMemory.c revision 167814
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 2967760Smsmith/* 3067760Smsmith * 6.2 : Memory Management 3167760Smsmith */ 3267760Smsmith 33148318Snjl#include <sys/cdefs.h> 34148318Snjl__FBSDID("$FreeBSD: head/sys/dev/acpica/Osd/OsdMemory.c 167814 2007-03-22 18:16:43Z jkim $"); 35148318Snjl 36150003Sobrien#include <contrib/dev/acpica/acpi.h> 3767760Smsmith 3867760Smsmith#include <sys/kernel.h> 3967760Smsmith#include <sys/malloc.h> 4067760Smsmith#include <vm/vm.h> 4167760Smsmith#include <vm/pmap.h> 4267760Smsmith 43128225SnjlMALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 4467760Smsmith 4567760Smsmithvoid * 4692118SpeterAcpiOsAllocate(ACPI_SIZE Size) 4767760Smsmith{ 48128225Snjl return (malloc(Size, M_ACPICA, M_NOWAIT)); 4967760Smsmith} 5067760Smsmith 5167760Smsmithvoid 52128225SnjlAcpiOsFree(void *Memory) 5367760Smsmith{ 5467760Smsmith free(Memory, M_ACPICA); 5567760Smsmith} 5667760Smsmith 57167814Sjkimvoid * 58167814SjkimAcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_NATIVE_UINT Length) 5967760Smsmith{ 60167814Sjkim return (pmap_mapbios((vm_offset_t)PhysicalAddress, Length)); 6167760Smsmith} 6267760Smsmith 6367760Smsmithvoid 64128225SnjlAcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) 6567760Smsmith{ 66161223Sjhb pmap_unmapbios((vm_offset_t)LogicalAddress, Length); 6767760Smsmith} 6867760Smsmith 6980071SmsmithACPI_STATUS 70128225SnjlAcpiOsGetPhysicalAddress(void *LogicalAddress, 71128225Snjl ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 7280071Smsmith{ 73128225Snjl /* We can't necessarily do this, so cop out. */ 74128225Snjl return (AE_BAD_ADDRESS); 7580071Smsmith} 7680071Smsmith 77167814SjkimACPI_STATUS 78167814SjkimAcpiOsValidateInterface (char *Interface) 79167814Sjkim{ 80167814Sjkim return (AE_SUPPORT); 81167814Sjkim} 82167814Sjkim 8367760Smsmith/* 8467760Smsmith * There is no clean way to do this. We make the charitable assumption 8567760Smsmith * that callers will not pass garbage to us. 8667760Smsmith */ 87167814SjkimACPI_STATUS 88167814SjkimAcpiOsValidateAddress (UINT8 SpaceId, ACPI_PHYSICAL_ADDRESS Address, 89167814Sjkim ACPI_SIZE Length) 90167814Sjkim{ 91167814Sjkim return (AE_OK); 92167814Sjkim} 93167814Sjkim 9467760SmsmithBOOLEAN 95117534SmarcelAcpiOsReadable (void *Pointer, ACPI_SIZE Length) 9667760Smsmith{ 97128225Snjl return (TRUE); 9867760Smsmith} 9967760Smsmith 10067760SmsmithBOOLEAN 101117534SmarcelAcpiOsWritable (void *Pointer, ACPI_SIZE Length) 10267760Smsmith{ 103128225Snjl return (TRUE); 10467760Smsmith} 10567760Smsmith 10680071SmsmithACPI_STATUS 107128225SnjlAcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width) 10869459Smsmith{ 10969459Smsmith void *LogicalAddress; 11069459Smsmith 111167814Sjkim LogicalAddress = AcpiOsMapMemory(Address, Width / 8); 112167814Sjkim if (LogicalAddress == NULL) 113128225Snjl return (AE_NOT_EXIST); 11469459Smsmith 11580071Smsmith switch (Width) { 11680071Smsmith case 8: 11780071Smsmith *(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress); 11869459Smsmith break; 11980071Smsmith case 16: 12080071Smsmith *(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress); 12169459Smsmith break; 12280071Smsmith case 32: 12380071Smsmith *(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress); 12469459Smsmith break; 12580071Smsmith case 64: 12680071Smsmith *(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress); 12780071Smsmith break; 12880071Smsmith default: 12980071Smsmith /* debug trap goes here */ 13092666Speter break; 13169459Smsmith } 13269459Smsmith 13380071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 13469459Smsmith 135128225Snjl return (AE_OK); 13669459Smsmith} 13769459Smsmith 13880071SmsmithACPI_STATUS 139128225SnjlAcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width) 14069459Smsmith{ 14169459Smsmith void *LogicalAddress; 14269459Smsmith 143167814Sjkim LogicalAddress = AcpiOsMapMemory(Address, Width / 8); 144167814Sjkim if (LogicalAddress == NULL) 145128225Snjl return (AE_NOT_EXIST); 14669459Smsmith 14780071Smsmith switch (Width) { 14880071Smsmith case 8: 14969459Smsmith (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 15069459Smsmith break; 15180071Smsmith case 16: 15269459Smsmith (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 15369459Smsmith break; 15480071Smsmith case 32: 15580071Smsmith (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 15669459Smsmith break; 15780071Smsmith case 64: 15880071Smsmith (*(volatile u_int64_t *)LogicalAddress) = Value; 15980071Smsmith break; 16080071Smsmith default: 16180071Smsmith /* debug trap goes here */ 16292666Speter break; 16369459Smsmith } 16469459Smsmith 16580071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 16669459Smsmith 167128225Snjl return (AE_OK); 16869459Smsmith} 169