OsdHardware.c revision 92666
167760Smsmith/*- 280071Smsmith * Copyright (c) 2000, 2001 Michael Smith 367760Smsmith * Copyright (c) 2000 BSDi 467760Smsmith * All rights reserved. 567760Smsmith * 667760Smsmith * Redistribution and use in source and binary forms, with or without 767760Smsmith * modification, are permitted provided that the following conditions 867760Smsmith * are met: 967760Smsmith * 1. Redistributions of source code must retain the above copyright 1067760Smsmith * notice, this list of conditions and the following disclaimer. 1167760Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1267760Smsmith * notice, this list of conditions and the following disclaimer in the 1367760Smsmith * documentation and/or other materials provided with the distribution. 1467760Smsmith * 1567760Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1667760Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1767760Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1867760Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1967760Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2067760Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2167760Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2267760Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2367760Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2467760Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2567760Smsmith * SUCH DAMAGE. 2667760Smsmith * 2767760Smsmith * $FreeBSD: head/sys/dev/acpica/Osd/OsdHardware.c 92666 2002-03-19 11:02:06Z peter $ 2867760Smsmith */ 2967760Smsmith 3067760Smsmith/* 3167760Smsmith * 6.7 : Hardware Abstraction 3267760Smsmith */ 3367760Smsmith 3467760Smsmith#include "acpi.h" 3567760Smsmith 3667760Smsmith#include <machine/bus_pio.h> 3767760Smsmith#include <machine/bus.h> 3867760Smsmith#include <machine/pci_cfgreg.h> 3967760Smsmith 4067760Smsmith/* 4167760Smsmith * ACPICA's rather gung-ho approach to hardware resource ownership is a little 4267760Smsmith * troublesome insofar as there is no easy way for us to know in advance 4367760Smsmith * exactly which I/O resources it's going to want to use. 4467760Smsmith * 4567760Smsmith * In order to deal with this, we ignore resource ownership entirely, and simply 4667760Smsmith * use the native I/O space accessor functionality. This is Evil, but it works. 4767760Smsmith * 4867760Smsmith * XXX use an intermediate #define for the tag/handle 4967760Smsmith */ 5067760Smsmith 5184446Sdfr#ifdef __i386__ 5267760Smsmith#define ACPI_BUS_SPACE_IO I386_BUS_SPACE_IO 5367760Smsmith#define ACPI_BUS_HANDLE 0 5484446Sdfr#endif 5584446Sdfr#ifdef __ia64__ 5684446Sdfr#define ACPI_BUS_SPACE_IO IA64_BUS_SPACE_IO 5784446Sdfr#define ACPI_BUS_HANDLE 0 5884446Sdfr#endif 5967760Smsmith 6080071SmsmithACPI_STATUS 6180071SmsmithAcpiOsReadPort ( 6280071Smsmith ACPI_IO_ADDRESS InPort, 6380071Smsmith void *Value, 6480071Smsmith UINT32 Width) 6567760Smsmith{ 6680071Smsmith switch (Width) { 6780071Smsmith case 8: 6880071Smsmith *(u_int8_t *)Value = bus_space_read_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); 6980071Smsmith break; 7080071Smsmith case 16: 7180071Smsmith *(u_int16_t *)Value = bus_space_read_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); 7280071Smsmith break; 7380071Smsmith case 32: 7480071Smsmith *(u_int32_t *)Value = bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); 7580071Smsmith break; 7680071Smsmith default: 7780071Smsmith /* debug trap goes here */ 7892666Speter break; 7980071Smsmith } 8067760Smsmith 8180071Smsmith return(AE_OK); 8267760Smsmith} 8367760Smsmith 8467760SmsmithACPI_STATUS 8580071SmsmithAcpiOsWritePort ( 8680071Smsmith ACPI_IO_ADDRESS OutPort, 8787036Smsmith ACPI_INTEGER Value, 8880071Smsmith UINT32 Width) 8967760Smsmith{ 9080071Smsmith switch (Width) { 9180071Smsmith case 8: 9280071Smsmith bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 9380071Smsmith break; 9480071Smsmith case 16: 9580071Smsmith bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 9680071Smsmith break; 9780071Smsmith case 32: 9880071Smsmith bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 9980071Smsmith break; 10080071Smsmith default: 10180071Smsmith /* debug trap goes here */ 10292666Speter break; 10380071Smsmith } 10467760Smsmith 10567760Smsmith return(AE_OK); 10667760Smsmith} 10767760Smsmith 10867760SmsmithACPI_STATUS 10980071SmsmithAcpiOsReadPciConfiguration ( 11080071Smsmith ACPI_PCI_ID *PciId, 11180071Smsmith UINT32 Register, 11280071Smsmith void *Value, 11380071Smsmith UINT32 Width) 11467760Smsmith{ 11580071Smsmith u_int32_t byte_width = Width / 8; 11680071Smsmith u_int32_t val; 11767760Smsmith 11867760Smsmith if (!pci_cfgregopen()) 11980071Smsmith return(AE_NOT_EXIST); 12067760Smsmith 12180071Smsmith val = pci_cfgregread(PciId->Bus, PciId->Device, PciId->Function, Register, byte_width); 12280071Smsmith switch (Width) { 12380071Smsmith case 8: 12480071Smsmith *(u_int8_t *)Value = val & 0xff; 12580071Smsmith break; 12680071Smsmith case 16: 12780071Smsmith *(u_int16_t *)Value = val & 0xffff; 12880071Smsmith break; 12980071Smsmith case 32: 13080071Smsmith *(u_int32_t *)Value = val; 13180071Smsmith break; 13280071Smsmith default: 13380071Smsmith /* debug trap goes here */ 13492666Speter break; 13580071Smsmith } 13680071Smsmith 13780071Smsmith 13867760Smsmith return(AE_OK); 13967760Smsmith} 14067760Smsmith 14180071Smsmith 14267760SmsmithACPI_STATUS 14380071SmsmithAcpiOsWritePciConfiguration ( 14480071Smsmith ACPI_PCI_ID *PciId, 14580071Smsmith UINT32 Register, 14687036Smsmith ACPI_INTEGER Value, 14780071Smsmith UINT32 Width) 14867760Smsmith{ 14980071Smsmith u_int32_t byte_width = Width / 8; 15067760Smsmith 15167760Smsmith if (!pci_cfgregopen()) 15280071Smsmith return(AE_NOT_EXIST); 15367760Smsmith 15480071Smsmith pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, Value, byte_width); 15580071Smsmith 15667760Smsmith return(AE_OK); 15767760Smsmith} 158