OsdHardware.c revision 213783
1/*- 2 * Copyright (c) 2000, 2001 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28/* 29 * 6.7 : Hardware Abstraction 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD: head/sys/dev/acpica/Osd/OsdHardware.c 213783 2010-10-13 16:30:41Z jkim $"); 34 35#include <contrib/dev/acpica/include/acpi.h> 36 37#include <sys/bus.h> 38#include <sys/kernel.h> 39#include <machine/iodev.h> 40#include <machine/pci_cfgreg.h> 41#include <dev/acpica/acpivar.h> 42#include <dev/pci/pcireg.h> 43 44/* 45 * ACPICA's rather gung-ho approach to hardware resource ownership is a little 46 * troublesome insofar as there is no easy way for us to know in advance 47 * exactly which I/O resources it's going to want to use. 48 * 49 * In order to deal with this, we ignore resource ownership entirely, and simply 50 * use the native I/O space accessor functionality. This is Evil, but it works. 51 */ 52 53ACPI_STATUS 54AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width) 55{ 56 57 switch (Width) { 58 case 8: 59 *Value = iodev_read_1(InPort); 60 break; 61 case 16: 62 *Value = iodev_read_2(InPort); 63 break; 64 case 32: 65 *Value = iodev_read_4(InPort); 66 break; 67 } 68 69 return (AE_OK); 70} 71 72ACPI_STATUS 73AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32 Value, UINT32 Width) 74{ 75 76 switch (Width) { 77 case 8: 78 iodev_write_1(OutPort, Value); 79 break; 80 case 16: 81 iodev_write_2(OutPort, Value); 82 break; 83 case 32: 84 iodev_write_4(OutPort, Value); 85 break; 86 } 87 88 return (AE_OK); 89} 90 91ACPI_STATUS 92AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value, 93 UINT32 Width) 94{ 95 96 if (Width == 64) 97 return (AE_SUPPORT); 98 99 if (!pci_cfgregopen()) 100 return (AE_NOT_EXIST); 101 102 *(UINT64 *)Value = pci_cfgregread(PciId->Bus, PciId->Device, 103 PciId->Function, Register, Width / 8); 104 105 return (AE_OK); 106} 107 108 109ACPI_STATUS 110AcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register, 111 UINT64 Value, UINT32 Width) 112{ 113 114 if (Width == 64) 115 return (AE_SUPPORT); 116 117 if (!pci_cfgregopen()) 118 return (AE_NOT_EXIST); 119 120 pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, 121 Value, Width / 8); 122 123 return (AE_OK); 124} 125