OsdMemory.c revision 148318
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 148318 2005-07-22 23:10:02Z njl $"); 35148318Snjl 3667760Smsmith#include "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 5767760SmsmithACPI_STATUS 58128225SnjlAcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length, 59128225Snjl void **LogicalAddress) 6067760Smsmith{ 6167760Smsmith *LogicalAddress = pmap_mapdev((vm_offset_t)PhysicalAddress, Length); 6267760Smsmith if (*LogicalAddress == NULL) 63128225Snjl return (AE_BAD_ADDRESS); 64128225Snjl return (AE_OK); 6567760Smsmith} 6667760Smsmith 6767760Smsmithvoid 68128225SnjlAcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) 6967760Smsmith{ 7067760Smsmith pmap_unmapdev((vm_offset_t)LogicalAddress, Length); 7167760Smsmith} 7267760Smsmith 7380071SmsmithACPI_STATUS 74128225SnjlAcpiOsGetPhysicalAddress(void *LogicalAddress, 75128225Snjl ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 7680071Smsmith{ 77128225Snjl /* We can't necessarily do this, so cop out. */ 78128225Snjl return (AE_BAD_ADDRESS); 7980071Smsmith} 8080071Smsmith 8167760Smsmith/* 8267760Smsmith * There is no clean way to do this. We make the charitable assumption 8367760Smsmith * that callers will not pass garbage to us. 8467760Smsmith */ 8567760SmsmithBOOLEAN 86117534SmarcelAcpiOsReadable (void *Pointer, ACPI_SIZE Length) 8767760Smsmith{ 88128225Snjl return (TRUE); 8967760Smsmith} 9067760Smsmith 9167760SmsmithBOOLEAN 92117534SmarcelAcpiOsWritable (void *Pointer, ACPI_SIZE Length) 9367760Smsmith{ 94128225Snjl return (TRUE); 9567760Smsmith} 9667760Smsmith 9780071SmsmithACPI_STATUS 98128225SnjlAcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width) 9969459Smsmith{ 10069459Smsmith void *LogicalAddress; 10169459Smsmith 102128225Snjl if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) 103128225Snjl return (AE_NOT_EXIST); 10469459Smsmith 10580071Smsmith switch (Width) { 10680071Smsmith case 8: 10780071Smsmith *(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress); 10869459Smsmith break; 10980071Smsmith case 16: 11080071Smsmith *(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress); 11169459Smsmith break; 11280071Smsmith case 32: 11380071Smsmith *(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress); 11469459Smsmith break; 11580071Smsmith case 64: 11680071Smsmith *(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress); 11780071Smsmith break; 11880071Smsmith default: 11980071Smsmith /* debug trap goes here */ 12092666Speter break; 12169459Smsmith } 12269459Smsmith 12380071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 12469459Smsmith 125128225Snjl return (AE_OK); 12669459Smsmith} 12769459Smsmith 12880071SmsmithACPI_STATUS 129128225SnjlAcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width) 13069459Smsmith{ 13169459Smsmith void *LogicalAddress; 13269459Smsmith 133128225Snjl if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) 134128225Snjl return (AE_NOT_EXIST); 13569459Smsmith 13680071Smsmith switch (Width) { 13780071Smsmith case 8: 13869459Smsmith (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 13969459Smsmith break; 14080071Smsmith case 16: 14169459Smsmith (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 14269459Smsmith break; 14380071Smsmith case 32: 14480071Smsmith (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 14569459Smsmith break; 14680071Smsmith case 64: 14780071Smsmith (*(volatile u_int64_t *)LogicalAddress) = Value; 14880071Smsmith break; 14980071Smsmith default: 15080071Smsmith /* debug trap goes here */ 15192666Speter break; 15269459Smsmith } 15369459Smsmith 15480071Smsmith AcpiOsUnmapMemory(LogicalAddress, Width / 8); 15569459Smsmith 156128225Snjl return (AE_OK); 15769459Smsmith} 158