OsdMemory.c revision 193530
1272343Sngie/*- 2272343Sngie * Copyright (c) 2000 Mitsaru Iwasaki 3272343Sngie * Copyright (c) 2000 Michael Smith 4272343Sngie * Copyright (c) 2000 BSDi 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * Redistribution and use in source and binary forms, with or without 8272343Sngie * modification, are permitted provided that the following conditions 9272343Sngie * are met: 10272343Sngie * 1. Redistributions of source code must retain the above copyright 11272343Sngie * notice, this list of conditions and the following disclaimer. 12272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 13272343Sngie * notice, this list of conditions and the following disclaimer in the 14272343Sngie * documentation and/or other materials provided with the distribution. 15272343Sngie * 16272343Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17272343Sngie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18272343Sngie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19272343Sngie * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20272343Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22272343Sngie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23272343Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24272343Sngie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25272343Sngie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26272343Sngie * SUCH DAMAGE. 27272343Sngie */ 28272343Sngie 29272343Sngie/* 30272343Sngie * 6.2 : Memory Management 31272343Sngie */ 32272343Sngie 33272343Sngie#include <sys/cdefs.h> 34272343Sngie__FBSDID("$FreeBSD: head/sys/dev/acpica/Osd/OsdMemory.c 193530 2009-06-05 18:44:36Z jkim $"); 35272343Sngie 36272343Sngie#include <contrib/dev/acpica/include/acpi.h> 37272343Sngie 38272343Sngie#include <sys/kernel.h> 39272343Sngie#include <sys/malloc.h> 40272343Sngie#include <vm/vm.h> 41272343Sngie#include <vm/pmap.h> 42272343Sngie 43272343SngieMALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool"); 44272343Sngie 45272343Sngievoid * 46272343SngieAcpiOsAllocate(ACPI_SIZE Size) 47272343Sngie{ 48272343Sngie return (malloc(Size, M_ACPICA, M_NOWAIT)); 49272343Sngie} 50272343Sngie 51272343Sngievoid 52272343SngieAcpiOsFree(void *Memory) 53272343Sngie{ 54272343Sngie free(Memory, M_ACPICA); 55272343Sngie} 56272343Sngie 57272343Sngievoid * 58272343SngieAcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length) 59272343Sngie{ 60272343Sngie return (pmap_mapbios((vm_offset_t)PhysicalAddress, Length)); 61272343Sngie} 62272343Sngie 63272343Sngievoid 64272343SngieAcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) 65272343Sngie{ 66272343Sngie pmap_unmapbios((vm_offset_t)LogicalAddress, Length); 67272343Sngie} 68272343Sngie 69272343SngieACPI_STATUS 70272343SngieAcpiOsGetPhysicalAddress(void *LogicalAddress, 71272343Sngie ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 72272343Sngie{ 73272343Sngie /* We can't necessarily do this, so cop out. */ 74272343Sngie return (AE_BAD_ADDRESS); 75272343Sngie} 76272343Sngie 77272343SngieACPI_STATUS 78272343SngieAcpiOsValidateInterface (char *Interface) 79272343Sngie{ 80272343Sngie return (AE_SUPPORT); 81272343Sngie} 82272343Sngie 83272343SngieBOOLEAN 84272343SngieAcpiOsReadable (void *Pointer, ACPI_SIZE Length) 85272343Sngie{ 86272343Sngie return (TRUE); 87272343Sngie} 88272343Sngie 89272343SngieBOOLEAN 90272343SngieAcpiOsWritable (void *Pointer, ACPI_SIZE Length) 91272343Sngie{ 92 return (TRUE); 93} 94 95ACPI_STATUS 96AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width) 97{ 98 void *LogicalAddress; 99 100 LogicalAddress = AcpiOsMapMemory(Address, Width / 8); 101 if (LogicalAddress == NULL) 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 LogicalAddress = AcpiOsMapMemory(Address, Width / 8); 133 if (LogicalAddress == NULL) 134 return (AE_NOT_EXIST); 135 136 switch (Width) { 137 case 8: 138 (*(volatile u_int8_t *)LogicalAddress) = Value & 0xff; 139 break; 140 case 16: 141 (*(volatile u_int16_t *)LogicalAddress) = Value & 0xffff; 142 break; 143 case 32: 144 (*(volatile u_int32_t *)LogicalAddress) = Value & 0xffffffff; 145 break; 146 case 64: 147 (*(volatile u_int64_t *)LogicalAddress) = Value; 148 break; 149 default: 150 /* debug trap goes here */ 151 break; 152 } 153 154 AcpiOsUnmapMemory(LogicalAddress, Width / 8); 155 156 return (AE_OK); 157} 158