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$ 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 42 static MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 43 44 void * 45 AcpiOsAllocate(ACPI_SIZE Size) 46 { 47 return(malloc(Size, M_ACPICA, M_NOWAIT)); 48 } 49 50 void 51 AcpiOsFree (void *Memory) 52 { 53 free(Memory, M_ACPICA); 54 } 55 56 ACPI_STATUS 57 AcpiOsMapMemory (ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length, void **LogicalAddress) 58 { 59 *LogicalAddress = pmap_mapdev((vm_offset_t)PhysicalAddress, Length); 60 if (*LogicalAddress == NULL) 61 return(AE_BAD_ADDRESS); 62 return(AE_OK); 63 } 64 65 void 66 AcpiOsUnmapMemory (void *LogicalAddress, ACPI_SIZE Length) 67 { 68 pmap_unmapdev((vm_offset_t)LogicalAddress, Length); 69 } 70 71 ACPI_STATUS 72 AcpiOsGetPhysicalAddress(void *LogicalAddress, ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 73 { 74 /* we can't necessarily do this, so cop out */ 75 return(AE_BAD_ADDRESS); 76 } 77 78 /* 79 * There is no clean way to do this. We make the charitable assumption 80 * that callers will not pass garbage to us. 81 */ 82 BOOLEAN 83 AcpiOsReadable (void *Pointer, UINT32 Length) 84 { 85 return(TRUE); 86 } 87 88 BOOLEAN 89 AcpiOsWritable (void *Pointer, UINT32 Length) 90 { 91 return(TRUE); 92 } 93 94 ACPI_STATUS 95 AcpiOsReadMemory ( 96 ACPI_PHYSICAL_ADDRESS Address, 97 void *Value, 98 UINT32 Width) 99 { 100 void *LogicalAddress; 101 102 if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) { 103 return(AE_NOT_EXIST); 104 } 105 106 switch (Width) { 107 case 8: 108 *(u_int8_t *)Value = (*(volatile u_int8_t *)LogicalAddress); 109 break; 110 case 16: 111 *(u_int16_t *)Value = (*(volatile u_int16_t *)LogicalAddress); 112 break; 113 case 32: 114 *(u_int32_t *)Value = (*(volatile u_int32_t *)LogicalAddress); 115 break; 116 case 64: 117 *(u_int64_t *)Value = (*(volatile u_int64_t *)LogicalAddress); 118 break; 119 default: 120 /* debug trap goes here */ 121 break; 122 } 123 124 AcpiOsUnmapMemory(LogicalAddress, Width / 8); 125 126 return(AE_OK); 127 } 128 129 ACPI_STATUS 130 AcpiOsWriteMemory ( 131 ACPI_PHYSICAL_ADDRESS Address, 132 ACPI_INTEGER Value, 133 UINT32 Width) 134 { 135 void *LogicalAddress; 136 137 if (AcpiOsMapMemory(Address, Width / 8, &LogicalAddress) != AE_OK) { 138 return(AE_NOT_EXIST); 139 } 140 141 switch (Width) { 142 case 8: 143 (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 144 break; 145 case 16: 146 (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 147 break; 148 case 32: 149 (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 150 break; 151 case 64: 152 (*(volatile u_int64_t *)LogicalAddress) = Value; 153 break; 154 default: 155 /* debug trap goes here */ 156 break; 157 } 158 159 AcpiOsUnmapMemory(LogicalAddress, Width / 8); 160 161 return(AE_OK); 162 } 163