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 2867760Smsmith/* 2967760Smsmith * 6.7 : Hardware Abstraction 3067760Smsmith */ 3167760Smsmith 32148318Snjl#include <sys/cdefs.h> 33148318Snjl__FBSDID("$FreeBSD$"); 34148318Snjl 35193530Sjkim#include <contrib/dev/acpica/include/acpi.h> 3667760Smsmith 37210157Sjkim#include <machine/iodev.h> 3867760Smsmith#include <machine/pci_cfgreg.h> 3967760Smsmith 4067760Smsmith/* 4167760Smsmith * ACPICA's rather gung-ho approach to hardware resource ownership is a little 42157452Snjl * 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. 44157452Snjl * 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 4980071SmsmithACPI_STATUS 50128225SnjlAcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width) 5167760Smsmith{ 52157245Snjl 5380071Smsmith switch (Width) { 5480071Smsmith case 8: 55210157Sjkim *Value = iodev_read_1(InPort); 56209966Sjkim break; 5780071Smsmith case 16: 58210157Sjkim *Value = iodev_read_2(InPort); 59209966Sjkim break; 6080071Smsmith case 32: 61210157Sjkim *Value = iodev_read_4(InPort); 62209966Sjkim break; 6380071Smsmith } 6467760Smsmith 65128225Snjl return (AE_OK); 6667760Smsmith} 6767760Smsmith 6867760SmsmithACPI_STATUS 69128225SnjlAcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32 Value, UINT32 Width) 7067760Smsmith{ 71157245Snjl 7280071Smsmith switch (Width) { 7380071Smsmith case 8: 74210157Sjkim iodev_write_1(OutPort, Value); 75209966Sjkim break; 7680071Smsmith case 16: 77210157Sjkim iodev_write_2(OutPort, Value); 78209966Sjkim break; 7980071Smsmith case 32: 80210157Sjkim iodev_write_4(OutPort, Value); 81209966Sjkim break; 8280071Smsmith } 8367760Smsmith 84128225Snjl return (AE_OK); 8567760Smsmith} 8667760Smsmith 8767760SmsmithACPI_STATUS 88210976SjkimAcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value, 89128225Snjl UINT32 Width) 9067760Smsmith{ 9167760Smsmith 92210137Sjkim if (Width == 64) 93210137Sjkim return (AE_SUPPORT); 94210137Sjkim 9567760Smsmith if (!pci_cfgregopen()) 96209966Sjkim return (AE_NOT_EXIST); 9767760Smsmith 98210137Sjkim *(UINT64 *)Value = pci_cfgregread(PciId->Bus, PciId->Device, 99210137Sjkim PciId->Function, Register, Width / 8); 100157452Snjl 101128225Snjl return (AE_OK); 10267760Smsmith} 10367760Smsmith 10480071Smsmith 10567760SmsmithACPI_STATUS 106128225SnjlAcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register, 107202771Sjkim UINT64 Value, UINT32 Width) 10867760Smsmith{ 10967760Smsmith 110210137Sjkim if (Width == 64) 111210137Sjkim return (AE_SUPPORT); 112210137Sjkim 11367760Smsmith if (!pci_cfgregopen()) 114128225Snjl return (AE_NOT_EXIST); 11567760Smsmith 116128225Snjl pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, 117210137Sjkim Value, Width / 8); 11880071Smsmith 119128225Snjl return (AE_OK); 12067760Smsmith} 121