Home | History | Annotate | Line # | Download | only in acpica
OsdMemory.c revision 1.2
      1  1.2  jmcneill /*	$NetBSD: OsdMemory.c,v 1.2 2007/12/09 20:27:54 jmcneill Exp $	*/
      2  1.1     kochi 
      3  1.1     kochi /*
      4  1.1     kochi  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1     kochi  * All rights reserved.
      6  1.1     kochi  *
      7  1.1     kochi  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.1     kochi  *
      9  1.1     kochi  * Redistribution and use in source and binary forms, with or without
     10  1.1     kochi  * modification, are permitted provided that the following conditions
     11  1.1     kochi  * are met:
     12  1.1     kochi  * 1. Redistributions of source code must retain the above copyright
     13  1.1     kochi  *    notice, this list of conditions and the following disclaimer.
     14  1.1     kochi  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1     kochi  *    notice, this list of conditions and the following disclaimer in the
     16  1.1     kochi  *    documentation and/or other materials provided with the distribution.
     17  1.1     kochi  * 3. All advertising materials mentioning features or use of this software
     18  1.1     kochi  *    must display the following acknowledgement:
     19  1.1     kochi  *	This product includes software developed for the NetBSD Project by
     20  1.1     kochi  *	Wasabi Systems, Inc.
     21  1.1     kochi  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1     kochi  *    or promote products derived from this software without specific prior
     23  1.1     kochi  *    written permission.
     24  1.1     kochi  *
     25  1.1     kochi  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1     kochi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1     kochi  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1     kochi  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1     kochi  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1     kochi  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1     kochi  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1     kochi  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1     kochi  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1     kochi  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1     kochi  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1     kochi  */
     37  1.1     kochi 
     38  1.1     kochi /*
     39  1.1     kochi  * OS Services Layer
     40  1.1     kochi  *
     41  1.1     kochi  * 6.2: Memory management.
     42  1.1     kochi  */
     43  1.1     kochi 
     44  1.1     kochi #include <sys/cdefs.h>
     45  1.2  jmcneill __KERNEL_RCSID(0, "$NetBSD: OsdMemory.c,v 1.2 2007/12/09 20:27:54 jmcneill Exp $");
     46  1.1     kochi 
     47  1.1     kochi #include <sys/param.h>
     48  1.1     kochi #include <sys/malloc.h>
     49  1.1     kochi 
     50  1.1     kochi #include <dev/acpi/acpica.h>
     51  1.1     kochi 
     52  1.1     kochi #include <machine/acpi_machdep.h>
     53  1.1     kochi 
     54  1.1     kochi MALLOC_DECLARE(M_ACPI);
     55  1.1     kochi 
     56  1.1     kochi /*
     57  1.1     kochi  * AcpiOsMapMemory:
     58  1.1     kochi  *
     59  1.1     kochi  *	Map physical memory into the caller's address space.
     60  1.1     kochi  */
     61  1.2  jmcneill void *
     62  1.2  jmcneill AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length)
     63  1.1     kochi {
     64  1.2  jmcneill 	ACPI_STATUS Status;
     65  1.2  jmcneill 	void *LogicalAddress = NULL;
     66  1.1     kochi 
     67  1.2  jmcneill 	Status = acpi_md_OsMapMemory(PhysicalAddress, Length, &LogicalAddress);
     68  1.2  jmcneill 	if (ACPI_FAILURE (Status))
     69  1.2  jmcneill 		return NULL;
     70  1.2  jmcneill 	return LogicalAddress;
     71  1.1     kochi }
     72  1.1     kochi 
     73  1.1     kochi /*
     74  1.1     kochi  * AcpiOsUnmapMemory:
     75  1.1     kochi  *
     76  1.1     kochi  *	Remove a physical to logical memory mapping.
     77  1.1     kochi  */
     78  1.1     kochi void
     79  1.1     kochi AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length)
     80  1.1     kochi {
     81  1.1     kochi 
     82  1.1     kochi 	acpi_md_OsUnmapMemory(LogicalAddress, Length);
     83  1.1     kochi }
     84  1.1     kochi 
     85  1.1     kochi /*
     86  1.1     kochi  * AcpiOsGetPhysicalAddress:
     87  1.1     kochi  *
     88  1.1     kochi  *	Translate a logical address to a physical address.
     89  1.1     kochi  */
     90  1.1     kochi ACPI_STATUS
     91  1.1     kochi AcpiOsGetPhysicalAddress(void *LogicalAddress,
     92  1.1     kochi     ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
     93  1.1     kochi {
     94  1.1     kochi 
     95  1.1     kochi 	return acpi_md_OsGetPhysicalAddress(LogicalAddress, PhysicalAddress);
     96  1.1     kochi }
     97  1.1     kochi 
     98  1.1     kochi /*
     99  1.1     kochi  * AcpiOsAllocate:
    100  1.1     kochi  *
    101  1.1     kochi  *	Allocate memory from the dynamic memory pool.
    102  1.1     kochi  */
    103  1.1     kochi void *
    104  1.1     kochi AcpiOsAllocate(ACPI_SIZE Size)
    105  1.1     kochi {
    106  1.1     kochi 
    107  1.1     kochi 	return malloc(Size, M_ACPI, M_NOWAIT);
    108  1.1     kochi }
    109  1.1     kochi 
    110  1.1     kochi /*
    111  1.1     kochi  * AcpiOsFree:
    112  1.1     kochi  *
    113  1.1     kochi  *	Free previously allocated memory.
    114  1.1     kochi  */
    115  1.1     kochi void
    116  1.1     kochi AcpiOsFree(void *Memory)
    117  1.1     kochi {
    118  1.1     kochi 
    119  1.1     kochi 	free(Memory, M_ACPI);
    120  1.1     kochi }
    121  1.1     kochi 
    122  1.1     kochi 
    123  1.1     kochi /*
    124  1.1     kochi  * AcpiOsReadable:
    125  1.1     kochi  *
    126  1.1     kochi  *	Check if a memory region is readable.
    127  1.1     kochi  */
    128  1.1     kochi BOOLEAN
    129  1.1     kochi AcpiOsReadable(void *Pointer, ACPI_SIZE Length)
    130  1.1     kochi {
    131  1.1     kochi 
    132  1.1     kochi 	return acpi_md_OsReadable(Pointer, Length);
    133  1.1     kochi }
    134  1.1     kochi 
    135  1.1     kochi /*
    136  1.1     kochi  * AcpiOsWritable:
    137  1.1     kochi  *
    138  1.1     kochi  *	Check if a memory region is writable (and readable).
    139  1.1     kochi  */
    140  1.1     kochi BOOLEAN
    141  1.1     kochi AcpiOsWritable(void *Pointer, ACPI_SIZE Length)
    142  1.1     kochi {
    143  1.1     kochi 
    144  1.1     kochi 	return acpi_md_OsWritable(Pointer, Length);
    145  1.1     kochi }
    146  1.2  jmcneill 
    147  1.2  jmcneill ACPI_STATUS
    148  1.2  jmcneill AcpiOsValidateInterface(char *Interface)
    149  1.2  jmcneill {
    150  1.2  jmcneill 
    151  1.2  jmcneill 	return AE_SUPPORT;
    152  1.2  jmcneill }
    153  1.2  jmcneill 
    154  1.2  jmcneill ACPI_STATUS
    155  1.2  jmcneill AcpiOsValidateAddress(UINT8 SpaceId, ACPI_PHYSICAL_ADDRESS Address,
    156  1.2  jmcneill     ACPI_SIZE Length)
    157  1.2  jmcneill {
    158  1.2  jmcneill 
    159  1.2  jmcneill 	return AE_OK;
    160  1.2  jmcneill }
    161