xref: /freebsd/sys/dev/acpica/Osd/OsdMemory.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1fd660059SMike Smith /*-
2c434440bSMike Smith  * Copyright (c) 2000 Mitsaru Iwasaki
3fd660059SMike Smith  * Copyright (c) 2000 Michael Smith
4fd660059SMike Smith  * Copyright (c) 2000 BSDi
5fd660059SMike Smith  * All rights reserved.
6fd660059SMike Smith  *
7fd660059SMike Smith  * Redistribution and use in source and binary forms, with or without
8fd660059SMike Smith  * modification, are permitted provided that the following conditions
9fd660059SMike Smith  * are met:
10fd660059SMike Smith  * 1. Redistributions of source code must retain the above copyright
11fd660059SMike Smith  *    notice, this list of conditions and the following disclaimer.
12fd660059SMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
13fd660059SMike Smith  *    notice, this list of conditions and the following disclaimer in the
14fd660059SMike Smith  *    documentation and/or other materials provided with the distribution.
15fd660059SMike Smith  *
16fd660059SMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17fd660059SMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18fd660059SMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19fd660059SMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20fd660059SMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21fd660059SMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22fd660059SMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23fd660059SMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24fd660059SMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25fd660059SMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26fd660059SMike Smith  * SUCH DAMAGE.
27fd660059SMike Smith  */
28fd660059SMike Smith 
29fd660059SMike Smith /*
30fd660059SMike Smith  * 6.2 : Memory Management
31fd660059SMike Smith  */
32fd660059SMike Smith 
33a3ab9d1eSNate Lawson #include <sys/cdefs.h>
34129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
35fd660059SMike Smith 
36fd660059SMike Smith #include <sys/kernel.h>
37fd660059SMike Smith #include <sys/malloc.h>
38fd660059SMike Smith #include <vm/vm.h>
39fd660059SMike Smith #include <vm/pmap.h>
40fd660059SMike Smith 
41d745c852SEd Schouten static MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool");
42fd660059SMike Smith 
43fd660059SMike Smith void *
AcpiOsAllocate(ACPI_SIZE Size)4475a3a26dSPeter Wemm AcpiOsAllocate(ACPI_SIZE Size)
45fd660059SMike Smith {
46fd660059SMike Smith     return (malloc(Size, M_ACPICA, M_NOWAIT));
47fd660059SMike Smith }
48fd660059SMike Smith 
49fd660059SMike Smith void
AcpiOsFree(void * Memory)50fd660059SMike Smith AcpiOsFree(void *Memory)
51fd660059SMike Smith {
52fd660059SMike Smith     free(Memory, M_ACPICA);
53fd660059SMike Smith }
54fd660059SMike Smith 
552be4e471SJung-uk Kim void *
AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress,ACPI_SIZE Length)56129d3046SJung-uk Kim AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length)
57fd660059SMike Smith {
582be4e471SJung-uk Kim     return (pmap_mapbios((vm_offset_t)PhysicalAddress, Length));
59fd660059SMike Smith }
60fd660059SMike Smith 
61fd660059SMike Smith void
AcpiOsUnmapMemory(void * LogicalAddress,ACPI_SIZE Length)6275a3a26dSPeter Wemm AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length)
63fd660059SMike Smith {
64*7ae99f80SJohn Baldwin     pmap_unmapbios(LogicalAddress, Length);
65fd660059SMike Smith }
66fd660059SMike Smith 
679d839ea8SMike Smith ACPI_STATUS
AcpiOsGetPhysicalAddress(void * LogicalAddress,ACPI_PHYSICAL_ADDRESS * PhysicalAddress)68c871a6daSNate Lawson AcpiOsGetPhysicalAddress(void *LogicalAddress,
69c871a6daSNate Lawson     ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
709d839ea8SMike Smith {
71c871a6daSNate Lawson     /* We can't necessarily do this, so cop out. */
729d839ea8SMike Smith     return (AE_BAD_ADDRESS);
739d839ea8SMike Smith }
749d839ea8SMike Smith 
75fd660059SMike Smith BOOLEAN
AcpiOsReadable(void * Pointer,ACPI_SIZE Length)766613111bSMarcel Moolenaar AcpiOsReadable (void *Pointer, ACPI_SIZE Length)
77fd660059SMike Smith {
78fd660059SMike Smith     return (TRUE);
79fd660059SMike Smith }
80fd660059SMike Smith 
81fd660059SMike Smith BOOLEAN
AcpiOsWritable(void * Pointer,ACPI_SIZE Length)826613111bSMarcel Moolenaar AcpiOsWritable (void *Pointer, ACPI_SIZE Length)
83fd660059SMike Smith {
84fd660059SMike Smith     return (TRUE);
85fd660059SMike Smith }
86fd660059SMike Smith 
879d839ea8SMike Smith ACPI_STATUS
AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address,UINT64 * Value,UINT32 Width)88a159c266SJung-uk Kim AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 *Value, UINT32 Width)
89c434440bSMike Smith {
90c434440bSMike Smith     void	*LogicalAddress;
91c434440bSMike Smith 
92aa353b1bSJung-uk Kim     LogicalAddress = pmap_mapdev(Address, Width / 8);
932be4e471SJung-uk Kim     if (LogicalAddress == NULL)
949d839ea8SMike Smith 	return (AE_NOT_EXIST);
95c434440bSMike Smith 
969d839ea8SMike Smith     switch (Width) {
979d839ea8SMike Smith     case 8:
9889339b38SJung-uk Kim 	*Value = *(volatile uint8_t *)LogicalAddress;
999d839ea8SMike Smith 	break;
1009d839ea8SMike Smith     case 16:
10189339b38SJung-uk Kim 	*Value = *(volatile uint16_t *)LogicalAddress;
1029d839ea8SMike Smith 	break;
1039d839ea8SMike Smith     case 32:
10489339b38SJung-uk Kim 	*Value = *(volatile uint32_t *)LogicalAddress;
10530171114SPeter Wemm 	break;
106a159c266SJung-uk Kim     case 64:
107a159c266SJung-uk Kim 	*Value = *(volatile uint64_t *)LogicalAddress;
108a159c266SJung-uk Kim 	break;
1099d839ea8SMike Smith     }
1109d839ea8SMike Smith 
111*7ae99f80SJohn Baldwin     pmap_unmapdev(LogicalAddress, Width / 8);
1129d839ea8SMike Smith 
1139d839ea8SMike Smith     return (AE_OK);
1149d839ea8SMike Smith }
1159d839ea8SMike Smith 
1169d839ea8SMike Smith ACPI_STATUS
AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address,UINT64 Value,UINT32 Width)117a159c266SJung-uk Kim AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 Value, UINT32 Width)
1189d839ea8SMike Smith {
1199d839ea8SMike Smith     void	*LogicalAddress;
1209d839ea8SMike Smith 
121aa353b1bSJung-uk Kim     LogicalAddress = pmap_mapdev(Address, Width / 8);
1222be4e471SJung-uk Kim     if (LogicalAddress == NULL)
1239d839ea8SMike Smith 	return (AE_NOT_EXIST);
1249d839ea8SMike Smith 
1259d839ea8SMike Smith     switch (Width) {
1269d839ea8SMike Smith     case 8:
12789339b38SJung-uk Kim 	*(volatile uint8_t *)LogicalAddress = Value;
128c434440bSMike Smith 	break;
1299d839ea8SMike Smith     case 16:
13089339b38SJung-uk Kim 	*(volatile uint16_t *)LogicalAddress = Value;
131c434440bSMike Smith 	break;
1329d839ea8SMike Smith     case 32:
13389339b38SJung-uk Kim 	*(volatile uint32_t *)LogicalAddress = Value;
13430171114SPeter Wemm 	break;
135a159c266SJung-uk Kim     case 64:
136a159c266SJung-uk Kim 	*(volatile uint64_t *)LogicalAddress = Value;
137a159c266SJung-uk Kim 	break;
138c434440bSMike Smith     }
139c434440bSMike Smith 
140*7ae99f80SJohn Baldwin     pmap_unmapdev(LogicalAddress, Width / 8);
141c434440bSMike Smith 
1429d839ea8SMike Smith     return (AE_OK);
143c434440bSMike Smith }
144