2005-01-05 20:17:21 +00:00
|
|
|
/*-
|
2017-11-27 15:03:07 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
* Copyright (c) 1997, Stefan Esser <se@freebsd.org>
|
2000-10-02 07:11:13 +00:00
|
|
|
* Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
|
|
|
|
* Copyright (c) 2000, BSDi
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-25 21:19:19 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2004-03-13 19:19:13 +00:00
|
|
|
#include <sys/param.h>
|
1995-02-26 05:14:53 +00:00
|
|
|
#include <sys/systm.h>
|
1999-05-18 20:48:43 +00:00
|
|
|
#include <sys/bus.h>
|
2003-02-18 03:36:49 +00:00
|
|
|
#include <sys/lock.h>
|
2008-09-11 21:42:11 +00:00
|
|
|
#include <sys/kernel.h>
|
2003-02-18 03:36:49 +00:00
|
|
|
#include <sys/mutex.h>
|
2009-05-18 21:47:32 +00:00
|
|
|
#include <sys/sysctl.h>
|
2002-07-21 05:35:42 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
2008-08-22 02:14:23 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
2000-10-02 07:11:13 +00:00
|
|
|
#include <machine/pci_cfgreg.h>
|
2000-12-08 22:11:23 +00:00
|
|
|
|
2008-09-10 18:06:08 +00:00
|
|
|
static uint32_t pci_docfgregread(int bus, int slot, int func, int reg,
|
|
|
|
int bytes);
|
2008-08-22 02:14:23 +00:00
|
|
|
static int pciereg_cfgread(int bus, unsigned slot, unsigned func,
|
|
|
|
unsigned reg, unsigned bytes);
|
|
|
|
static void pciereg_cfgwrite(int bus, unsigned slot, unsigned func,
|
|
|
|
unsigned reg, int data, unsigned bytes);
|
2000-10-02 07:11:13 +00:00
|
|
|
static int pcireg_cfgread(int bus, int slot, int func, int reg, int bytes);
|
|
|
|
static void pcireg_cfgwrite(int bus, int slot, int func, int reg, int data, int bytes);
|
2000-04-16 20:48:33 +00:00
|
|
|
|
2009-05-18 21:47:32 +00:00
|
|
|
SYSCTL_DECL(_hw_pci);
|
|
|
|
|
pci_cfgreg.c: Use io port config access for early boot time.
Some early PCIe chipsets are explicitly listed in the white-list to
enable use of the MMIO config space accesses, perhaps because ACPI
tables were not reliable source of the base MCFG address at that time.
For that chipsets, MCFG base was read from the known chipset MCFGbase
config register.
During very early stage of boot, when access to the PCI config space
is performed (see e.g. pci_early_quirks.c), we cannot map 255MB of
registers because the method used with pre-boot pmap overflows initial
kernel page tables.
Move fallback to read MCFGbase to the attachment method of the
x86/legacy device, which removes code duplication, and results in the
use of io accesses until MCFG is parsed or legacy attach called.
For amd64, pre-initialize cfgmech with CFGMECH_1, right now we
dynamically assign CFGMECH_1 to it anyway, and remove checks for
CFGMECH_NONE.
There is a mention in the Intel documentation for corresponding
chipsets that OS must use either io port or MMIO access method, but we
already break this rule by reading MCFGbase register, so one more
access seems to be innocent.
Reported by: longwitz@incore.de
PR: 236838
Reviewed by: avg (other version), jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D19833
2019-04-09 18:07:17 +00:00
|
|
|
/*
|
|
|
|
* For amd64 we assume that type 1 I/O port-based access always works.
|
|
|
|
* If an ACPI MCFG table exists, pcie_cfgregopen() will be called to
|
|
|
|
* switch to memory-mapped access.
|
|
|
|
*/
|
|
|
|
int cfgmech = CFGMECH_1;
|
|
|
|
|
2008-08-22 02:14:23 +00:00
|
|
|
static vm_offset_t pcie_base;
|
|
|
|
static int pcie_minbus, pcie_maxbus;
|
2008-09-10 18:06:08 +00:00
|
|
|
static uint32_t pcie_badslots;
|
2003-02-18 03:36:49 +00:00
|
|
|
static struct mtx pcicfg_mtx;
|
2017-05-04 05:28:46 +00:00
|
|
|
MTX_SYSINIT(pcicfg_mtx, &pcicfg_mtx, "pcicfg_mtx", MTX_SPIN);
|
2008-09-11 21:42:11 +00:00
|
|
|
static int mcfg_enable = 1;
|
2009-05-18 21:47:32 +00:00
|
|
|
SYSCTL_INT(_hw_pci, OID_AUTO, mcfg, CTLFLAG_RDTUN, &mcfg_enable, 0,
|
|
|
|
"Enable support for PCI-e memory mapped config access");
|
2003-02-18 03:36:49 +00:00
|
|
|
|
2000-10-02 07:11:13 +00:00
|
|
|
int
|
|
|
|
pci_cfgregopen(void)
|
2000-08-28 21:48:13 +00:00
|
|
|
{
|
2008-08-22 02:14:23 +00:00
|
|
|
|
2003-05-01 01:05:25 +00:00
|
|
|
return (1);
|
2000-10-02 07:11:13 +00:00
|
|
|
}
|
2000-04-16 20:48:33 +00:00
|
|
|
|
2008-09-10 18:06:08 +00:00
|
|
|
static uint32_t
|
|
|
|
pci_docfgregread(int bus, int slot, int func, int reg, int bytes)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cfgmech == CFGMECH_PCIE &&
|
2009-03-24 18:10:22 +00:00
|
|
|
(bus >= pcie_minbus && bus <= pcie_maxbus) &&
|
2008-09-10 18:06:08 +00:00
|
|
|
(bus != 0 || !(1 << slot & pcie_badslots)))
|
|
|
|
return (pciereg_cfgread(bus, slot, func, reg, bytes));
|
|
|
|
else
|
|
|
|
return (pcireg_cfgread(bus, slot, func, reg, bytes));
|
|
|
|
}
|
|
|
|
|
2000-10-02 07:11:13 +00:00
|
|
|
/*
|
2000-12-08 22:11:23 +00:00
|
|
|
* Read configuration space register
|
2000-10-02 07:11:13 +00:00
|
|
|
*/
|
2000-12-08 22:11:23 +00:00
|
|
|
u_int32_t
|
|
|
|
pci_cfgregread(int bus, int slot, int func, int reg, int bytes)
|
|
|
|
{
|
2002-07-21 05:35:42 +00:00
|
|
|
uint32_t line;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some BIOS writers seem to want to ignore the spec and put
|
2003-05-01 01:05:25 +00:00
|
|
|
* 0 in the intline rather than 255 to indicate none. Some use
|
|
|
|
* numbers in the range 128-254 to indicate something strange and
|
|
|
|
* apparently undocumented anywhere. Assume these are completely bogus
|
|
|
|
* and map them to 255, which the rest of the PCI code recognizes as
|
|
|
|
* as an invalid IRQ.
|
2002-07-21 05:35:42 +00:00
|
|
|
*/
|
|
|
|
if (reg == PCIR_INTLINE && bytes == 1) {
|
2008-09-10 18:06:08 +00:00
|
|
|
line = pci_docfgregread(bus, slot, func, PCIR_INTLINE, 1);
|
2003-05-01 01:05:25 +00:00
|
|
|
if (line == 0 || line >= 128)
|
|
|
|
line = PCI_INVALID_IRQ;
|
|
|
|
return (line);
|
2002-07-21 05:35:42 +00:00
|
|
|
}
|
2008-09-10 18:06:08 +00:00
|
|
|
return (pci_docfgregread(bus, slot, func, reg, bytes));
|
2000-12-08 22:11:23 +00:00
|
|
|
}
|
|
|
|
|
2000-10-02 07:11:13 +00:00
|
|
|
/*
|
|
|
|
* Write configuration space register
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes)
|
2000-04-16 20:48:33 +00:00
|
|
|
{
|
2003-02-18 03:36:49 +00:00
|
|
|
|
2008-09-10 18:06:08 +00:00
|
|
|
if (cfgmech == CFGMECH_PCIE &&
|
2009-03-24 18:10:22 +00:00
|
|
|
(bus >= pcie_minbus && bus <= pcie_maxbus) &&
|
2008-09-10 18:06:08 +00:00
|
|
|
(bus != 0 || !(1 << slot & pcie_badslots)))
|
|
|
|
pciereg_cfgwrite(bus, slot, func, reg, data, bytes);
|
|
|
|
else
|
|
|
|
pcireg_cfgwrite(bus, slot, func, reg, data, bytes);
|
2000-04-16 20:48:33 +00:00
|
|
|
}
|
|
|
|
|
2000-10-02 07:11:13 +00:00
|
|
|
/*
|
|
|
|
* Configuration space access using direct register operations
|
|
|
|
*/
|
1995-02-01 23:06:58 +00:00
|
|
|
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
/* enable configuration space accesses and return data port address */
|
1995-03-21 23:06:07 +00:00
|
|
|
static int
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
pci_cfgenable(unsigned bus, unsigned slot, unsigned func, int reg, int bytes)
|
|
|
|
{
|
2002-07-21 05:35:42 +00:00
|
|
|
int dataport = 0;
|
|
|
|
|
2009-09-24 07:11:23 +00:00
|
|
|
if (bus <= PCI_BUSMAX && slot <= PCI_SLOTMAX && func <= PCI_FUNCMAX &&
|
|
|
|
(unsigned)reg <= PCI_REGMAX && bytes != 3 &&
|
|
|
|
(unsigned)bytes <= 4 && (reg & (bytes - 1)) == 0) {
|
2013-11-30 22:17:27 +00:00
|
|
|
outl(CONF1_ADDR_PORT, (1U << 31) | (bus << 16) | (slot << 11)
|
2007-11-28 22:20:08 +00:00
|
|
|
| (func << 8) | (reg & ~0x03));
|
|
|
|
dataport = CONF1_DATA_PORT + (reg & 0x03);
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
}
|
2002-07-21 05:35:42 +00:00
|
|
|
return (dataport);
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
}
|
1995-03-21 23:06:07 +00:00
|
|
|
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
/* disable configuration space accesses */
|
|
|
|
static void
|
|
|
|
pci_cfgdisable(void)
|
|
|
|
{
|
2007-11-28 22:20:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing. Writing a 0 to the address port can apparently
|
|
|
|
* confuse some bridges and cause spurious access failures.
|
|
|
|
*/
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
}
|
1995-02-01 23:06:58 +00:00
|
|
|
|
2000-04-16 20:48:33 +00:00
|
|
|
static int
|
2000-08-28 21:48:13 +00:00
|
|
|
pcireg_cfgread(int bus, int slot, int func, int reg, int bytes)
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
{
|
2002-07-21 05:35:42 +00:00
|
|
|
int data = -1;
|
|
|
|
int port;
|
|
|
|
|
2003-02-18 03:36:49 +00:00
|
|
|
mtx_lock_spin(&pcicfg_mtx);
|
2002-07-21 05:35:42 +00:00
|
|
|
port = pci_cfgenable(bus, slot, func, reg, bytes);
|
|
|
|
if (port != 0) {
|
|
|
|
switch (bytes) {
|
|
|
|
case 1:
|
|
|
|
data = inb(port);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
data = inw(port);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
data = inl(port);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pci_cfgdisable();
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
}
|
2003-02-18 03:36:49 +00:00
|
|
|
mtx_unlock_spin(&pcicfg_mtx);
|
2002-07-21 05:35:42 +00:00
|
|
|
return (data);
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
}
|
1995-02-01 23:06:58 +00:00
|
|
|
|
2000-04-16 20:48:33 +00:00
|
|
|
static void
|
2000-08-28 21:48:13 +00:00
|
|
|
pcireg_cfgwrite(int bus, int slot, int func, int reg, int data, int bytes)
|
Completely replace the PCI bus driver code to make it better reflect
reality. There will be a new call interface, but for now the file
pci_compat.c (which is to be deleted, after all drivers are converted)
provides an emulation of the old PCI bus driver functions. The only
change that might be visible to drivers is, that the type pcici_t
(which had been meant to be just a handle, whose exact definition
should not be relied on), has been converted into a pcicfgregs* .
The Tekram AMD SCSI driver bogusly relied on the definition of pcici_t
and has been converted to just call the PCI drivers functions to access
configuration space register, instead of inventing its own ...
This code is by no means complete, but assumed to be fully operational,
and brings the official code base more in line with my development code.
A new generic device descriptor data type has to be agreed on. The PCI
code will then use that data type to provide new functionality:
1) userconfig support
2) "wired" PCI devices
3) conflicts checking against ISA/EISA
4) maps will depend on the command register enable bits
5) PCI to Anything bridges can be defined as devices,
and are probed like any "standard" PCI device.
The following features are currently missing, but will be added back,
soon:
1) unknown device probe message
2) suppression of "mirrored" devices caused by ancient, broken chip-sets
This code relies on generic shared interrupt support just commited to
kern_intr.c (plus the modifications of isa.c and isa_device.h).
1997-05-26 15:08:43 +00:00
|
|
|
{
|
2002-07-21 05:35:42 +00:00
|
|
|
int port;
|
|
|
|
|
2003-02-18 03:36:49 +00:00
|
|
|
mtx_lock_spin(&pcicfg_mtx);
|
2002-07-21 05:35:42 +00:00
|
|
|
port = pci_cfgenable(bus, slot, func, reg, bytes);
|
|
|
|
if (port != 0) {
|
|
|
|
switch (bytes) {
|
|
|
|
case 1:
|
|
|
|
outb(port, data);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
outw(port, data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
outl(port, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pci_cfgdisable();
|
1995-09-18 21:48:39 +00:00
|
|
|
}
|
2003-02-18 03:36:49 +00:00
|
|
|
mtx_unlock_spin(&pcicfg_mtx);
|
1995-09-18 21:48:39 +00:00
|
|
|
}
|
2008-08-22 02:14:23 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
pcie_cfgregopen(uint64_t base, uint8_t minbus, uint8_t maxbus)
|
|
|
|
{
|
2008-09-10 18:06:08 +00:00
|
|
|
uint32_t val1, val2;
|
|
|
|
int slot;
|
2008-09-11 21:42:11 +00:00
|
|
|
|
|
|
|
if (!mcfg_enable)
|
|
|
|
return (0);
|
2008-08-22 02:14:23 +00:00
|
|
|
|
|
|
|
if (minbus != 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (bootverbose)
|
|
|
|
printf("PCIe: Memory Mapped configuration base @ 0x%lx\n",
|
|
|
|
base);
|
|
|
|
|
|
|
|
/* XXX: We should make sure this really fits into the direct map. */
|
2018-10-18 20:49:16 +00:00
|
|
|
pcie_base = (vm_offset_t)pmap_mapdev_pciecfg(base, (maxbus + 1) << 20);
|
2008-08-22 02:14:23 +00:00
|
|
|
pcie_minbus = minbus;
|
|
|
|
pcie_maxbus = maxbus;
|
|
|
|
cfgmech = CFGMECH_PCIE;
|
2008-09-10 18:06:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* On some AMD systems, some of the devices on bus 0 are
|
|
|
|
* inaccessible using memory-mapped PCI config access. Walk
|
|
|
|
* bus 0 looking for such devices. For these devices, we will
|
|
|
|
* fall back to using type 1 config access instead.
|
|
|
|
*/
|
|
|
|
if (pci_cfgregopen() != 0) {
|
2009-09-24 07:11:23 +00:00
|
|
|
for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
|
2008-09-10 18:06:08 +00:00
|
|
|
val1 = pcireg_cfgread(0, slot, 0, 0, 4);
|
|
|
|
if (val1 == 0xffffffff)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
val2 = pciereg_cfgread(0, slot, 0, 0, 4);
|
|
|
|
if (val2 != val1)
|
|
|
|
pcie_badslots |= (1 << slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-22 02:14:23 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2012-12-01 00:56:19 +00:00
|
|
|
#define PCIE_VADDR(base, reg, bus, slot, func) \
|
|
|
|
((base) + \
|
|
|
|
((((bus) & 0xff) << 20) | \
|
|
|
|
(((slot) & 0x1f) << 15) | \
|
|
|
|
(((func) & 0x7) << 12) | \
|
|
|
|
((reg) & 0xfff)))
|
|
|
|
|
2012-10-14 10:13:50 +00:00
|
|
|
/*
|
|
|
|
* AMD BIOS And Kernel Developer's Guides for CPU families starting with 10h
|
|
|
|
* have a requirement that all accesses to the memory mapped PCI configuration
|
|
|
|
* space are done using AX class of registers.
|
|
|
|
* Since other vendors do not currently have any contradicting requirements
|
|
|
|
* the AMD access pattern is applied universally.
|
|
|
|
*/
|
2008-08-22 02:14:23 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
pciereg_cfgread(int bus, unsigned slot, unsigned func, unsigned reg,
|
|
|
|
unsigned bytes)
|
|
|
|
{
|
2012-11-30 20:15:01 +00:00
|
|
|
vm_offset_t va;
|
2008-08-22 02:14:23 +00:00
|
|
|
int data = -1;
|
|
|
|
|
2009-09-24 07:11:23 +00:00
|
|
|
if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX ||
|
|
|
|
func > PCI_FUNCMAX || reg > PCIE_REGMAX)
|
2008-08-22 02:14:23 +00:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
va = PCIE_VADDR(pcie_base, reg, bus, slot, func);
|
|
|
|
|
|
|
|
switch (bytes) {
|
|
|
|
case 4:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movl %1, %0" : "=a" (data)
|
|
|
|
: "m" (*(volatile uint32_t *)va));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movzwl %1, %0" : "=a" (data)
|
|
|
|
: "m" (*(volatile uint16_t *)va));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movzbl %1, %0" : "=a" (data)
|
|
|
|
: "m" (*(volatile uint8_t *)va));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pciereg_cfgwrite(int bus, unsigned slot, unsigned func, unsigned reg, int data,
|
|
|
|
unsigned bytes)
|
|
|
|
{
|
2012-11-30 20:15:01 +00:00
|
|
|
vm_offset_t va;
|
2008-08-22 02:14:23 +00:00
|
|
|
|
2009-09-24 07:11:23 +00:00
|
|
|
if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX ||
|
|
|
|
func > PCI_FUNCMAX || reg > PCIE_REGMAX)
|
2008-08-22 02:14:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va = PCIE_VADDR(pcie_base, reg, bus, slot, func);
|
|
|
|
|
|
|
|
switch (bytes) {
|
|
|
|
case 4:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movl %1, %0" : "=m" (*(volatile uint32_t *)va)
|
2012-10-14 10:13:50 +00:00
|
|
|
: "a" (data));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movw %1, %0" : "=m" (*(volatile uint16_t *)va)
|
2012-11-30 00:59:37 +00:00
|
|
|
: "a" ((uint16_t)data));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-11-30 20:15:01 +00:00
|
|
|
__asm("movb %1, %0" : "=m" (*(volatile uint8_t *)va)
|
2012-11-30 00:59:37 +00:00
|
|
|
: "a" ((uint8_t)data));
|
2008-08-22 02:14:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|