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-12-13 01:25:11 +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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $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
|
|
|
*
|
|
|
|
*/
|
1994-09-01 01:45:19 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
#include "opt_bus.h"
|
|
|
|
|
1994-09-14 01:34:51 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-10-12 02:33:23 +00:00
|
|
|
#include <sys/malloc.h>
|
1999-04-24 19:59:20 +00:00
|
|
|
#include <sys/module.h>
|
2000-12-08 22:11:23 +00:00
|
|
|
#include <sys/linker.h>
|
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
|
|
|
#include <sys/fcntl.h>
|
1996-10-22 20:20:14 +00:00
|
|
|
#include <sys/conf.h>
|
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
|
|
|
#include <sys/kernel.h>
|
1998-09-15 08:21:13 +00:00
|
|
|
#include <sys/queue.h>
|
2002-07-26 07:58:16 +00:00
|
|
|
#include <sys/sysctl.h>
|
1998-09-15 08:21:13 +00:00
|
|
|
#include <sys/types.h>
|
1995-03-21 23:01:06 +00:00
|
|
|
|
1994-09-01 01:45:19 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/pmap.h>
|
1998-09-15 08:21:13 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-09-01 01:45:19 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2000-05-28 16:35:57 +00:00
|
|
|
#include <sys/pciio.h>
|
2002-02-27 05:09:14 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pci_private.h>
|
1995-03-21 23:01:06 +00:00
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
#include "pcib_if.h"
|
2000-12-13 01:25:11 +00:00
|
|
|
#include "pci_if.h"
|
|
|
|
|
|
|
|
static u_int32_t pci_mapbase(unsigned mapreg);
|
|
|
|
static int pci_maptype(unsigned mapreg);
|
|
|
|
static int pci_mapsize(unsigned testval);
|
|
|
|
static int pci_maprange(unsigned mapreg);
|
|
|
|
static void pci_fixancient(pcicfgregs *cfg);
|
|
|
|
|
|
|
|
static int pci_porten(device_t pcib, int b, int s, int f);
|
|
|
|
static int pci_memen(device_t pcib, int b, int s, int f);
|
|
|
|
static int pci_add_map(device_t pcib, int b, int s, int f, int reg,
|
|
|
|
struct resource_list *rl);
|
2002-08-26 15:23:52 +00:00
|
|
|
static void pci_add_resources(device_t pcib, device_t dev);
|
2000-12-13 01:25:11 +00:00
|
|
|
static int pci_probe(device_t dev);
|
2002-08-26 15:23:52 +00:00
|
|
|
static int pci_attach(device_t dev);
|
2002-09-04 03:13:16 +00:00
|
|
|
static void pci_load_vendor_data(void);
|
2000-12-13 01:25:11 +00:00
|
|
|
static int pci_describe_parse_line(char **ptr, int *vendor,
|
|
|
|
int *device, char **desc);
|
|
|
|
static char *pci_describe_device(device_t dev);
|
|
|
|
static int pci_modevent(module_t mod, int what, void *arg);
|
2003-02-17 19:47:02 +00:00
|
|
|
static void pci_hdrtypedata(device_t pcib, int b, int s, int f,
|
|
|
|
pcicfgregs *cfg);
|
|
|
|
static void pci_read_extcap(device_t pcib, pcicfgregs *cfg);
|
2000-12-13 01:25:11 +00:00
|
|
|
|
|
|
|
static device_method_t pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, pci_probe),
|
2002-08-26 15:23:52 +00:00
|
|
|
DEVMETHOD(device_attach, pci_attach),
|
2000-12-13 01:25:11 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, pci_print_child),
|
|
|
|
DEVMETHOD(bus_probe_nomatch, pci_probe_nomatch),
|
|
|
|
DEVMETHOD(bus_read_ivar, pci_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, pci_write_ivar),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
|
|
|
|
|
|
|
DEVMETHOD(bus_get_resource_list,pci_get_resource_list),
|
|
|
|
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
|
|
|
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
|
|
|
DEVMETHOD(bus_delete_resource, pci_delete_resource),
|
|
|
|
DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
|
|
|
|
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
2003-02-17 21:20:35 +00:00
|
|
|
DEVMETHOD(bus_child_pnpinfo_str, pci_child_pnpinfo_str_method),
|
|
|
|
DEVMETHOD(bus_child_location_str, pci_child_location_str_method),
|
2000-12-13 01:25:11 +00:00
|
|
|
|
|
|
|
/* PCI interface */
|
|
|
|
DEVMETHOD(pci_read_config, pci_read_config_method),
|
|
|
|
DEVMETHOD(pci_write_config, pci_write_config_method),
|
2001-02-27 23:13:20 +00:00
|
|
|
DEVMETHOD(pci_enable_busmaster, pci_enable_busmaster_method),
|
|
|
|
DEVMETHOD(pci_disable_busmaster, pci_disable_busmaster_method),
|
|
|
|
DEVMETHOD(pci_enable_io, pci_enable_io_method),
|
|
|
|
DEVMETHOD(pci_disable_io, pci_disable_io_method),
|
|
|
|
DEVMETHOD(pci_get_powerstate, pci_get_powerstate_method),
|
|
|
|
DEVMETHOD(pci_set_powerstate, pci_set_powerstate_method),
|
2000-12-13 01:25:11 +00:00
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t pci_driver = {
|
|
|
|
"pci",
|
|
|
|
pci_methods,
|
|
|
|
0, /* no softc */
|
|
|
|
};
|
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
devclass_t pci_devclass;
|
2000-12-13 01:25:11 +00:00
|
|
|
DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);
|
2002-04-17 00:31:32 +00:00
|
|
|
MODULE_VERSION(pci, 1);
|
2000-08-28 21:48:13 +00:00
|
|
|
|
2000-12-08 22:11:23 +00:00
|
|
|
static char *pci_vendordata;
|
|
|
|
static size_t pci_vendordata_size;
|
1997-06-25 20:56:29 +00:00
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
|
1999-10-28 08:06:59 +00:00
|
|
|
struct pci_quirk {
|
|
|
|
u_int32_t devid; /* Vendor/device of the card */
|
|
|
|
int type;
|
2001-02-06 09:25:10 +00:00
|
|
|
#define PCI_QUIRK_MAP_REG 1 /* PCI map register in weird place */
|
1999-10-28 08:06:59 +00:00
|
|
|
int arg1;
|
|
|
|
int arg2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_quirk pci_quirks[] = {
|
2001-12-21 01:28:59 +00:00
|
|
|
/* The Intel 82371AB and 82443MX has a map register at offset 0x90. */
|
1999-10-28 08:06:59 +00:00
|
|
|
{ 0x71138086, PCI_QUIRK_MAP_REG, 0x90, 0 },
|
2001-12-21 01:28:59 +00:00
|
|
|
{ 0x719b8086, PCI_QUIRK_MAP_REG, 0x90, 0 },
|
2001-03-15 06:51:45 +00:00
|
|
|
/* As does the Serverworks OSB4 (the SMBus mapping register) */
|
|
|
|
{ 0x02001166, PCI_QUIRK_MAP_REG, 0x90, 0 },
|
1999-10-28 08:06:59 +00:00
|
|
|
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
1999-10-14 21:38:33 +00:00
|
|
|
/* map register information */
|
|
|
|
#define PCI_MAPMEM 0x01 /* memory map */
|
|
|
|
#define PCI_MAPMEMP 0x02 /* prefetchable memory map */
|
|
|
|
#define PCI_MAPPORT 0x04 /* port map */
|
|
|
|
|
2001-12-19 08:49:11 +00:00
|
|
|
struct devlist pci_devq;
|
|
|
|
u_int32_t pci_generation;
|
1998-09-15 08:21:13 +00:00
|
|
|
u_int32_t pci_numdevs = 0;
|
|
|
|
|
2002-07-26 07:58:16 +00:00
|
|
|
/* sysctl vars */
|
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, pci, CTLFLAG_RD, 0, "PCI bus tuning parameters");
|
|
|
|
|
2002-11-13 09:40:09 +00:00
|
|
|
static int pci_enable_io_modes = 1;
|
2002-07-26 07:58:16 +00:00
|
|
|
TUNABLE_INT("hw.pci.enable_io_modes", (int *)&pci_enable_io_modes);
|
|
|
|
SYSCTL_INT(_hw_pci, OID_AUTO, enable_io_modes, CTLFLAG_RW,
|
|
|
|
&pci_enable_io_modes, 1,
|
|
|
|
"Enable I/O and memory bits in the config register. Some BIOSes do not\n\
|
|
|
|
enable these bits correctly. We'd like to do this all the time, but there\n\
|
|
|
|
are some peripherals that this causes problems with.");
|
|
|
|
|
2002-01-10 00:56:02 +00:00
|
|
|
/* Find a device_t by bus/slot/function */
|
|
|
|
|
|
|
|
device_t
|
2002-10-16 19:11:59 +00:00
|
|
|
pci_find_bsf(u_int8_t bus, u_int8_t slot, u_int8_t func)
|
2002-01-10 00:56:02 +00:00
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
|
|
|
|
STAILQ_FOREACH(dinfo, &pci_devq, pci_links) {
|
|
|
|
if ((dinfo->cfg.bus == bus) &&
|
|
|
|
(dinfo->cfg.slot == slot) &&
|
|
|
|
(dinfo->cfg.func == func)) {
|
|
|
|
return (dinfo->cfg.dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a device_t by vendor/device ID */
|
|
|
|
|
|
|
|
device_t
|
2002-10-16 19:11:59 +00:00
|
|
|
pci_find_device(u_int16_t vendor, u_int16_t device)
|
2002-01-10 00:56:02 +00:00
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
|
|
|
|
STAILQ_FOREACH(dinfo, &pci_devq, pci_links) {
|
|
|
|
if ((dinfo->cfg.vendor == vendor) &&
|
|
|
|
(dinfo->cfg.device == device)) {
|
|
|
|
return (dinfo->cfg.dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* return base address of memory or port map */
|
1994-10-12 02:33:23 +00:00
|
|
|
|
1999-10-14 21:38:33 +00:00
|
|
|
static u_int32_t
|
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_mapbase(unsigned mapreg)
|
1995-03-21 23:01:06 +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
|
|
|
int mask = 0x03;
|
|
|
|
if ((mapreg & 0x01) == 0)
|
|
|
|
mask = 0x0f;
|
|
|
|
return (mapreg & ~mask);
|
1995-03-21 23:01:06 +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
|
|
|
/* return map type of memory or port map */
|
1996-04-14 20:14:36 +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_maptype(unsigned mapreg)
|
|
|
|
{
|
|
|
|
static u_int8_t maptype[0x10] = {
|
|
|
|
PCI_MAPMEM, PCI_MAPPORT,
|
|
|
|
PCI_MAPMEM, 0,
|
|
|
|
PCI_MAPMEM, PCI_MAPPORT,
|
|
|
|
0, 0,
|
|
|
|
PCI_MAPMEM|PCI_MAPMEMP, PCI_MAPPORT,
|
|
|
|
PCI_MAPMEM|PCI_MAPMEMP, 0,
|
|
|
|
PCI_MAPMEM|PCI_MAPMEMP, PCI_MAPPORT,
|
|
|
|
0, 0,
|
1997-01-21 23:23:40 +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
|
|
|
return maptype[mapreg & 0x0f];
|
1997-01-21 23:23:40 +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
|
|
|
/* return log2 of map size decoded for memory or port map */
|
1995-03-21 23:01:06 +00:00
|
|
|
|
1996-01-30 01:14:29 +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_mapsize(unsigned testval)
|
1996-01-30 01:14:29 +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
|
|
|
int ln2size;
|
1996-01-30 01:14:29 +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
|
|
|
testval = pci_mapbase(testval);
|
1997-05-28 10:01:03 +00:00
|
|
|
ln2size = 0;
|
|
|
|
if (testval != 0) {
|
|
|
|
while ((testval & 1) == 0)
|
|
|
|
{
|
|
|
|
ln2size++;
|
|
|
|
testval >>= 1;
|
|
|
|
}
|
1995-09-07 15:20:53 +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
|
|
|
return (ln2size);
|
1995-03-21 23:01:06 +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
|
|
|
/* return log2 of address range supported by map register */
|
1995-03-21 23:01:06 +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
|
|
|
static int
|
|
|
|
pci_maprange(unsigned mapreg)
|
|
|
|
{
|
|
|
|
int ln2range = 0;
|
|
|
|
switch (mapreg & 0x07) {
|
|
|
|
case 0x00:
|
|
|
|
case 0x01:
|
|
|
|
case 0x05:
|
|
|
|
ln2range = 32;
|
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
ln2range = 20;
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
ln2range = 64;
|
|
|
|
break;
|
1996-04-14 20:14:36 +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
|
|
|
return (ln2range);
|
1995-02-02 13:12:18 +00:00
|
|
|
}
|
1995-03-21 23:01:06 +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
|
|
|
/* adjust some values from PCI 1.0 devices to match 2.0 standards ... */
|
1997-01-21 23:23:40 +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
|
|
|
static void
|
|
|
|
pci_fixancient(pcicfgregs *cfg)
|
1997-01-21 23:23:40 +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
|
|
|
if (cfg->hdrtype != 0)
|
|
|
|
return;
|
1997-01-21 23:23:40 +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
|
|
|
/* PCI to PCI bridges use header type 1 */
|
1998-08-13 19:12:20 +00:00
|
|
|
if (cfg->baseclass == PCIC_BRIDGE && cfg->subclass == PCIS_BRIDGE_PCI)
|
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
|
|
|
cfg->hdrtype = 1;
|
1997-01-21 23:23:40 +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
|
|
|
/* extract header type specific config data */
|
1995-03-21 23:01:06 +00:00
|
|
|
|
2003-02-17 19:47:02 +00:00
|
|
|
static void
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg)
|
1995-03-21 23:01:06 +00:00
|
|
|
{
|
2000-08-28 21:48:13 +00:00
|
|
|
#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
|
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
|
|
|
switch (cfg->hdrtype) {
|
|
|
|
case 0:
|
2000-08-28 21:48:13 +00:00
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_0, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_0, 2);
|
1999-10-14 21:38:33 +00:00
|
|
|
cfg->nummaps = PCI_MAXMAPS_0;
|
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
|
|
|
break;
|
|
|
|
case 1:
|
2000-08-28 21:48:13 +00:00
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_1, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_1, 2);
|
1999-10-14 21:38:33 +00:00
|
|
|
cfg->nummaps = PCI_MAXMAPS_1;
|
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
|
|
|
break;
|
|
|
|
case 2:
|
2000-08-28 21:48:13 +00:00
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_2, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_2, 2);
|
1999-10-14 21:38:33 +00:00
|
|
|
cfg->nummaps = PCI_MAXMAPS_2;
|
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
|
|
|
break;
|
1995-09-07 15:20:53 +00:00
|
|
|
}
|
2000-08-28 21:48:13 +00:00
|
|
|
#undef REG
|
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:01:06 +00:00
|
|
|
|
2000-12-13 01:25:11 +00:00
|
|
|
/* read configuration header into pcicfgregs structure */
|
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-02-27 05:09:14 +00:00
|
|
|
struct pci_devinfo *
|
2002-03-13 16:32:11 +00:00
|
|
|
pci_read_device(device_t pcib, int b, int s, int f, size_t size)
|
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
|
|
|
{
|
2000-08-28 21:48:13 +00:00
|
|
|
#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
|
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
|
|
|
pcicfgregs *cfg = NULL;
|
1998-09-15 08:21:13 +00:00
|
|
|
struct pci_devinfo *devlist_entry;
|
|
|
|
struct devlist *devlist_head;
|
|
|
|
|
|
|
|
devlist_head = &pci_devq;
|
|
|
|
|
|
|
|
devlist_entry = NULL;
|
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
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
if (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_DEVVENDOR, 4) != -1) {
|
2003-02-19 05:47:46 +00:00
|
|
|
devlist_entry = malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
|
1998-09-15 08:21:13 +00:00
|
|
|
if (devlist_entry == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
cfg = &devlist_entry->cfg;
|
1999-05-20 15:33:33 +00:00
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
cfg->bus = b;
|
|
|
|
cfg->slot = s;
|
|
|
|
cfg->func = f;
|
|
|
|
cfg->vendor = REG(PCIR_VENDOR, 2);
|
|
|
|
cfg->device = REG(PCIR_DEVICE, 2);
|
|
|
|
cfg->cmdreg = REG(PCIR_COMMAND, 2);
|
|
|
|
cfg->statreg = REG(PCIR_STATUS, 2);
|
|
|
|
cfg->baseclass = REG(PCIR_CLASS, 1);
|
|
|
|
cfg->subclass = REG(PCIR_SUBCLASS, 1);
|
|
|
|
cfg->progif = REG(PCIR_PROGIF, 1);
|
|
|
|
cfg->revid = REG(PCIR_REVID, 1);
|
|
|
|
cfg->hdrtype = REG(PCIR_HEADERTYPE, 1);
|
|
|
|
cfg->cachelnsz = REG(PCIR_CACHELNSZ, 1);
|
|
|
|
cfg->lattimer = REG(PCIR_LATTIMER, 1);
|
|
|
|
cfg->intpin = REG(PCIR_INTPIN, 1);
|
|
|
|
cfg->intline = REG(PCIR_INTLINE, 1);
|
1997-05-27 04:09:01 +00:00
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
cfg->mingnt = REG(PCIR_MINGNT, 1);
|
|
|
|
cfg->maxlat = REG(PCIR_MAXLAT, 1);
|
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
|
|
|
|
|
|
|
cfg->mfdev = (cfg->hdrtype & PCIM_MFDEV) != 0;
|
|
|
|
cfg->hdrtype &= ~PCIM_MFDEV;
|
|
|
|
|
|
|
|
pci_fixancient(cfg);
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_hdrtypedata(pcib, b, s, f, cfg);
|
1998-09-15 08:21:13 +00:00
|
|
|
|
2000-12-13 01:25:11 +00:00
|
|
|
if (REG(PCIR_STATUS, 2) & PCIM_STATUS_CAPPRESENT)
|
|
|
|
pci_read_extcap(pcib, cfg);
|
|
|
|
|
1998-09-15 08:21:13 +00:00
|
|
|
STAILQ_INSERT_TAIL(devlist_head, devlist_entry, pci_links);
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_sel.pc_bus = cfg->bus;
|
|
|
|
devlist_entry->conf.pc_sel.pc_dev = cfg->slot;
|
|
|
|
devlist_entry->conf.pc_sel.pc_func = cfg->func;
|
|
|
|
devlist_entry->conf.pc_hdr = cfg->hdrtype;
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_subvendor = cfg->subvendor;
|
|
|
|
devlist_entry->conf.pc_subdevice = cfg->subdevice;
|
|
|
|
devlist_entry->conf.pc_vendor = cfg->vendor;
|
|
|
|
devlist_entry->conf.pc_device = cfg->device;
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_class = cfg->baseclass;
|
|
|
|
devlist_entry->conf.pc_subclass = cfg->subclass;
|
|
|
|
devlist_entry->conf.pc_progif = cfg->progif;
|
|
|
|
devlist_entry->conf.pc_revid = cfg->revid;
|
|
|
|
|
|
|
|
pci_numdevs++;
|
|
|
|
pci_generation++;
|
1995-09-07 15:20:53 +00:00
|
|
|
}
|
1998-09-15 08:21:13 +00:00
|
|
|
return (devlist_entry);
|
2000-08-28 21:48:13 +00:00
|
|
|
#undef REG
|
1995-03-21 23:01:06 +00:00
|
|
|
}
|
|
|
|
|
2003-02-17 19:47:02 +00:00
|
|
|
static void
|
2000-12-13 01:25:11 +00:00
|
|
|
pci_read_extcap(device_t pcib, pcicfgregs *cfg)
|
|
|
|
{
|
|
|
|
#define REG(n, w) PCIB_READ_CONFIG(pcib, cfg->bus, cfg->slot, cfg->func, n, w)
|
|
|
|
int ptr, nextptr, ptrptr;
|
|
|
|
|
|
|
|
switch (cfg->hdrtype) {
|
|
|
|
case 0:
|
|
|
|
ptrptr = 0x34;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ptrptr = 0x14;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return; /* no extended capabilities support */
|
|
|
|
}
|
|
|
|
nextptr = REG(ptrptr, 1); /* sanity check? */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read capability entries.
|
|
|
|
*/
|
|
|
|
while (nextptr != 0) {
|
2001-01-01 16:49:31 +00:00
|
|
|
/* Sanity check */
|
|
|
|
if (nextptr > 255) {
|
|
|
|
printf("illegal PCI extended capability offset %d\n",
|
|
|
|
nextptr);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
/* Find the next entry */
|
|
|
|
ptr = nextptr;
|
|
|
|
nextptr = REG(ptr + 1, 1);
|
|
|
|
|
|
|
|
/* Process this entry */
|
|
|
|
switch (REG(ptr, 1)) {
|
|
|
|
case 0x01: /* PCI power management */
|
|
|
|
if (cfg->pp_cap == 0) {
|
|
|
|
cfg->pp_cap = REG(ptr + PCIR_POWER_CAP, 2);
|
|
|
|
cfg->pp_status = ptr + PCIR_POWER_STATUS;
|
|
|
|
cfg->pp_pmcsr = ptr + PCIR_POWER_PMCSR;
|
|
|
|
if ((nextptr - ptr) > PCIR_POWER_DATA)
|
|
|
|
cfg->pp_data = ptr + PCIR_POWER_DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef REG
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* free pcicfgregs structure and all depending data structures */
|
1995-03-21 23:01:06 +00:00
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
1998-09-15 08:21:13 +00:00
|
|
|
pci_freecfg(struct pci_devinfo *dinfo)
|
1995-03-21 23:01:06 +00:00
|
|
|
{
|
1998-09-15 08:21:13 +00:00
|
|
|
struct devlist *devlist_head;
|
|
|
|
|
|
|
|
devlist_head = &pci_devq;
|
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
STAILQ_REMOVE(devlist_head, dinfo, pci_devinfo, pci_links);
|
1998-09-15 08:21:13 +00:00
|
|
|
free(dinfo, M_DEVBUF);
|
|
|
|
|
|
|
|
/* increment the generation count */
|
|
|
|
pci_generation++;
|
|
|
|
|
|
|
|
/* we're losing one device */
|
|
|
|
pci_numdevs--;
|
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
|
|
|
return (0);
|
1995-03-21 23:01:06 +00:00
|
|
|
}
|
|
|
|
|
1996-10-22 20:20:14 +00:00
|
|
|
/*
|
2000-12-13 01:25:11 +00:00
|
|
|
* PCI power manangement
|
1996-10-22 20:20:14 +00:00
|
|
|
*/
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_set_powerstate_method(device_t dev, device_t child, int state)
|
1996-10-22 20:20:14 +00:00
|
|
|
{
|
2001-02-27 23:13:20 +00:00
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(child);
|
2000-12-13 01:25:11 +00:00
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
u_int16_t status;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (cfg->pp_cap != 0) {
|
2001-02-27 23:13:20 +00:00
|
|
|
status = PCI_READ_CONFIG(dev, child, cfg->pp_status, 2) & ~PCIM_PSTAT_DMASK;
|
2000-12-13 01:25:11 +00:00
|
|
|
result = 0;
|
|
|
|
switch (state) {
|
|
|
|
case PCI_POWERSTATE_D0:
|
|
|
|
status |= PCIM_PSTAT_D0;
|
|
|
|
break;
|
|
|
|
case PCI_POWERSTATE_D1:
|
|
|
|
if (cfg->pp_cap & PCIM_PCAP_D1SUPP) {
|
|
|
|
status |= PCIM_PSTAT_D1;
|
|
|
|
} else {
|
|
|
|
result = EOPNOTSUPP;
|
1999-05-31 22:13:37 +00:00
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWERSTATE_D2:
|
|
|
|
if (cfg->pp_cap & PCIM_PCAP_D2SUPP) {
|
|
|
|
status |= PCIM_PSTAT_D2;
|
|
|
|
} else {
|
|
|
|
result = EOPNOTSUPP;
|
1999-05-31 22:13:37 +00:00
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWERSTATE_D3:
|
|
|
|
status |= PCIM_PSTAT_D3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = EINVAL;
|
1999-05-31 22:13:37 +00:00
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
if (result == 0)
|
2001-02-27 23:13:20 +00:00
|
|
|
PCI_WRITE_CONFIG(dev, child, cfg->pp_status, status, 2);
|
2000-12-13 01:25:11 +00:00
|
|
|
} else {
|
|
|
|
result = ENXIO;
|
1999-05-31 22:13:37 +00:00
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
return(result);
|
1999-05-31 22:13:37 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_get_powerstate_method(device_t dev, device_t child)
|
1996-10-22 20:20:14 +00:00
|
|
|
{
|
2001-02-27 23:13:20 +00:00
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(child);
|
2000-12-13 01:25:11 +00:00
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
u_int16_t status;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (cfg->pp_cap != 0) {
|
2001-02-27 23:13:20 +00:00
|
|
|
status = PCI_READ_CONFIG(dev, child, cfg->pp_status, 2);
|
2000-12-13 01:25:11 +00:00
|
|
|
switch (status & PCIM_PSTAT_DMASK) {
|
|
|
|
case PCIM_PSTAT_D0:
|
|
|
|
result = PCI_POWERSTATE_D0;
|
1998-09-15 08:21:13 +00:00
|
|
|
break;
|
2000-12-13 01:25:11 +00:00
|
|
|
case PCIM_PSTAT_D1:
|
|
|
|
result = PCI_POWERSTATE_D1;
|
1998-09-15 08:21:13 +00:00
|
|
|
break;
|
2000-12-13 01:25:11 +00:00
|
|
|
case PCIM_PSTAT_D2:
|
|
|
|
result = PCI_POWERSTATE_D2;
|
1998-09-15 08:21:13 +00:00
|
|
|
break;
|
2000-12-13 01:25:11 +00:00
|
|
|
case PCIM_PSTAT_D3:
|
|
|
|
result = PCI_POWERSTATE_D3;
|
1998-09-15 08:21:13 +00:00
|
|
|
break;
|
2000-12-13 01:25:11 +00:00
|
|
|
default:
|
|
|
|
result = PCI_POWERSTATE_UNKNOWN;
|
1998-09-15 08:21:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-12-13 01:25:11 +00:00
|
|
|
} else {
|
|
|
|
/* No support, device is always at D0 */
|
|
|
|
result = PCI_POWERSTATE_D0;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
1998-09-15 08:21:13 +00:00
|
|
|
|
2000-12-13 01:25:11 +00:00
|
|
|
/*
|
|
|
|
* Some convenience functions for PCI device drivers.
|
|
|
|
*/
|
1998-09-15 08:21:13 +00:00
|
|
|
|
2000-12-13 01:25:11 +00:00
|
|
|
static __inline void
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_set_command_bit(device_t dev, device_t child, u_int16_t bit)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2002-06-01 03:41:02 +00:00
|
|
|
u_int16_t command;
|
1998-09-15 08:21:13 +00:00
|
|
|
|
2002-06-01 03:41:02 +00:00
|
|
|
command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
|
|
|
|
command |= bit;
|
|
|
|
PCI_WRITE_CONFIG(dev, child, PCIR_COMMAND, command, 2);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1998-09-15 08:21:13 +00:00
|
|
|
|
2000-12-13 01:25:11 +00:00
|
|
|
static __inline void
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_clear_command_bit(device_t dev, device_t child, u_int16_t bit)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2002-06-01 03:41:02 +00:00
|
|
|
u_int16_t command;
|
1996-10-22 20:20:14 +00:00
|
|
|
|
2002-06-01 03:41:02 +00:00
|
|
|
command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
|
|
|
|
command &= ~bit;
|
|
|
|
PCI_WRITE_CONFIG(dev, child, PCIR_COMMAND, command, 2);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1997-01-21 23:23:40 +00:00
|
|
|
|
2003-04-16 03:15:08 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_enable_busmaster_method(device_t dev, device_t child)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2002-06-01 03:41:02 +00:00
|
|
|
pci_set_command_bit(dev, child, PCIM_CMD_BUSMASTEREN);
|
2003-04-16 03:15:08 +00:00
|
|
|
return (0);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1996-10-22 20:20:14 +00:00
|
|
|
|
2003-04-16 03:15:08 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_disable_busmaster_method(device_t dev, device_t child)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2002-06-01 03:41:02 +00:00
|
|
|
pci_clear_command_bit(dev, child, PCIM_CMD_BUSMASTEREN);
|
2003-04-16 03:15:08 +00:00
|
|
|
return (0);
|
1996-10-22 20:20:14 +00:00
|
|
|
}
|
|
|
|
|
2003-04-16 03:15:08 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_enable_io_method(device_t dev, device_t child, int space)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2003-04-16 03:15:08 +00:00
|
|
|
u_int16_t command;
|
|
|
|
u_int16_t bit;
|
|
|
|
char *error;
|
|
|
|
|
|
|
|
bit = 0;
|
|
|
|
error = NULL;
|
|
|
|
|
2002-06-01 03:41:02 +00:00
|
|
|
switch(space) {
|
|
|
|
case SYS_RES_IOPORT:
|
2003-04-16 03:15:08 +00:00
|
|
|
bit = PCIM_CMD_PORTEN;
|
|
|
|
error = "port";
|
2002-06-01 03:41:02 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_MEMORY:
|
2003-04-16 03:15:08 +00:00
|
|
|
bit = PCIM_CMD_MEMEN;
|
|
|
|
error = "memory";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
2002-06-01 03:41:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-04-16 03:15:08 +00:00
|
|
|
pci_set_command_bit(dev, child, bit);
|
|
|
|
command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
|
|
|
|
if (command & bit)
|
|
|
|
return (0);
|
|
|
|
device_printf(child, "failed to enable %s mapping!\n", error);
|
|
|
|
return (ENXIO);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1996-10-22 20:20:14 +00:00
|
|
|
|
2003-04-16 03:15:08 +00:00
|
|
|
int
|
2001-02-27 23:13:20 +00:00
|
|
|
pci_disable_io_method(device_t dev, device_t child, int space)
|
2000-12-13 01:25:11 +00:00
|
|
|
{
|
2003-04-16 03:15:08 +00:00
|
|
|
u_int16_t command;
|
|
|
|
u_int16_t bit;
|
|
|
|
char *error;
|
|
|
|
|
|
|
|
bit = 0;
|
|
|
|
error = NULL;
|
|
|
|
|
2002-06-01 03:41:02 +00:00
|
|
|
switch(space) {
|
|
|
|
case SYS_RES_IOPORT:
|
2003-04-16 03:15:08 +00:00
|
|
|
bit = PCIM_CMD_PORTEN;
|
|
|
|
error = "port";
|
2002-06-01 03:41:02 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_MEMORY:
|
2003-04-16 03:15:08 +00:00
|
|
|
bit = PCIM_CMD_MEMEN;
|
|
|
|
error = "memory";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
2002-06-01 03:41:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-04-16 03:15:08 +00:00
|
|
|
pci_clear_command_bit(dev, child, bit);
|
|
|
|
command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
|
|
|
|
if (command & bit) {
|
|
|
|
device_printf(child, "failed to disable %s mapping!\n", error);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
return (0);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* New style pci driver. Parent device is either a pci-host-bridge or a
|
|
|
|
* pci-pci-bridge. Both kinds are represented by instances of pcib.
|
|
|
|
*/
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
void
|
1999-04-16 21:22:55 +00:00
|
|
|
pci_print_verbose(struct pci_devinfo *dinfo)
|
|
|
|
{
|
|
|
|
if (bootverbose) {
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
printf("found->\tvendor=0x%04x, dev=0x%04x, revid=0x%02x\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->vendor, cfg->device, cfg->revid);
|
2000-09-05 00:32:19 +00:00
|
|
|
printf("\tbus=%d, slot=%d, func=%d\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->bus, cfg->slot, cfg->func);
|
1999-04-16 21:22:55 +00:00
|
|
|
printf("\tclass=%02x-%02x-%02x, hdrtype=0x%02x, mfdev=%d\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->baseclass, cfg->subclass, cfg->progif, cfg->hdrtype,
|
|
|
|
cfg->mfdev);
|
1999-04-16 21:22:55 +00:00
|
|
|
printf("\tcmdreg=0x%04x, statreg=0x%04x, cachelnsz=%d (dwords)\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->cmdreg, cfg->statreg, cfg->cachelnsz);
|
1999-04-16 21:22:55 +00:00
|
|
|
printf("\tlattimer=0x%02x (%d ns), mingnt=0x%02x (%d ns), maxlat=0x%02x (%d ns)\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->lattimer, cfg->lattimer * 30, cfg->mingnt,
|
|
|
|
cfg->mingnt * 250, cfg->maxlat, cfg->maxlat * 250);
|
1999-04-16 21:22:55 +00:00
|
|
|
if (cfg->intpin > 0)
|
2002-06-01 03:41:02 +00:00
|
|
|
printf("\tintpin=%c, irq=%d\n",
|
|
|
|
cfg->intpin +'a' -1, cfg->intline);
|
2000-12-13 01:25:11 +00:00
|
|
|
if (cfg->pp_cap) {
|
|
|
|
u_int16_t status;
|
|
|
|
|
|
|
|
status = pci_read_config(cfg->dev, cfg->pp_status, 2);
|
|
|
|
printf("\tpowerspec %d supports D0%s%s D3 current D%d\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->pp_cap & PCIM_PCAP_SPEC,
|
|
|
|
cfg->pp_cap & PCIM_PCAP_D1SUPP ? " D1" : "",
|
|
|
|
cfg->pp_cap & PCIM_PCAP_D2SUPP ? " D2" : "",
|
|
|
|
status & PCIM_PSTAT_DMASK);
|
2000-12-13 01:25:11 +00:00
|
|
|
}
|
1999-10-14 21:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_porten(device_t pcib, int b, int s, int f)
|
1999-10-14 21:38:33 +00:00
|
|
|
{
|
2000-08-28 21:48:13 +00:00
|
|
|
return (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2)
|
|
|
|
& PCIM_CMD_PORTEN) != 0;
|
1999-10-14 21:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_memen(device_t pcib, int b, int s, int f)
|
1999-10-14 21:38:33 +00:00
|
|
|
{
|
2000-08-28 21:48:13 +00:00
|
|
|
return (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2)
|
|
|
|
& PCIM_CMD_MEMEN) != 0;
|
1999-10-14 21:38:33 +00:00
|
|
|
}
|
|
|
|
|
1999-10-28 08:06:59 +00:00
|
|
|
/*
|
|
|
|
* Add a resource based on a pci map register. Return 1 if the map
|
|
|
|
* register is a 32bit map register or 2 if it is a 64bit register.
|
|
|
|
*/
|
|
|
|
static int
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_add_map(device_t pcib, int b, int s, int f, int reg,
|
|
|
|
struct resource_list *rl)
|
1999-10-14 21:38:33 +00:00
|
|
|
{
|
1999-10-28 08:06:59 +00:00
|
|
|
u_int32_t map;
|
|
|
|
u_int64_t base;
|
|
|
|
u_int8_t ln2size;
|
|
|
|
u_int8_t ln2range;
|
|
|
|
u_int32_t testval;
|
2000-09-01 23:09:02 +00:00
|
|
|
u_int16_t cmd;
|
1999-10-28 08:06:59 +00:00
|
|
|
int type;
|
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
map = PCIB_READ_CONFIG(pcib, b, s, f, reg, 4);
|
1999-10-28 08:06:59 +00:00
|
|
|
|
|
|
|
if (map == 0 || map == 0xffffffff)
|
2002-06-01 05:44:45 +00:00
|
|
|
return (1); /* skip invalid entry */
|
1999-10-28 08:06:59 +00:00
|
|
|
|
2000-08-28 21:48:13 +00:00
|
|
|
PCIB_WRITE_CONFIG(pcib, b, s, f, reg, 0xffffffff, 4);
|
|
|
|
testval = PCIB_READ_CONFIG(pcib, b, s, f, reg, 4);
|
|
|
|
PCIB_WRITE_CONFIG(pcib, b, s, f, reg, map, 4);
|
1999-10-28 08:06:59 +00:00
|
|
|
|
|
|
|
base = pci_mapbase(map);
|
|
|
|
if (pci_maptype(map) & PCI_MAPMEM)
|
|
|
|
type = SYS_RES_MEMORY;
|
|
|
|
else
|
|
|
|
type = SYS_RES_IOPORT;
|
|
|
|
ln2size = pci_mapsize(testval);
|
|
|
|
ln2range = pci_maprange(testval);
|
|
|
|
if (ln2range == 64) {
|
|
|
|
/* Read the other half of a 64bit map register */
|
2000-08-28 21:48:13 +00:00
|
|
|
base |= (u_int64_t) PCIB_READ_CONFIG(pcib, b, s, f, reg + 4, 4) << 32;
|
1999-10-28 08:06:59 +00:00
|
|
|
}
|
1999-10-14 21:38:33 +00:00
|
|
|
|
2000-03-18 19:18:36 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
printf("\tmap[%02x]: type %x, range %2d, base %08x, size %2d",
|
2002-06-01 03:41:02 +00:00
|
|
|
reg, pci_maptype(map), ln2range,
|
|
|
|
(unsigned int) base, ln2size);
|
2000-08-28 21:48:13 +00:00
|
|
|
if (type == SYS_RES_IOPORT && !pci_porten(pcib, b, s, f))
|
2000-03-18 19:18:36 +00:00
|
|
|
printf(", port disabled\n");
|
2000-08-28 21:48:13 +00:00
|
|
|
else if (type == SYS_RES_MEMORY && !pci_memen(pcib, b, s, f))
|
2000-03-18 19:18:36 +00:00
|
|
|
printf(", memory disabled\n");
|
|
|
|
else
|
|
|
|
printf(", enabled\n");
|
|
|
|
}
|
2000-10-28 23:07:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This code theoretically does the right thing, but has
|
|
|
|
* undesirable side effects in some cases where
|
|
|
|
* peripherals respond oddly to having these bits
|
|
|
|
* enabled. Leave them alone by default.
|
|
|
|
*/
|
2002-07-26 07:58:16 +00:00
|
|
|
if (pci_enable_io_modes) {
|
|
|
|
/* Turn on resources that have been left off by a lazy BIOS */
|
|
|
|
if (type == SYS_RES_IOPORT && !pci_porten(pcib, b, s, f)) {
|
|
|
|
cmd = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2);
|
|
|
|
cmd |= PCIM_CMD_PORTEN;
|
|
|
|
PCIB_WRITE_CONFIG(pcib, b, s, f, PCIR_COMMAND, cmd, 2);
|
|
|
|
}
|
|
|
|
if (type == SYS_RES_MEMORY && !pci_memen(pcib, b, s, f)) {
|
|
|
|
cmd = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2);
|
|
|
|
cmd |= PCIM_CMD_MEMEN;
|
|
|
|
PCIB_WRITE_CONFIG(pcib, b, s, f, PCIR_COMMAND, cmd, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == SYS_RES_IOPORT && !pci_porten(pcib, b, s, f))
|
|
|
|
return (1);
|
|
|
|
if (type == SYS_RES_MEMORY && !pci_memen(pcib, b, s, f))
|
|
|
|
return (1);
|
2000-09-01 23:09:02 +00:00
|
|
|
}
|
2002-06-01 03:41:02 +00:00
|
|
|
resource_list_add(rl, type, reg, base, base + (1 << ln2size) - 1,
|
|
|
|
(1 << ln2size));
|
1999-10-14 21:38:33 +00:00
|
|
|
|
2002-06-01 05:44:45 +00:00
|
|
|
return ((ln2range == 64) ? 2 : 1);
|
1999-10-28 08:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 15:23:52 +00:00
|
|
|
pci_add_resources(device_t pcib, device_t dev)
|
1999-10-28 08:06:59 +00:00
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(dev);
|
2000-08-28 21:48:13 +00:00
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
1999-10-28 08:06:59 +00:00
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct pci_quirk *q;
|
2002-08-26 15:23:52 +00:00
|
|
|
int b, i, f, s;
|
1999-10-28 08:06:59 +00:00
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
b = cfg->bus;
|
|
|
|
s = cfg->slot;
|
|
|
|
f = cfg->func;
|
1999-10-28 08:06:59 +00:00
|
|
|
for (i = 0; i < cfg->nummaps;) {
|
2000-08-28 21:48:13 +00:00
|
|
|
i += pci_add_map(pcib, b, s, f, PCIR_MAPS + i*4, rl);
|
1999-10-28 08:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (q = &pci_quirks[0]; q->devid; q++) {
|
|
|
|
if (q->devid == ((cfg->device << 16) | cfg->vendor)
|
|
|
|
&& q->type == PCI_QUIRK_MAP_REG)
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_add_map(pcib, b, s, f, q->arg1, rl);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
1999-10-28 08:06:59 +00:00
|
|
|
|
2002-06-01 05:48:58 +00:00
|
|
|
if (cfg->intpin > 0 && PCI_INTERRUPT_VALID(cfg->intline)) {
|
2001-10-05 10:33:42 +00:00
|
|
|
#ifdef __ia64__
|
|
|
|
/*
|
|
|
|
* Re-route interrupts on ia64 so that we can get the
|
|
|
|
* I/O SAPIC interrupt numbers (the BIOS leaves legacy
|
|
|
|
* PIC interrupt numbers in the intline registers).
|
|
|
|
*/
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->intline = PCIB_ROUTE_INTERRUPT(pcib, dev, cfg->intpin);
|
2001-10-05 10:33:42 +00:00
|
|
|
#endif
|
2002-06-01 05:48:58 +00:00
|
|
|
resource_list_add(rl, SYS_RES_IRQ, 0, cfg->intline,
|
|
|
|
cfg->intline, 1);
|
2001-10-05 10:33:42 +00:00
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
void
|
|
|
|
pci_add_children(device_t dev, int busno, size_t dinfo_size)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
2000-08-28 21:48:13 +00:00
|
|
|
device_t pcib = device_get_parent(dev);
|
2002-08-26 15:23:52 +00:00
|
|
|
struct pci_devinfo *dinfo;
|
2000-08-28 21:48:13 +00:00
|
|
|
int maxslots;
|
2002-08-26 15:23:52 +00:00
|
|
|
int s, f, pcifunchigh;
|
1999-05-20 15:33:33 +00:00
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
KASSERT(dinfo_size >= sizeof(struct pci_devinfo),
|
|
|
|
("dinfo_size too small"));
|
|
|
|
maxslots = PCIB_MAXSLOTS(pcib);
|
2000-08-28 21:48:13 +00:00
|
|
|
for (s = 0; s <= maxslots; s++) {
|
2002-08-26 15:23:52 +00:00
|
|
|
pcifunchigh = 0;
|
2000-08-28 21:48:13 +00:00
|
|
|
for (f = 0; f <= pcifunchigh; f++) {
|
2002-08-26 15:23:52 +00:00
|
|
|
dinfo = pci_read_device(pcib, busno, s, f, dinfo_size);
|
1999-04-16 21:22:55 +00:00
|
|
|
if (dinfo != NULL) {
|
|
|
|
if (dinfo->cfg.mfdev)
|
2000-12-13 01:25:11 +00:00
|
|
|
pcifunchigh = PCI_FUNCMAX;
|
2002-08-26 15:23:52 +00:00
|
|
|
pci_add_child(dev, dinfo);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
void
|
|
|
|
pci_add_child(device_t bus, struct pci_devinfo *dinfo)
|
|
|
|
{
|
|
|
|
device_t pcib;
|
|
|
|
|
|
|
|
pcib = device_get_parent(bus);
|
|
|
|
dinfo->cfg.dev = device_add_child(bus, NULL, -1);
|
|
|
|
device_set_ivars(dinfo->cfg.dev, dinfo);
|
|
|
|
pci_add_resources(pcib, dinfo->cfg.dev);
|
|
|
|
pci_print_verbose(dinfo);
|
|
|
|
}
|
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
static int
|
2000-08-28 21:48:13 +00:00
|
|
|
pci_probe(device_t dev)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
|
|
|
|
1999-08-23 20:59:21 +00:00
|
|
|
device_set_desc(dev, "PCI bus");
|
2000-08-28 21:48:13 +00:00
|
|
|
|
2002-08-26 15:23:52 +00:00
|
|
|
/* Allow other subclasses to override this driver. */
|
|
|
|
return (-1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
int busno;
|
2000-08-28 21:48:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since there can be multiple independantly numbered PCI
|
|
|
|
* busses on some large alpha systems, we can't use the unit
|
|
|
|
* number to decide what bus we are probing. We ask the parent
|
|
|
|
* pcib what our bus number is.
|
|
|
|
*/
|
2000-10-09 00:43:45 +00:00
|
|
|
busno = pcib_get_bus(dev);
|
2002-08-26 15:23:52 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "physical bus=%d\n", busno);
|
|
|
|
|
|
|
|
pci_add_children(dev, busno, sizeof(struct pci_devinfo));
|
|
|
|
|
|
|
|
return (bus_generic_attach(dev));
|
|
|
|
}
|
|
|
|
|
2002-09-04 03:13:16 +00:00
|
|
|
static void
|
2002-08-26 15:23:52 +00:00
|
|
|
pci_load_vendor_data(void)
|
|
|
|
{
|
|
|
|
caddr_t vendordata, info;
|
2002-09-04 03:13:16 +00:00
|
|
|
|
|
|
|
if ((vendordata = preload_search_by_type("pci_vendor_data")) != NULL) {
|
|
|
|
info = preload_search_info(vendordata, MODINFO_ADDR);
|
|
|
|
pci_vendordata = *(char **)info;
|
|
|
|
info = preload_search_info(vendordata, MODINFO_SIZE);
|
|
|
|
pci_vendordata_size = *(size_t *)info;
|
|
|
|
/* terminate the database */
|
|
|
|
pci_vendordata[pci_vendordata_size] = '\n';
|
1999-08-23 20:59:21 +00:00
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
1999-04-16 21:22:55 +00:00
|
|
|
pci_print_child(device_t dev, device_t child)
|
|
|
|
{
|
1999-05-08 20:28:01 +00:00
|
|
|
struct pci_devinfo *dinfo;
|
2000-01-08 10:12:21 +00:00
|
|
|
struct resource_list *rl;
|
1999-05-08 20:28:01 +00:00
|
|
|
pcicfgregs *cfg;
|
1999-07-29 01:03:04 +00:00
|
|
|
int retval = 0;
|
1999-05-08 20:28:01 +00:00
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
2000-01-08 10:12:21 +00:00
|
|
|
rl = &dinfo->resources;
|
1999-07-29 01:03:04 +00:00
|
|
|
|
|
|
|
retval += bus_print_child_header(dev, child);
|
|
|
|
|
2001-12-21 21:49:57 +00:00
|
|
|
retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
|
|
|
|
retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
|
|
|
|
retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
|
2000-01-08 10:12:21 +00:00
|
|
|
if (device_get_flags(dev))
|
|
|
|
retval += printf(" flags %#x", device_get_flags(dev));
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
retval += printf(" at device %d.%d", pci_get_slot(child),
|
2002-06-01 03:41:02 +00:00
|
|
|
pci_get_function(child));
|
1999-07-29 01:03:04 +00:00
|
|
|
|
|
|
|
retval += bus_print_child_footer(dev, child);
|
|
|
|
|
|
|
|
return (retval);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 22:11:23 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
int class;
|
|
|
|
int subclass;
|
|
|
|
char *desc;
|
|
|
|
} pci_nomatch_tab[] = {
|
|
|
|
{PCIC_OLD, -1, "old"},
|
|
|
|
{PCIC_OLD, PCIS_OLD_NONVGA, "non-VGA display device"},
|
|
|
|
{PCIC_OLD, PCIS_OLD_VGA, "VGA-compatible display device"},
|
|
|
|
{PCIC_STORAGE, -1, "mass storage"},
|
|
|
|
{PCIC_STORAGE, PCIS_STORAGE_SCSI, "SCSI"},
|
|
|
|
{PCIC_STORAGE, PCIS_STORAGE_IDE, "ATA"},
|
|
|
|
{PCIC_STORAGE, PCIS_STORAGE_FLOPPY, "floppy disk"},
|
|
|
|
{PCIC_STORAGE, PCIS_STORAGE_IPI, "IPI"},
|
|
|
|
{PCIC_STORAGE, PCIS_STORAGE_RAID, "RAID"},
|
|
|
|
{PCIC_NETWORK, -1, "network"},
|
|
|
|
{PCIC_NETWORK, PCIS_NETWORK_ETHERNET, "ethernet"},
|
|
|
|
{PCIC_NETWORK, PCIS_NETWORK_TOKENRING, "token ring"},
|
|
|
|
{PCIC_NETWORK, PCIS_NETWORK_FDDI, "fddi"},
|
|
|
|
{PCIC_NETWORK, PCIS_NETWORK_ATM, "ATM"},
|
|
|
|
{PCIC_DISPLAY, -1, "display"},
|
|
|
|
{PCIC_DISPLAY, PCIS_DISPLAY_VGA, "VGA"},
|
|
|
|
{PCIC_DISPLAY, PCIS_DISPLAY_XGA, "XGA"},
|
|
|
|
{PCIC_MULTIMEDIA, -1, "multimedia"},
|
|
|
|
{PCIC_MULTIMEDIA, PCIS_MULTIMEDIA_VIDEO, "video"},
|
|
|
|
{PCIC_MULTIMEDIA, PCIS_MULTIMEDIA_AUDIO, "audio"},
|
|
|
|
{PCIC_MEMORY, -1, "memory"},
|
|
|
|
{PCIC_MEMORY, PCIS_MEMORY_RAM, "RAM"},
|
|
|
|
{PCIC_MEMORY, PCIS_MEMORY_FLASH, "flash"},
|
|
|
|
{PCIC_BRIDGE, -1, "bridge"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_HOST, "HOST-PCI"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_ISA, "PCI-ISA"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_EISA, "PCI-EISA"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_MCA, "PCI-MCA"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_PCI, "PCI-PCI"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_PCMCIA, "PCI-PCMCIA"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_NUBUS, "PCI-NuBus"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_CARDBUS, "PCI-CardBus"},
|
|
|
|
{PCIC_BRIDGE, PCIS_BRIDGE_OTHER, "PCI-unknown"},
|
|
|
|
{PCIC_SIMPLECOMM, -1, "simple comms"},
|
|
|
|
{PCIC_SIMPLECOMM, PCIS_SIMPLECOMM_UART, "UART"}, /* could detect 16550 */
|
|
|
|
{PCIC_SIMPLECOMM, PCIS_SIMPLECOMM_PAR, "parallel port"},
|
|
|
|
{PCIC_BASEPERIPH, -1, "base peripheral"},
|
|
|
|
{PCIC_BASEPERIPH, PCIS_BASEPERIPH_PIC, "interrupt controller"},
|
|
|
|
{PCIC_BASEPERIPH, PCIS_BASEPERIPH_DMA, "DMA controller"},
|
|
|
|
{PCIC_BASEPERIPH, PCIS_BASEPERIPH_TIMER, "timer"},
|
|
|
|
{PCIC_BASEPERIPH, PCIS_BASEPERIPH_RTC, "realtime clock"},
|
|
|
|
{PCIC_INPUTDEV, -1, "input device"},
|
|
|
|
{PCIC_INPUTDEV, PCIS_INPUTDEV_KEYBOARD, "keyboard"},
|
|
|
|
{PCIC_INPUTDEV, PCIS_INPUTDEV_DIGITIZER,"digitizer"},
|
|
|
|
{PCIC_INPUTDEV, PCIS_INPUTDEV_MOUSE, "mouse"},
|
|
|
|
{PCIC_DOCKING, -1, "docking station"},
|
|
|
|
{PCIC_PROCESSOR, -1, "processor"},
|
|
|
|
{PCIC_SERIALBUS, -1, "serial bus"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_FW, "FireWire"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_ACCESS, "AccessBus"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_SSA, "SSA"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_USB, "USB"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_FC, "Fibre Channel"},
|
|
|
|
{PCIC_SERIALBUS, PCIS_SERIALBUS_SMBUS, "SMBus"},
|
|
|
|
{0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
void
|
1999-07-27 04:28:14 +00:00
|
|
|
pci_probe_nomatch(device_t dev, device_t child)
|
|
|
|
{
|
2000-12-08 22:11:23 +00:00
|
|
|
int i;
|
|
|
|
char *cp, *scp, *device;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a listing for this device in a loaded device database.
|
|
|
|
*/
|
|
|
|
if ((device = pci_describe_device(child)) != NULL) {
|
2000-12-09 09:15:38 +00:00
|
|
|
device_printf(dev, "<%s>", device);
|
2000-12-08 22:11:23 +00:00
|
|
|
free(device, M_DEVBUF);
|
|
|
|
} else {
|
2002-06-01 03:41:02 +00:00
|
|
|
/*
|
|
|
|
* Scan the class/subclass descriptions for a general
|
|
|
|
* description.
|
|
|
|
*/
|
|
|
|
cp = "unknown";
|
|
|
|
scp = NULL;
|
|
|
|
for (i = 0; pci_nomatch_tab[i].desc != NULL; i++) {
|
|
|
|
if (pci_nomatch_tab[i].class == pci_get_class(child)) {
|
|
|
|
if (pci_nomatch_tab[i].subclass == -1) {
|
|
|
|
cp = pci_nomatch_tab[i].desc;
|
|
|
|
} else if (pci_nomatch_tab[i].subclass ==
|
|
|
|
pci_get_subclass(child)) {
|
|
|
|
scp = pci_nomatch_tab[i].desc;
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 22:11:23 +00:00
|
|
|
}
|
2002-06-01 03:41:02 +00:00
|
|
|
device_printf(dev, "<%s%s%s>",
|
2002-09-28 17:47:51 +00:00
|
|
|
cp ? cp : "",
|
|
|
|
((cp != NULL) && (scp != NULL)) ? ", " : "",
|
|
|
|
scp ? scp : "");
|
2000-12-08 22:11:23 +00:00
|
|
|
}
|
2001-09-01 23:06:14 +00:00
|
|
|
printf(" at device %d.%d (no driver attached)\n",
|
2002-06-01 03:41:02 +00:00
|
|
|
pci_get_slot(child), pci_get_function(child));
|
2000-12-08 22:11:23 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-11-22 03:34:43 +00:00
|
|
|
|
2000-12-08 22:11:23 +00:00
|
|
|
/*
|
|
|
|
* Parse the PCI device database, if loaded, and return a pointer to a
|
|
|
|
* description of the device.
|
|
|
|
*
|
|
|
|
* The database is flat text formatted as follows:
|
|
|
|
*
|
|
|
|
* Any line not in a valid format is ignored.
|
|
|
|
* Lines are terminated with newline '\n' characters.
|
|
|
|
*
|
|
|
|
* A VENDOR line consists of the 4 digit (hex) vendor code, a TAB, then
|
|
|
|
* the vendor name.
|
|
|
|
*
|
|
|
|
* A DEVICE line is entered immediately below the corresponding VENDOR ID.
|
|
|
|
* - devices cannot be listed without a corresponding VENDOR line.
|
|
|
|
* A DEVICE line consists of a TAB, the 4 digit (hex) device code,
|
|
|
|
* another TAB, then the device name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assuming (ptr) points to the beginning of a line in the database,
|
|
|
|
* return the vendor or device and description of the next entry.
|
|
|
|
* The value of (vendor) or (device) inappropriate for the entry type
|
|
|
|
* is set to -1. Returns nonzero at the end of the database.
|
|
|
|
*
|
|
|
|
* Note that this is slightly unrobust in the face of corrupt data;
|
|
|
|
* we attempt to safeguard against this by spamming the end of the
|
|
|
|
* database with a newline when we initialise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pci_describe_parse_line(char **ptr, int *vendor, int *device, char **desc)
|
|
|
|
{
|
|
|
|
char *cp = *ptr;
|
2000-12-09 09:15:38 +00:00
|
|
|
int left;
|
2000-12-08 22:11:23 +00:00
|
|
|
|
|
|
|
*device = -1;
|
|
|
|
*vendor = -1;
|
2000-12-09 09:15:38 +00:00
|
|
|
**desc = '\0';
|
2000-12-08 22:11:23 +00:00
|
|
|
for (;;) {
|
2000-12-09 09:15:38 +00:00
|
|
|
left = pci_vendordata_size - (cp - pci_vendordata);
|
|
|
|
if (left <= 0) {
|
|
|
|
*ptr = cp;
|
2000-12-08 22:11:23 +00:00
|
|
|
return(1);
|
2000-12-09 09:15:38 +00:00
|
|
|
}
|
2000-12-08 22:11:23 +00:00
|
|
|
|
|
|
|
/* vendor entry? */
|
2002-06-01 03:41:02 +00:00
|
|
|
if (*cp != '\t' &&
|
|
|
|
sscanf(cp, "%x\t%80[^\n]", vendor, *desc) == 2)
|
2000-12-08 22:11:23 +00:00
|
|
|
break;
|
|
|
|
/* device entry? */
|
2002-06-01 03:41:02 +00:00
|
|
|
if (*cp == '\t' &&
|
|
|
|
sscanf(cp, "%x\t%80[^\n]", device, *desc) == 2)
|
2000-12-08 22:11:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* skip to next line */
|
2000-12-09 09:15:38 +00:00
|
|
|
while (*cp != '\n' && left > 0) {
|
|
|
|
cp++;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
if (*cp == '\n') {
|
2000-12-08 22:11:23 +00:00
|
|
|
cp++;
|
2000-12-09 09:15:38 +00:00
|
|
|
left--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* skip to next line */
|
|
|
|
while (*cp != '\n' && left > 0) {
|
2000-12-08 22:11:23 +00:00
|
|
|
cp++;
|
2000-12-09 09:15:38 +00:00
|
|
|
left--;
|
2000-02-22 21:44:39 +00:00
|
|
|
}
|
2000-12-09 09:15:38 +00:00
|
|
|
if (*cp == '\n' && left > 0)
|
|
|
|
cp++;
|
2000-12-08 22:11:23 +00:00
|
|
|
*ptr = cp;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
pci_describe_device(device_t dev)
|
|
|
|
{
|
|
|
|
int vendor, device;
|
|
|
|
char *desc, *vp, *dp, *line;
|
|
|
|
|
|
|
|
desc = vp = dp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have no vendor data, we can't do anything.
|
|
|
|
*/
|
|
|
|
if (pci_vendordata == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the vendor data looking for this device
|
|
|
|
*/
|
|
|
|
line = pci_vendordata;
|
|
|
|
if ((vp = malloc(80, M_DEVBUF, M_NOWAIT)) == NULL)
|
|
|
|
goto out;
|
|
|
|
for (;;) {
|
|
|
|
if (pci_describe_parse_line(&line, &vendor, &device, &vp))
|
|
|
|
goto out;
|
|
|
|
if (vendor == pci_get_vendor(dev))
|
|
|
|
break;
|
2000-02-22 21:44:39 +00:00
|
|
|
}
|
2000-12-08 22:11:23 +00:00
|
|
|
if ((dp = malloc(80, M_DEVBUF, M_NOWAIT)) == NULL)
|
|
|
|
goto out;
|
|
|
|
for (;;) {
|
2000-12-09 09:15:38 +00:00
|
|
|
if (pci_describe_parse_line(&line, &vendor, &device, &dp)) {
|
|
|
|
*dp = 0;
|
|
|
|
break;
|
|
|
|
}
|
2000-12-08 22:11:23 +00:00
|
|
|
if (vendor != -1) {
|
|
|
|
*dp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (device == pci_get_device(dev))
|
|
|
|
break;
|
1999-07-27 04:28:14 +00:00
|
|
|
}
|
2000-12-09 09:15:38 +00:00
|
|
|
if (dp[0] == '\0')
|
|
|
|
snprintf(dp, 80, "0x%x", pci_get_device(dev));
|
2002-06-01 03:41:02 +00:00
|
|
|
if ((desc = malloc(strlen(vp) + strlen(dp) + 3, M_DEVBUF, M_NOWAIT)) !=
|
|
|
|
NULL)
|
2000-12-09 09:15:38 +00:00
|
|
|
sprintf(desc, "%s, %s", vp, dp);
|
2000-12-08 22:11:23 +00:00
|
|
|
out:
|
|
|
|
if (vp != NULL)
|
|
|
|
free(vp, M_DEVBUF);
|
|
|
|
if (dp != NULL)
|
|
|
|
free(dp, M_DEVBUF);
|
|
|
|
return(desc);
|
1999-07-27 04:28:14 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
2000-04-30 10:01:56 +00:00
|
|
|
pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
switch (which) {
|
2002-11-27 06:41:28 +00:00
|
|
|
case PCI_IVAR_ETHADDR:
|
|
|
|
/*
|
|
|
|
* The generic accessor doesn't deal with failure, so
|
|
|
|
* we set the return value, then return an error.
|
|
|
|
*/
|
|
|
|
*((u_int8_t **) result) = NULL;
|
|
|
|
return (EINVAL);
|
1999-04-16 21:22:55 +00:00
|
|
|
case PCI_IVAR_SUBVENDOR:
|
|
|
|
*result = cfg->subvendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SUBDEVICE:
|
|
|
|
*result = cfg->subdevice;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_VENDOR:
|
|
|
|
*result = cfg->vendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_DEVICE:
|
|
|
|
*result = cfg->device;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_DEVID:
|
|
|
|
*result = (cfg->device << 16) | cfg->vendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_CLASS:
|
|
|
|
*result = cfg->baseclass;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SUBCLASS:
|
|
|
|
*result = cfg->subclass;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_PROGIF:
|
|
|
|
*result = cfg->progif;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_REVID:
|
|
|
|
*result = cfg->revid;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_INTPIN:
|
|
|
|
*result = cfg->intpin;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_IRQ:
|
|
|
|
*result = cfg->intline;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_BUS:
|
|
|
|
*result = cfg->bus;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SLOT:
|
|
|
|
*result = cfg->slot;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_FUNCTION:
|
|
|
|
*result = cfg->func;
|
|
|
|
break;
|
|
|
|
default:
|
2002-06-01 05:44:45 +00:00
|
|
|
return (ENOENT);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
2002-06-01 05:44:45 +00:00
|
|
|
return (0);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
int
|
1999-04-16 21:22:55 +00:00
|
|
|
pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
switch (which) {
|
2002-11-27 06:41:28 +00:00
|
|
|
case PCI_IVAR_ETHADDR:
|
1999-04-16 21:22:55 +00:00
|
|
|
case PCI_IVAR_SUBVENDOR:
|
|
|
|
case PCI_IVAR_SUBDEVICE:
|
|
|
|
case PCI_IVAR_VENDOR:
|
|
|
|
case PCI_IVAR_DEVICE:
|
|
|
|
case PCI_IVAR_DEVID:
|
|
|
|
case PCI_IVAR_CLASS:
|
|
|
|
case PCI_IVAR_SUBCLASS:
|
|
|
|
case PCI_IVAR_PROGIF:
|
|
|
|
case PCI_IVAR_REVID:
|
|
|
|
case PCI_IVAR_INTPIN:
|
|
|
|
case PCI_IVAR_IRQ:
|
|
|
|
case PCI_IVAR_BUS:
|
|
|
|
case PCI_IVAR_SLOT:
|
|
|
|
case PCI_IVAR_FUNCTION:
|
2002-06-01 05:44:45 +00:00
|
|
|
return (EINVAL); /* disallow for now */
|
1999-04-16 21:22:55 +00:00
|
|
|
|
|
|
|
default:
|
2002-06-01 05:44:45 +00:00
|
|
|
return (ENOENT);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
2002-06-01 05:44:45 +00:00
|
|
|
return (0);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-08-28 10:02:59 +00:00
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
#ifdef DDB
|
|
|
|
#include <ddb/ddb.h>
|
|
|
|
#include <sys/cons.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List resources based on pci map registers, used for within ddb
|
|
|
|
*/
|
|
|
|
|
|
|
|
DB_SHOW_COMMAND(pciregs, db_pci_dump)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
struct devlist *devlist_head;
|
|
|
|
struct pci_conf *p;
|
|
|
|
const char *name;
|
|
|
|
int i, error, none_count, nl;
|
|
|
|
|
|
|
|
none_count = 0;
|
|
|
|
nl = 0;
|
|
|
|
/* get the head of the device queue */
|
|
|
|
devlist_head = &pci_devq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through the list of devices and print out devices
|
|
|
|
*/
|
|
|
|
for (error = 0, i = 0,
|
|
|
|
dinfo = STAILQ_FIRST(devlist_head);
|
|
|
|
(dinfo != NULL) && (error == 0) && (i < pci_numdevs);
|
|
|
|
dinfo = STAILQ_NEXT(dinfo, pci_links), i++) {
|
|
|
|
|
|
|
|
/* Populate pd_name and pd_unit */
|
|
|
|
name = NULL;
|
|
|
|
if (dinfo->cfg.dev)
|
|
|
|
name = device_get_name(dinfo->cfg.dev);
|
|
|
|
|
|
|
|
p = &dinfo->conf;
|
|
|
|
/*
|
|
|
|
* XXX just take 20 for now...
|
|
|
|
*/
|
|
|
|
if (nl++ == 20) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
db_printf("--More--");
|
|
|
|
c = cngetc();
|
|
|
|
db_printf("\r");
|
|
|
|
/*
|
|
|
|
* A whole screenfull or just one line?
|
|
|
|
*/
|
|
|
|
switch (c) {
|
|
|
|
case '\n': /* just one line */
|
|
|
|
nl = 20;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
nl = 0; /* another screenfull */
|
|
|
|
break;
|
|
|
|
default: /* exit */
|
|
|
|
db_printf("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
db_printf("%s%d@pci%d:%d:%d:\tclass=0x%06x card=0x%08x "
|
|
|
|
"chip=0x%08x rev=0x%02x hdr=0x%02x\n",
|
|
|
|
(name && *name) ? name : "none",
|
|
|
|
(name && *name) ? (int)device_get_unit(dinfo->cfg.dev) :
|
|
|
|
none_count++,
|
|
|
|
p->pc_sel.pc_bus, p->pc_sel.pc_dev,
|
|
|
|
p->pc_sel.pc_func, (p->pc_class << 16) |
|
|
|
|
(p->pc_subclass << 8) | p->pc_progif,
|
|
|
|
(p->pc_subdevice << 16) | p->pc_subvendor,
|
|
|
|
(p->pc_device << 16) | p->pc_vendor,
|
|
|
|
p->pc_revid, p->pc_hdr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DDB */
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
struct resource *
|
1999-10-14 21:38:33 +00:00
|
|
|
pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
1999-10-14 21:38:33 +00:00
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
2000-10-16 07:24:00 +00:00
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform lazy resource allocation
|
|
|
|
*
|
|
|
|
* XXX add support here for SYS_RES_IOPORT and SYS_RES_MEMORY
|
|
|
|
*/
|
|
|
|
if (device_get_parent(child) == dev) {
|
2003-04-15 19:38:18 +00:00
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
/*
|
|
|
|
* If the child device doesn't have an
|
|
|
|
* interrupt routed and is deserving of an
|
|
|
|
* interrupt, try to assign it one.
|
|
|
|
*/
|
|
|
|
if (!PCI_INTERRUPT_VALID(cfg->intline) &&
|
|
|
|
(cfg->intpin != 0)) {
|
|
|
|
cfg->intline = PCIB_ROUTE_INTERRUPT(
|
|
|
|
device_get_parent(dev), child, cfg->intpin);
|
|
|
|
if (PCI_INTERRUPT_VALID(cfg->intline)) {
|
|
|
|
pci_write_config(child, PCIR_INTLINE,
|
|
|
|
cfg->intline, 1);
|
|
|
|
resource_list_add(rl, SYS_RES_IRQ, 0,
|
|
|
|
cfg->intline, cfg->intline, 1);
|
|
|
|
}
|
2000-10-16 07:24:00 +00:00
|
|
|
}
|
2003-04-15 19:38:18 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
/*
|
|
|
|
* Enable the I/O mode. We should also be allocating
|
|
|
|
* resources too. XXX
|
|
|
|
*/
|
2003-04-16 03:15:08 +00:00
|
|
|
if (PCI_ENABLE_IO(dev, child, type))
|
|
|
|
return (NULL);
|
2003-04-15 19:38:18 +00:00
|
|
|
break;
|
2000-10-16 07:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2002-06-01 05:44:45 +00:00
|
|
|
return (resource_list_alloc(rl, dev, child, type, rid,
|
|
|
|
start, end, count, flags));
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
void
|
2000-11-28 07:12:12 +00:00
|
|
|
pci_delete_resource(device_t dev, device_t child, int type, int rid)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
2002-02-27 05:09:14 +00:00
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
struct resource_list *rl;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
if (device_get_parent(child) != dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
rl = &dinfo->resources;
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (rle) {
|
|
|
|
if (rle->res) {
|
2003-02-16 02:02:44 +00:00
|
|
|
if (rman_get_device(rle->res) != dev ||
|
2002-02-27 05:09:14 +00:00
|
|
|
rman_get_flags(rle->res) & RF_ACTIVE) {
|
|
|
|
device_printf(dev, "delete_resource: "
|
|
|
|
"Resource still owned by child, oops. "
|
|
|
|
"(type=%d, rid=%d, addr=%lx)\n",
|
|
|
|
rle->type, rle->rid,
|
|
|
|
rman_get_start(rle->res));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bus_release_resource(dev, type, rid, rle->res);
|
|
|
|
}
|
|
|
|
resource_list_delete(rl, type, rid);
|
|
|
|
}
|
2002-06-01 05:44:45 +00:00
|
|
|
/*
|
|
|
|
* Why do we turn off the PCI configuration BAR when we delete a
|
|
|
|
* resource? -- imp
|
|
|
|
*/
|
2002-02-27 05:09:14 +00:00
|
|
|
pci_write_config(child, rid, 0, 4);
|
|
|
|
BUS_DELETE_RESOURCE(device_get_parent(dev), child, type, rid);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
struct resource_list *
|
2000-11-28 07:12:12 +00:00
|
|
|
pci_get_resource_list (device_t dev, device_t child)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
2000-11-28 07:12:12 +00:00
|
|
|
struct pci_devinfo * dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list * rl = &dinfo->resources;
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2000-11-28 07:12:12 +00:00
|
|
|
if (!rl)
|
|
|
|
return (NULL);
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2000-11-28 07:12:12 +00:00
|
|
|
return (rl);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
u_int32_t
|
1999-04-16 21:22:55 +00:00
|
|
|
pci_read_config_method(device_t dev, device_t child, int reg, int width)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
2000-08-28 21:48:13 +00:00
|
|
|
|
2002-06-01 05:44:45 +00:00
|
|
|
return (PCIB_READ_CONFIG(device_get_parent(dev),
|
|
|
|
cfg->bus, cfg->slot, cfg->func, reg, width));
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
void
|
2002-06-01 05:44:45 +00:00
|
|
|
pci_write_config_method(device_t dev, device_t child, int reg,
|
|
|
|
u_int32_t val, int width)
|
1999-04-16 21:22:55 +00:00
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
2000-08-28 21:48:13 +00:00
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(device_get_parent(dev),
|
2002-06-01 03:41:02 +00:00
|
|
|
cfg->bus, cfg->slot, cfg->func, reg, val, width);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2003-02-17 21:20:35 +00:00
|
|
|
int
|
|
|
|
pci_child_location_str_method(device_t cbdev, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
snprintf(buf, buflen, "slot=%d function=%d", pci_get_slot(child),
|
|
|
|
pci_get_function(child));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pci_child_pnpinfo_str_method(device_t cbdev, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
snprintf(buf, buflen, "vendor=0x%04x device=0x%04x subvendor=0x%04x "
|
2003-02-18 03:25:57 +00:00
|
|
|
"subdevice=0x%04x class=0x%02x%02x%02x", cfg->vendor, cfg->device,
|
|
|
|
cfg->subvendor, cfg->subdevice, cfg->baseclass, cfg->subclass,
|
|
|
|
cfg->progif);
|
2003-02-17 21:20:35 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
static int
|
|
|
|
pci_modevent(module_t mod, int what, void *arg)
|
|
|
|
{
|
2002-09-04 03:13:16 +00:00
|
|
|
static dev_t pci_cdev;
|
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
switch (what) {
|
|
|
|
case MOD_LOAD:
|
1999-05-09 15:54:04 +00:00
|
|
|
STAILQ_INIT(&pci_devq);
|
2000-12-13 01:25:11 +00:00
|
|
|
pci_generation = 0;
|
2002-09-04 03:13:16 +00:00
|
|
|
pci_cdev = make_dev(&pcicdev, 0, UID_ROOT, GID_WHEEL, 0644,
|
|
|
|
"pci");
|
|
|
|
pci_load_vendor_data();
|
1999-04-16 21:22:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
2002-09-04 03:13:16 +00:00
|
|
|
destroy_dev(pci_cdev);
|
1999-04-16 21:22:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-01 05:44:45 +00:00
|
|
|
return (0);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|