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
2967760Smsmith/*
3067760Smsmith * 6.2 : Memory Management
3167760Smsmith */
3267760Smsmith
33148318Snjl#include <sys/cdefs.h>
34148318Snjl__FBSDID("$FreeBSD$");
35148318Snjl
36193530Sjkim#include <contrib/dev/acpica/include/acpi.h>
3767760Smsmith
3867760Smsmith#include <sys/kernel.h>
3967760Smsmith#include <sys/malloc.h>
4067760Smsmith#include <vm/vm.h>
4167760Smsmith#include <vm/pmap.h>
4267760Smsmith
43249132Smavstatic MALLOC_DEFINE(M_ACPICA, "acpica", "ACPI CA memory pool");
4467760Smsmith
4567760Smsmithvoid *
4692118SpeterAcpiOsAllocate(ACPI_SIZE Size)
4767760Smsmith{
48128225Snjl    return (malloc(Size, M_ACPICA, M_NOWAIT));
4967760Smsmith}
5067760Smsmith
5167760Smsmithvoid
52128225SnjlAcpiOsFree(void *Memory)
5367760Smsmith{
5467760Smsmith    free(Memory, M_ACPICA);
5567760Smsmith}
5667760Smsmith
57167814Sjkimvoid *
58193530SjkimAcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length)
5967760Smsmith{
60167814Sjkim    return (pmap_mapbios((vm_offset_t)PhysicalAddress, Length));
6167760Smsmith}
6267760Smsmith
6367760Smsmithvoid
64128225SnjlAcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length)
6567760Smsmith{
66161223Sjhb    pmap_unmapbios((vm_offset_t)LogicalAddress, Length);
6767760Smsmith}
6867760Smsmith
6980071SmsmithACPI_STATUS
70128225SnjlAcpiOsGetPhysicalAddress(void *LogicalAddress,
71128225Snjl    ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
7280071Smsmith{
73128225Snjl    /* We can't necessarily do this, so cop out. */
74128225Snjl    return (AE_BAD_ADDRESS);
7580071Smsmith}
7680071Smsmith
7767760SmsmithBOOLEAN
78117534SmarcelAcpiOsReadable (void *Pointer, ACPI_SIZE Length)
7967760Smsmith{
80128225Snjl    return (TRUE);
8167760Smsmith}
8267760Smsmith
8367760SmsmithBOOLEAN
84117534SmarcelAcpiOsWritable (void *Pointer, ACPI_SIZE Length)
8567760Smsmith{
86128225Snjl    return (TRUE);
8767760Smsmith}
8867760Smsmith
8980071SmsmithACPI_STATUS
90128225SnjlAcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width)
9169459Smsmith{
9269459Smsmith    void	*LogicalAddress;
9369459Smsmith
94210155Sjkim    LogicalAddress = pmap_mapdev(Address, Width / 8);
95167814Sjkim    if (LogicalAddress == NULL)
96128225Snjl	return (AE_NOT_EXIST);
9769459Smsmith
9880071Smsmith    switch (Width) {
9980071Smsmith    case 8:
100210129Sjkim	*Value = *(volatile uint8_t *)LogicalAddress;
10169459Smsmith	break;
10280071Smsmith    case 16:
103210129Sjkim	*Value = *(volatile uint16_t *)LogicalAddress;
10469459Smsmith	break;
10580071Smsmith    case 32:
106210129Sjkim	*Value = *(volatile uint32_t *)LogicalAddress;
10769459Smsmith	break;
10869459Smsmith    }
10969459Smsmith
110210155Sjkim    pmap_unmapdev((vm_offset_t)LogicalAddress, Width / 8);
11169459Smsmith
112128225Snjl    return (AE_OK);
11369459Smsmith}
11469459Smsmith
11580071SmsmithACPI_STATUS
116128225SnjlAcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width)
11769459Smsmith{
11869459Smsmith    void	*LogicalAddress;
11969459Smsmith
120210155Sjkim    LogicalAddress = pmap_mapdev(Address, Width / 8);
121167814Sjkim    if (LogicalAddress == NULL)
122128225Snjl	return (AE_NOT_EXIST);
12369459Smsmith
12480071Smsmith    switch (Width) {
12580071Smsmith    case 8:
126210129Sjkim	*(volatile uint8_t *)LogicalAddress = Value;
12769459Smsmith	break;
12880071Smsmith    case 16:
129210129Sjkim	*(volatile uint16_t *)LogicalAddress = Value;
13069459Smsmith	break;
13180071Smsmith    case 32:
132210129Sjkim	*(volatile uint32_t *)LogicalAddress = Value;
13369459Smsmith	break;
13469459Smsmith    }
13569459Smsmith
136210155Sjkim    pmap_unmapdev((vm_offset_t)LogicalAddress, Width / 8);
13769459Smsmith
138128225Snjl    return (AE_OK);
13969459Smsmith}
140