OsdMemory.c revision 128225
1/*- 2 * Copyright (c) 2000 Mitsaru Iwasaki 3 * Copyright (c) 2000 Michael Smith 4 * Copyright (c) 2000 BSDi 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD: head/sys/dev/acpica/Osd/OsdMemory.c 128225 2004-04-14 03:39:08Z njl $ 29 */ 30 31/* 32 * 6.2 : Memory Management 33 */ 34 35#include "acpi.h" 36 37#include <sys/kernel.h> 38#include <sys/malloc.h> 39#include <vm/vm.h> 40#include <vm/pmap.h> 41 42MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 43 44void * 45AcpiOsAllocate(ACPI_SIZE Size) 46{ 47 return (malloc(Size, M_ACPICA, M_NOWAIT)); 48} 49 50void 51AcpiOsFree(void *Memory) 52{ 53 free(Memory, M_ACPICA); 54} 55 56ACPI_STATUS 57AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length, 58 void **LogicalAddress) 59{ 60 *LogicalAddress = pmap_mapdev((vm_offset_t)PhysicalAddress, Length); 61 if (*LogicalAddress == NULL) 62 return (AE_BAD_ADDRESS); 63 return (AE_OK); 64} 65 66void 67AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) 68{ 69 pmap_unmapdev((vm_offset_t)LogicalAddress, Length); 70} 71 72ACPI_STATUS 73AcpiOsGetPhysicalAddress(void *LogicalAddress, 74 ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 75{ 76 /* We can't necessarily do this, so cop out. */ 77 return (AE_BAD_ADDRESS); 78} 79 80/* 81 * There is no clean way to do this. We make the charitable assumption 82 * that callers will not pass garbage to us. 83 */ 84BOOLEAN 85AcpiOsReadable (void *Pointer, ACPI_SIZE Length) 86{ 87 return (TRUE); 88} 89 90BOOLEAN 91AcpiOsWritable (void *Pointer, ACPI_SIZE Length) 92{ 93 return (TRUE); 94} 95 96ACPI_STATUS 97AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width) 98{ 99 void *LogicalAddress; 100 101 if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) 102 return (AE_NOT_EXIST); 103 104 switch (Width) { 105 case 8: 106 *(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress); 107 break; 108 case 16: 109 *(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress); 110 break; 111 case 32: 112 *(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress); 113 break; 114 case 64: 115 *(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress); 116 break; 117 default: 118 /* debug trap goes here */ 119 break; 120 } 121 122 AcpiOsUnmapMemory(LogicalAddress, Width / 8); 123 124 return (AE_OK); 125} 126 127ACPI_STATUS 128AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width) 129{ 130 void *LogicalAddress; 131 132 if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) 133 return (AE_NOT_EXIST); 134 135 switch (Width) { 136 case 8: 137 (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 138 break; 139 case 16: 140 (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 141 break; 142 case 32: 143 (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 144 break; 145 case 64: 146 (*(volatile u_int64_t *)LogicalAddress) = Value; 147 break; 148 default: 149 /* debug trap goes here */ 150 break; 151 } 152 153 AcpiOsUnmapMemory(LogicalAddress, Width / 8); 154 155 return (AE_OK); 156} 157