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-08-22 02:14:23 +00:00
|
|
|
enum {
|
|
|
|
CFGMECH_NONE = 0,
|
|
|
|
CFGMECH_1,
|
|
|
|
CFGMECH_PCIE,
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
2008-08-22 02:14:23 +00:00
|
|
|
static int cfgmech;
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Initialise access to PCI configuration space
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pci_cfgregopen(void)
|
2000-08-28 21:48:13 +00:00
|
|
|
{
|
2008-08-22 02:14:23 +00:00
|
|
|
uint64_t pciebar;
|
|
|
|
uint16_t did, vid;
|
2002-07-21 05:35:42 +00:00
|
|
|
|
2008-08-22 02:14:23 +00:00
|
|
|
if (cfgmech != CFGMECH_NONE)
|
2003-05-01 01:05:25 +00:00
|
|
|
return (1);
|
2008-08-22 02:14:23 +00:00
|
|
|
cfgmech = CFGMECH_1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grope around in the PCI config space to see if this is a
|
|
|
|
* chipset that is capable of doing memory-mapped config cycles.
|
|
|
|
* This also implies that it can do PCIe extended config cycles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Check for supported chipsets */
|
|
|
|
vid = pci_cfgregread(0, 0, 0, PCIR_VENDOR, 2);
|
|
|
|
did = pci_cfgregread(0, 0, 0, PCIR_DEVICE, 2);
|
|
|
|
switch (vid) {
|
|
|
|
case 0x8086:
|
|
|
|
switch (did) {
|
|
|
|
case 0x3590:
|
|
|
|
case 0x3592:
|
|
|
|
/* Intel 7520 or 7320 */
|
|
|
|
pciebar = pci_cfgregread(0, 0, 0, 0xce, 2) << 16;
|
|
|
|
pcie_cfgregopen(pciebar, 0, 255);
|
|
|
|
break;
|
|
|
|
case 0x2580:
|
|
|
|
case 0x2584:
|
|
|
|
case 0x2590:
|
|
|
|
/* Intel 915, 925, or 915GM */
|
|
|
|
pciebar = pci_cfgregread(0, 0, 0, 0x48, 4);
|
|
|
|
pcie_cfgregopen(pciebar, 0, 255);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2017-05-04 05:28:46 +00:00
|
|
|
if (cfgmech == CFGMECH_NONE)
|
|
|
|
return (0xffffffff);
|
|
|
|
|
2002-07-21 05:35:42 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
2017-05-04 05:28:46 +00:00
|
|
|
if (cfgmech == CFGMECH_NONE)
|
|
|
|
return;
|
|
|
|
|
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. */
|
|
|
|
pcie_base = (vm_offset_t)pmap_mapdev(base, (maxbus + 1) << 20);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|