OsdMemory.c revision 69459
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 69459 2000-12-01 10:19:28Z msmith $ 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 4267760SmsmithMALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 4367760Smsmith 4467760Smsmithvoid * 4567760SmsmithAcpiOsAllocate(UINT32 Size) 4667760Smsmith{ 4767760Smsmith return(malloc(Size, M_ACPICA, M_NOWAIT)); 4867760Smsmith} 4967760Smsmith 5067760Smsmithvoid * 5167760SmsmithAcpiOsCallocate (UINT32 Size) 5267760Smsmith{ 5367760Smsmith void *alloc; 5467760Smsmith 5567760Smsmith alloc = malloc(Size, M_ACPICA, M_NOWAIT); 5667760Smsmith if (alloc != NULL) 5767760Smsmith bzero(alloc, Size); 5867760Smsmith return(alloc); 5967760Smsmith} 6067760Smsmith 6167760Smsmithvoid 6267760SmsmithAcpiOsFree (void *Memory) 6367760Smsmith{ 6467760Smsmith free(Memory, M_ACPICA); 6567760Smsmith} 6667760Smsmith 6767760SmsmithACPI_STATUS 6869459SmsmithAcpiOsMapMemory (ACPI_PHYSICAL_ADDRESS PhysicalAddress, UINT32 Length, void **LogicalAddress) 6967760Smsmith{ 7067760Smsmith *LogicalAddress = pmap_mapdev((vm_offset_t)PhysicalAddress, Length); 7167760Smsmith if (*LogicalAddress == NULL) 7267760Smsmith return(AE_BAD_ADDRESS); 7367760Smsmith return(AE_OK); 7467760Smsmith} 7567760Smsmith 7667760Smsmithvoid 7767760SmsmithAcpiOsUnmapMemory (void *LogicalAddress, UINT32 Length) 7867760Smsmith{ 7967760Smsmith pmap_unmapdev((vm_offset_t)LogicalAddress, Length); 8067760Smsmith} 8167760Smsmith 8267760Smsmith/* 8367760Smsmith * There is no clean way to do this. We make the charitable assumption 8467760Smsmith * that callers will not pass garbage to us. 8567760Smsmith */ 8667760SmsmithBOOLEAN 8767760SmsmithAcpiOsReadable (void *Pointer, UINT32 Length) 8867760Smsmith{ 8967760Smsmith return(TRUE); 9067760Smsmith} 9167760Smsmith 9267760SmsmithBOOLEAN 9367760SmsmithAcpiOsWritable (void *Pointer, UINT32 Length) 9467760Smsmith{ 9567760Smsmith return(TRUE); 9667760Smsmith} 9767760Smsmith 9869459Smsmithstatic __inline 9969459SmsmithUINT32 10069459SmsmithAcpiOsMemInX (UINT32 Length, ACPI_PHYSICAL_ADDRESS InAddr) 10169459Smsmith{ 10269459Smsmith UINT32 Value; 10369459Smsmith void *LogicalAddress; 10469459Smsmith 10569459Smsmith if (AcpiOsMapMemory(InAddr, Length, &LogicalAddress) != AE_OK) { 10669459Smsmith return(0); 10769459Smsmith } 10869459Smsmith 10969459Smsmith switch (Length) { 11069459Smsmith case 1: 11169459Smsmith Value = (*(volatile u_int8_t *)LogicalAddress) & 0xff; 11269459Smsmith break; 11369459Smsmith case 2: 11469459Smsmith Value = (*(volatile u_int16_t *)LogicalAddress) & 0xffff; 11569459Smsmith break; 11669459Smsmith case 4: 11769459Smsmith Value = (*(volatile u_int32_t *)LogicalAddress); 11869459Smsmith break; 11969459Smsmith } 12069459Smsmith 12169459Smsmith AcpiOsUnmapMemory(LogicalAddress, Length); 12269459Smsmith 12369459Smsmith return(Value); 12469459Smsmith} 12569459Smsmith 12669459SmsmithUINT8 12769459SmsmithAcpiOsMemIn8 (ACPI_PHYSICAL_ADDRESS InAddr) 12869459Smsmith{ 12969459Smsmith return((UINT8)AcpiOsMemInX(1, InAddr)); 13069459Smsmith} 13169459Smsmith 13269459SmsmithUINT16 13369459SmsmithAcpiOsMemIn16 (ACPI_PHYSICAL_ADDRESS InAddr) 13469459Smsmith{ 13569459Smsmith return((UINT16)AcpiOsMemInX(2, InAddr)); 13669459Smsmith} 13769459Smsmith 13869459SmsmithUINT32 13969459SmsmithAcpiOsMemIn32 (ACPI_PHYSICAL_ADDRESS InAddr) 14069459Smsmith{ 14169459Smsmith return((UINT32)AcpiOsMemInX(4, InAddr)); 14269459Smsmith} 14369459Smsmith 14469459Smsmithstatic __inline 14569459Smsmithvoid 14669459SmsmithAcpiOsMemOutX (UINT32 Length, ACPI_PHYSICAL_ADDRESS OutAddr, UINT32 Value) 14769459Smsmith{ 14869459Smsmith void *LogicalAddress; 14969459Smsmith 15069459Smsmith if (AcpiOsMapMemory(OutAddr, Length, &LogicalAddress) != AE_OK) { 15169459Smsmith return; 15269459Smsmith } 15369459Smsmith 15469459Smsmith switch (Length) { 15569459Smsmith case 1: 15669459Smsmith (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 15769459Smsmith break; 15869459Smsmith case 2: 15969459Smsmith (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 16069459Smsmith break; 16169459Smsmith case 4: 16269459Smsmith (*(volatile u_int32_t *)LogicalAddress) = Value; 16369459Smsmith break; 16469459Smsmith } 16569459Smsmith 16669459Smsmith AcpiOsUnmapMemory(LogicalAddress, Length); 16769459Smsmith} 16869459Smsmith 16969459Smsmithvoid 17069459SmsmithAcpiOsMemOut8 (ACPI_PHYSICAL_ADDRESS OutAddr, UINT8 Value) 17169459Smsmith{ 17269459Smsmith AcpiOsMemOutX(1, OutAddr, (UINT32)Value); 17369459Smsmith} 17469459Smsmith 17569459Smsmithvoid 17669459SmsmithAcpiOsMemOut16 (ACPI_PHYSICAL_ADDRESS OutAddr, UINT16 Value) 17769459Smsmith{ 17869459Smsmith AcpiOsMemOutX(2, OutAddr, (UINT32)Value); 17969459Smsmith} 18069459Smsmith 18169459Smsmithvoid 18269459SmsmithAcpiOsMemOut32 (ACPI_PHYSICAL_ADDRESS OutAddr, UINT32 Value) 18369459Smsmith{ 18469459Smsmith AcpiOsMemOutX(4, OutAddr, (UINT32)Value); 18569459Smsmith} 18669459Smsmith 187