History log of /freebsd-current/sys/dev/pci/pci.c
Revision Date Author Comments
# 56b822a1 05-Jun-2024 John Baldwin <jhb@FreeBSD.org>

pci: Only add special VF handling for direct children in bus methods

For activate/deactivate resource, use a more standard check at the
start of the function since the addition of the PCI_IOV code made this
more complex. For the three recently added methods, just add the
typical check at the beginning that I missed.

This wasn't always fatal as if your system only had PCI device_t's as
children of PCI bus devices it would happen to work ok, but if you
have a non-PCI child device (e.g. an ATA channel) then dereferencing
ivars for non-direct-children could fault.

Reported by: Cirrus-CI (via emaste)
Reviewed by: emaste
Fixes: 871b33ad65ba pci: Consistently use pci_vf_* for suballocated VF memory resources
Differential Revision: https://reviews.freebsd.org/D45499


# 871b33ad 04-Jun-2024 John Baldwin <jhb@FreeBSD.org>

pci: Consistently use pci_vf_* for suballocated VF memory resources

Some of the bus resource methods were passing these up to the parent
which triggered rman mismatch assertions in INVARIANTS kernels.

Reported by: kp
Reviewed by: imp
Tested by: kp (earlier version)
Differential Revision: https://reviews.freebsd.org/D45406


# 0f1d148c 01-Jun-2024 John Baldwin <jhb@FreeBSD.org>

pci: Use kobj typedefs for new-bus method prototypes

Reviewed by: kp, imp
Differential Revision: https://reviews.freebsd.org/D45405


# 9dbf5b0e 13-Mar-2024 John Baldwin <jhb@FreeBSD.org>

new-bus: Remove the 'rid' and 'type' arguments from BUS_RELEASE_RESOURCE

The public bus_release_resource() API still accepts both forms, but
the internal kobj method no longer passes the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D44131


# 2baed46e 13-Mar-2024 John Baldwin <jhb@FreeBSD.org>

new-bus: Remove the 'rid' and 'type' arguments from BUS_*ACTIVATE_RESOURCE

The public bus_activate/deactivate_resource() API still accepts both
forms, but the internal kobj methods no longer pass the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D44130


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 43e545e8 14-Aug-2023 Ed Maste <emaste@FreeBSD.org>

pci: return 0 for pci_remap_intr_method MSI-X non-error case

When remapping a MSI-X vector, we would always return ENOENT, even if
successful. This didn't really matter, as the sole caller of
BUS_REMAP_INTR also didn't check for errors.

Return 0 if there's no error, so that we can start handling (or at least
warning about) actual failures.

Reviewed by: jhb
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41449


# 586164cc 21-Jun-2023 Stefan Eßer <se@FreeBSD.org>

dev/pci: simplify PCI VPD access functions

This update contains a rewrite of the VPD parser based on the
definition of the structure of the VPD data (ident, R/O resource
data, optional R/W data, end tag).

The parser it replaces was based on a state machine, with the tags
and the parsed data controlling the state changes. The flexibility
of this parser is actually not required, and it has caused kernel
panics when operating on malformed data.

Analysis of the VPD code to make it more robust lead me to believe
that it was easier to write a "strict" parser than to restrict the
flexible state machine to detect and reject non-well-formed data.
A number of restrictions had already been added, but they make the
state machine ever more complex and harder to understand.

This updated parser has been verified to return identical parsed data
as the current implementation for the example VPD data given in the
PCI standard and in some actual PCIe VPD data.

It is strict in the sense that it detects and rejects any deviation
from a well-formed VPD structure.

PR: 272018
Approved by: kib
MFC after: 4 weeks
Differential Revision: https://reviews.freebsd.org/D34268


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 48d70503 06-Feb-2023 Corvin Köhne <corvink@FreeBSD.org>

pci: add tunable hw.pci.enable_mps_tune

If the tunable is set to 0, the tuning of the MPS (maximum payload size)
is disabled and the default MPS values set by the BIOS are used. In this
case the system may use a lower speed or operate in a less optimized
state, but it can resolve issues with stability and compatibility. With
specific devices the tuning of the mps, can lead to a complete freeze of
the system.

Reviewed by: manu
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D38397


# 6b497700 03-Sep-2022 Gordon Bergling <gbe@FreeBSD.org>

pci(4): Fix a typo in asource code comment

- s/overriden/overridden/

MFC after: 3 days


# 16bedf53 19-Aug-2022 John Baldwin <jhb@FreeBSD.org>

pci: Add helper routines to iterate over a device's BARs.

Reviewed by: imp, markj, emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36237


# c84c5e00 18-Jul-2022 Mitchell Horne <mhorne@FreeBSD.org>

ddb: annotate some commands with DB_CMD_MEMSAFE

This is not completely exhaustive, but covers a large majority of
commands in the tree.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35583


# 00c00c38 03-Jul-2022 Gordon Bergling <gbe@FreeBSD.org>

pci(4): Fix a common typo in source code comments

- s/transistions/transitions/

MFC after: 3 days


# 97a41013 06-May-2022 John Baldwin <jhb@FreeBSD.org>

pci: Remove unused devclass arguments to DRIVER_MODULE.


# f010b9c2 22-Apr-2022 John F. Carr <jfc@mit.edu>

pci: recognize "non-essential instrumentation" devices

Some AMD EPYC VCPUs generated boot message of the type:

pci4: <unknown> at device 0.0 (no driver attached)

These are displayed for device class 0x13 devices, e.g.:

none8@pci0:130:0:0: class=0x130000 rev=0x00 hdr=0x00 vendor=0x1022 \
device=0x148a subvendor=0x1022 subdevice=0x148a
vendor = 'Advanced Micro Devices, Inc. [AMD]'
device = 'Starship/Matisse PCIe Dummy Function'
class = non-essential instrumentation

Since these devices serve no purpose (no driver attaches) I have
enabled the reporting of suich devices only for verbose boots (a
diversion from the patch provided in the PR).

A verbose boot will now display such devices as:

pci4: <non-essential instrumentation> at device 0.0 (no driver attached)

PR: 263469
Reported by: jfc@mit.edu (John F. Carr)
MFC after: 1 week


# 09b966ee 04-Apr-2022 Warner Losh <imp@FreeBSD.org>

Mark cfg as __unused to avoid ifdef soup

Sponsored by: Netflix


# 25670e46 28-Feb-2022 Warner Losh <imp@FreeBSD.org>

pci: Add arbitrary locator support to pci.

If the pciX:Y:Z and pciW:X:Y:Z 'at' locations don't work, allow try the
LOCATOR:PATH syntax. Use dev_wired_cache to generically look them up.

Sponsored by: Netflix
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D32784


# b029685a 28-Feb-2022 Warner Losh <imp@FreeBSD.org>

pci: switch logic a little

If we find a match, then assign it. Flip the logic in the if and assign
the unit rather than continuing if it doesn't match. Will make it easier
to expand to other matching schemes.

Sponsored by: Netflix
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D32779


# d0a20e40 28-Feb-2022 Warner Losh <imp@FreeBSD.org>

Add UEFI locator for bus_get_device_path, pci acpi

Add a UEFI locator type. It prints the UEFI device names for a FreeBSD
device_t name. It works with PCI and ACPI device nodes. USB forthcoming.

Sponsored by: Netflix
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D32749


# f01c8633 20-Feb-2022 Stefan Eßer <se@FreeBSD.org>

dev/pci: fix potential panic due to bogus VPD data

A panic has been observed on a system with a Intel X520 dual LAN
device. The panic is caused by a KASSERT() noticing that the amount
of VPD data copied out to the pciconf command does not match the
amount of data read from the device.

The cause of the size mismatch was VPD data that started with 0x82,
the VPD tag that indicates that a VPD ident follows, but with a length
of more than 255 characters, which happens to be the maximum ident
size supported by the API between kernel and the pciconf program.
The data provided did not resemble an actual VPD identifier, and it
can be assumed that the initial tag value 0x82 happens to be there
by accident.

An ident size of 255 far exceeds the sensible length of that data
element, which is in the order of at most 30 to 40 bytes.

This patch adds several consitstency checks to the VPD parser, the
most critical being that ident lengths of more than 255 bytes are
rejected. Other checks reject VPD with more than one ident tag or
with an empty (zero length) ident string.

This patch prevents the panic that occured when "pciconf -lV" was
executed on the affected system.

During the anaylsis of the issue and the VPD code it has been
found that the VPD parser uses a state machine that accepts tags
in any order and combination. This is a bad match for the actual
VPD data, which has a very simple structure that can be parsed
with a non-recursive direct descent parser (which always knows
exactly which token to expect next).

A review fpr a much simpler VPD parser that performs many more
consistency checks and rejects invalid VPD has been proposed in
review https://reviews.freebsd.org/D34268.

Reported by: mikej at paymentallianceintl.com (Michael Jung)
Approved by: jhb
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D34255


# 68cbe189 23-Nov-2021 Kornel Duleba <mindal@semihalf.com>

pci: Don't try to read cfg registers of non-existing devices

Instead of returning 0xffs some controllers, such as Layerscape generate
an external exception when someone attempts to read any register
of config space of a non-existing device other than PCIR_VENDOR.
This causes a kernel panic.
Fix it by bailing during device enumeration if a device vendor register
returns invalid value. (0xffff)
Use this opportunity to replace some hardcoded values with a macro.

I believe that this change won't have any unintended side-effects since
it is safe to assume that vendor == 0xffff -> hdr_type == 0xffff.

Sponsored by: Alstom
Obtained from: Semihalf
Reviewed by: jhb
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D33059


# 1f960e64 09-Nov-2021 Mark Johnston <markj@FreeBSD.org>

pci: Implement pci_bar_enabled() for SR-IOV VFs

In a VF's configuration space, "memory space enable" is hard-wired to 0,
so the existing implementation always returns false. We need to read
the SR-IOV control register from the PF device to get the value of the
MSE bit.

Fix pci_bar_enabled() to read this register instead for VFs. I don't
see any way to access the PF's config space without a backpointer in the
pci device ivars, so I added one.

This fixes a regression where bhyve(8) fails to map the MSI-X table
after commit 7fa233534736 ("bhyve: Map the MSI-X table unconditionally
for passthrough") when a VF is passed through, since with that commit we
use PCIOCBARMMAP to map the table and that ioctl always fails for VFs
without this change. As a bonus, pciconf(8) now correctly reports the
enablement of BARs for VFs.

Reported and tested by: Raúl Muñoz <raul.munoz@custos.es>
Reviewed by: rstone, jhb
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32839


# 82098c8b 17-Oct-2021 Jessica Clarke <jrtc27@FreeBSD.org>

LinuxKPI: Support lazy BAR allocation

Linux KPIs like pci_resource_start/len assume that BARs have been
allocated, but FreeBSD lazily allocates BARs if it cannot allocate the
firmware-allocated BARs. Thus using the Linux KPIs must force allocation
of the BARs rather than returning 0 for the start and length, which can
crash drm-kmod drivers that assume the BARs are valid. This is needed
for the AMDGPU driver to be able to attach on SiFive's HiFive Unmatched.

Reviewed by: hselasky, jhb, mav
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D32447


# ddfc9c4c 22-Jun-2021 Warner Losh <imp@FreeBSD.org>

newbus: Move from bus_child_{pnpinfo,location}_src to bus_child_{pnpinfo,location} with sbuf

Now that the upper layers all go through a layer to tie into these
information functions that translates an sbuf into char * and len. The
current interface suffers issues of what to do in cases of truncation,
etc. Instead, migrate all these functions to using struct sbuf and these
issues go away. The caller is also in charge of any memory allocation
and/or expansion that's needed during this process.

Create a bus_generic_child_{pnpinfo,location} and make it default. It
just returns success. This is for those busses that have no information
for these items. Migrate the now-empty routines to using this as
appropriate.

Document these new interfaces with man pages, and oversight from before.

Reviewed by: jhb, bcr
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D29937


# 5a898b2b 05-Apr-2021 Alexander Motin <mav@FreeBSD.org>

Set PCIe device's Max_Payload_Size to match PCIe root's.

Usually on boot the MPS is already configured by BIOS. But we've
found that on hot-plug it is not true at least for our Supermicro
X11 boards. As result, mismatch between root's configuration of
256 bytes and device's default of 128 bytes cause problems for some
devices, while others seem to work fine.

MFC after: 1 month
Sponsored by: iXsystems, Inc.


# a9f0367b 23-Mar-2021 Bjoern A. Zeeb <bz@FreeBSD.org>

pci: enhance printf for leaked MSI[-X] vectors

When debugging leaked MSI/MSI-X vectors through LinuxKPI I found
the informational printf unhelpful. Rather than just stating we
leaked also tell how many MSI or MSI-X vectors we leak.

Sponsored-by: The FreeBSD Foundation
Reviewed-by: jhb
MFC-after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D29394


# 1acf24a0 16-Mar-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

Implement pci_get_relaxed_ordering_enabled() helper function.

Discussed with: kib@
MFC after: 1 week
Sponsored by: Mellanox Technologies // NVIDIA Networking


# 8517a547 10-Dec-2020 Emmanuel Vadot <manu@FreeBSD.org>

pci: Add pci_find_class_from

pci_find_class_from help finding one or multiple device matching
a class and subclass.
If the from argument is not null we will first loop in the device list
until we find the matching device and only then start to check if the
class/subclass matches.

Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D27549


# 6186bfbd 29-Sep-2020 Ruslan Bukin <br@FreeBSD.org>

Rename kernel option ACPI_DMAR to IOMMU.
This is mostly needed for a common arm64/amd64 iommu code.

Reviewed by: kib
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D26587


# 025730aa 29-Sep-2020 Ruslan Bukin <br@FreeBSD.org>

o Rename acpi_iommu_get_dma_tag() -> iommu_get_dma_tag().
This function isn't ACPI dependent and we may use it on FDT systems
as well.
o Don't repeat the function declaration, include iommu.h instead.

Reviewed by: andrew, kib
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D26584


# 04e8183f 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

pci: clean up empty lines in .c and .h files


# c34e4b5c 07-Aug-2020 Alexander Motin <mav@FreeBSD.org>

Enable hw.pci.enable_aspm tunable by default.

While effects on power saving is only a guess, effects on hot-plug are
clearly visible. Lets try to enable it and see what happen.

MFC after: 3 months


# 855e49f3 27-Jul-2020 Alexander Motin <mav@FreeBSD.org>

Add initial driver for ACPI Platform Error Interfaces.

APEI allows platform to report different kinds of errors to OS in several
ways. We've found that Supermicro X10/X11 motherboards report PCIe errors
appearing on hot-unplug via this interface using NMI. Without respective
driver it ended up in kernel panic without any additional information.

This driver introduces support for the APEI Generic Hardware Error Source
reporting via NMI, SCI or polling. It decodes the reported errors and
either pass them to pci(4) for processing or just logs otherwise. Errors
marked as fatal still end up in kernel panic, but some more informative.

When somebody get to native PCIe AER support implementation both of the
reporting mechanisms should get common error recovery code. Since in our
case errors happen when the device is already gone, there is nothing to
recover, so the code just clears the error statuses, practically ignoring
the otherwise destructive NMIs in nicer way.

MFC after: 2 weeks
Relnotes: yes
Sponsored by: iXsystems, Inc.


# 4cee4598 26-Jun-2020 Alexander Motin <mav@FreeBSD.org>

Add mostly dummy hw.pci.enable_aspm tunable.

The only thing this tunable enables now is reporting to ACPI _OSC that
Active State Power Management and Clock Power Management Capability are
"supported" by the OS.

I've found that at least some Supermicro server boards do not allow OS
to support native PCIe hot-plug unless it reports those capabilities.
After spending significant time in PCIe specs I have found very little
motivation for that, and none of it applies to those motherboards, not
enabling ASPM themselves. So unless OS explicitly wants to save power,
I see nothing for it to do there actually.

I guess it may get sense to support ASPM when we get Thunderbolt support.
Otherwise I have no system with PCIe hot-plug where power saving matters.

It would be nice to enable this by default, but I worry that it affect
power saving of some laptops, even though I haven't noticed that myself.


# cffd37da 29-May-2020 Andriy Gapon <avg@FreeBSD.org>

do not enable pci bridge decoding on resume until I/O windows are restored

PCI bus driver restores most but not all of a child PCI-PCI bridge
configuration. The bridge's I/O windows are restored by pcib driver and
that happens later in time. This can be problematic because the Command
register is restored before the windows are restored. If the firmware
programs the windows incorrectly or even does not program them at all,
then the bridge can start claiming I/O cycles that are not intended for
it. This will continue until the correct windows are restored.

I have observed this problem with a buggy BIOS where after resuming from
S3 an I/O port window of a PCI-PCI bridge was configured with zero base
and limit causing the bridge to claim 0x0 - 0xFFF port range. That
interfered with ACPI port access including ACPI PM Timer at port 0x808,
thus wreaking havoc in the time keeping.

The solution is to restore the Command register of PCI-PCI bridges after
the windows are restored in pcib driver. While here, I decided that for
other PCI device types (normal and cardbus) it's better to restore the
Command register after their BARs are restored.

To do: per jhb's suggestion, move the window handling to pci driver.

Reviewed by: imp, jhb, kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D25028


# 43843cc2 26-May-2020 Ruslan Bukin <br@FreeBSD.org>

Rename dmar_get_dma_tag() to acpi_iommu_get_dma_tag().
This is needed for a new IOMMU controller support.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D24943


# a8f48cf8 17-Mar-2020 Navdeep Parhar <np@FreeBSD.org>

Remove spurious warning about invalid VPD data.

The warning used to be displayed for valid VPDs about 512B or above in
size. Fix the size check and add a break while here so that the routine
stops if if detects any problem.

Tested with "pciconf -lV"

Reviewed by: kib@, jhb@
MFC after: 1 week
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D23679


# 59e4be22 16-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (5 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked). Use it in
preparation for a general review of all nodes.
This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Reviewed by: imp, kib
Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D23633


# 484651cd 18-Dec-2019 Mark Peek <mp@FreeBSD.org>

Remove VMware MSI-X from the PCI blacklist.

First reported against ESXi 5.0, PCI passthrough was not working due to
MSI-X issues. However, this issue was fixed via patch releases against
ESXi 5.5 and 6.0 in 2016. Given ESXi 5.5 and earlier have been EOL, this
patch removes the VMware MSI-X blacklist entries in the quirk table.

PR: 203874
Reviewed by: imp, jhb
MFC after: 1 month
Sponsored by: VMware
Differential Revision: https://reviews.freebsd.org/D22819


# 96b506a5 24-Nov-2019 Warner Losh <imp@FreeBSD.org>

Hoist locking giant back up into the ioctl handler

Move the locking back into the ioctl handler. This "fixes" the race where we hve
a hot plug event just after the dropping of Giant in pci_find_dbsf, assuming the
driver doesn't then call anything that drops and picks up Giant again... It's a
little safer since don't think it doesn't, but we lack the tools to know for
sure.


# dd615d09 23-Nov-2019 Warner Losh <imp@FreeBSD.org>

Push Giant down one layer

The /dev/pci device doesn't need GIANT, per se. However, one routine
that it calls, pci_find_dbsf implicitly does. It walks a list that can
change when PCI scans a new bus. With hotplug, this means we could
have a race with that scanning. To prevent that, take out Giant around
scanning the list.

However, given that we have places in the tree that drop giant, if
held when we call into them, the whole use of Giant to protect newbus
may be less effective that we desire, so add a comment about why we're
talking it out, and we'll address the issue when we lock newbus with
something other than Giant.


# 21d31962 15-Oct-2019 John Baldwin <jhb@FreeBSD.org>

Export pci_attach() and pci_detach().

Reviewed by: imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D21948


# e64f3dee 08-Jul-2019 Warner Losh <imp@FreeBSD.org>

Work around devices which return all zeros for reads of existing MSI-X
table VCTRL registers.

Unconditionally program the MSI-X vector control Mask field for MSI-X
table entries without regarud for Mask's previous value. Some devices
return all zeros on reads of the VCTRL registers, which would cause us
to skip disabling interrupts. This fixes the Samsung SM961/PM961 SSDs
which are return zero starting from offset 0x3084 within the memory
region specified by BAR0, even when they are active MSI-X vectors.

The Illumos kernel writes these unconditionally to 0 or 1. However,
section 6.8.2.9 of the PCI Local Bus 3.0 spec (dated Feb 3, 2004)
states for bits 31::01:
After reset, the state of these bits must be 0. However, for
potential future use, software must preserve the value of
these reserved bits when modifying the value of other Vector
Control bits. If software modifies the value of these reserved
bits, the result is undefined."
so we always set or clear the Mask bit, but otherwise preserves the
old value.

PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=211713
Reviewed By: imp, jhb
Submitted by: Ka Ho Ng
MFC After: 1 week
Differential Revision: https://reviews.freebsd.org/D20873


# e2e050c8 19-May-2019 Conrad Meyer <cem@FreeBSD.org>

Extract eventfilter declarations to sys/_eventfilter.h

This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.


# 96ca24dc 19-Apr-2019 Tycho Nightingale <tychon@FreeBSD.org>

remove the 4GB boundary requirement on PCI DMA segments

Reviewed by: kib
Discussed with: jhb
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D19867


# ca19084f 07-Apr-2019 Konstantin Belousov <kib@FreeBSD.org>

Give new home to the comment from ppt_pci_reset(), explaining a nuance
of power reset.

Noted by: soralx@cydem.org
Sponsored by: Mellanox Technologies
MFC after: 12 days


# 5db2a4a8 05-Apr-2019 Konstantin Belousov <kib@FreeBSD.org>

Implement resets for PCI buses and PCIe bridges.

For PCI device (i.e. child of a PCI bus), reset tries FLR if
implemented and worked, and falls to power reset otherwise.

For PCIe bus (child of a PCIe bridge or root port), reset
disables PCIe link and then re-trains it, performing what is known as
link-level reset.

Reviewed by: imp (previous version), jhb (previous version)
Sponsored by: Mellanox Technologies
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D19646


# b2bbb744 01-Apr-2019 Tycho Nightingale <tychon@FreeBSD.org>

Devices behind downstream bridges should still get DMAR protection.

Reviewed by: kib
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D19717


# 967b2dce 11-Feb-2019 John Baldwin <jhb@FreeBSD.org>

Enable PCI BAR reallocation by default.

When pci_realloc_bars was first added, the intention was to eventually
enable it by default, but it was left disabled to preserve existing
behavior. The setting is pretty conservative in that it does not
attempt to allocate resources for BARs that the BIOS/firmware leaves
disabled. It only attempts to reallocate resources for a BAR that the
firmware programmed during boot but that conflicts with another
resource during the kernel's device scan.

PR 221350 is an example of a machine that this knob fixes.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D18965


# 82a5a275 17-Dec-2018 Andriy Gapon <avg@FreeBSD.org>

add support for marking interrupt handlers as suspended

The goal of this change is to fix a problem with PCI shared interrupts
during suspend and resume.

I have observed a couple of variations of the following scenario.
Devices A and B are on the same PCI bus and share the same interrupt.
Device A's driver is suspended first and the device is powered down.
Device B generates an interrupt. Interrupt handlers of both drivers are
called. Device A's interrupt handler accesses registers of the powered
down device and gets back bogus values (I assume all 0xff). That data is
interpreted as interrupt status bits, etc. So, the interrupt handler
gets confused and may produce some noise or enter an infinite loop, etc.

This change affects only PCI devices. The pci(4) bus driver marks a
child's interrupt handler as suspended after the child's suspend method
is called and before the device is powered down. This is done only for
traditional PCI interrupts, because only they can be shared.

At the moment the change is only for x86.

Notable changes in core subsystems / interfaces:
- BUS_SUSPEND_INTR and BUS_RESUME_INTR methods are added to bus
interface along with convenience functions bus_suspend_intr and
bus_resume_intr;
- rman_set_irq_cookie and rman_get_irq_cookie functions are added to
provide a way to associate an interrupt resource with an interrupt
cookie;
- intr_event_suspend_handler and intr_event_resume_handler functions
are added to the MI interrupt handler interface.

I added two new interrupt handler flags, IH_SUSP and IH_CHANGED, to
implement the new intr_event functions. IH_SUSP marks a suspended
interrupt handler. IH_CHANGED is used to implement a barrier that
ensures that a change to the interrupt handler's state is visible
to future interrupts.
While there, I fixed some whitespace issues in comments and changed a
couple of logically boolean variables to be bool.

MFC after: 1 month (maybe)
Differential Revision: https://reviews.freebsd.org/D15755


# 867bb99b 17-Dec-2018 Greg Lehey <grog@FreeBSD.org>

Work around BIOS quirks on HPE Proliant MicroServer Gen10

PR: 221350
Submitted by: Bob Bishop
Reported by: Rafal Lukawiecki
Reviewed by: jhb
MFC after: 2 weeks


# bfed756a 03-Dec-2018 Justin Hibbits <jhibbits@FreeBSD.org>

Sprinkle EARLY_DRIVER_MODULE around the tree

Mark some buses as BUS_PASS_BUS, and some resources as BUS_PASS_RESOURCE.
This also decouples some resource attachment orderings from being races by
device tree ordering, instead relying on the bus pass to provide the
ordering.

This was originally intended to support multipass suspend/resume, but it's
also needed on PowerMacs when using fdt, as the device tree seems to get
created in reverse of the OFW tree.
Reviewed by: nwhitehorn (long ago)
Differential Revision: https://reviews.freebsd.org/D918


# 1ace6e5b 18-Aug-2018 Konstantin Belousov <kib@FreeBSD.org>

Rudimentary AER reading code for ddb(4).

This is very primitive code to inspect the PCI error state and AER
error state, dump the log and clear errors, from ddb.
pci_print_faulted_dev() is made external to allow calling it from
other places. It was called from NMI handler but this chunk is not
included.

Also there is a tunable-controlled code to clear AER on device attach,
disabled by default.

All this code was useful to me when I debugged ACPI_DMAR failures (not
faults) long time ago.

Reviewed by: cem, imp (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D7813


# 971b5f76 07-Jul-2018 Warner Losh <imp@FreeBSD.org>

Create PCI_MATCH and pci_match_device

Create a covenience function to match PCI device IDs. It's about 15
years overdue.

Differential Revision: https://reviews.freebsd.org/D15999


# 7a16dacd 19-Feb-2018 Bryan Venteicher <bryanv@FreeBSD.org>

Add PCI methods to iterate over the PCI capabilities

VirtIO V1 provides configuration in multiple VENDOR capabilities so this
allows all of the configuration to be discovered.

Reviewed by: jhb
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D14325


# 151ba793 24-Dec-2017 Alexander Kabaev <kan@FreeBSD.org>

Do pass removing some write-only variables from the kernel.

This reduces noise when kernel is compiled by newer GCC versions,
such as one used by external toolchain ports.

Reviewed by: kib, andrew(sys/arm and sys/arm64), emaste(partial), erj(partial)
Reviewed by: jhb (sys/dev/pci/* sys/kern/vfs_aio.c and sys/kern/kern_synch.c)
Differential Revision: https://reviews.freebsd.org/D10385


# bb010783 20-Dec-2017 Warner Losh <imp@FreeBSD.org>

Add device location wiring to the pci bus.

This allows one to specify, for example, that if there's an igb card
in bus 12, slot 0, function 0, it should be assigned igb5. If there
isn't, or there's one in a different slot, normal numbering rules
apply (hinted units are skipped). Adding 'hint.igb.5.at="pci12:0:0"'
or 'hint.igb.5.at="pci0:12:0:0"' to /boot/device.hints will accomplish
this. The double quotes are important.

The kernel only accepts the strings (in shell notation):
pci$d:$b:$s:$f
and pci$b:$s:$f
where $d is the pci domain, $b is the pci bus number, $s is the slot
number and $f is the function number. A string compare is done with
the current device to avoid another string parser in the kernel. All
numbers are unsigned decimal without leading zeros.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13546


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# eab9d0a8 14-Nov-2017 Warner Losh <imp@FreeBSD.org>

Inline pcie_link_{status,caps} where needed. Remove them as they
aren't really needed and I don't want to document them.

Suggested by: jhb@
Sponsored by: Netflix


# d505913c 13-Nov-2017 Warner Losh <imp@FreeBSD.org>

Provide pcie_link_status and pcie_link_cap convenience functions.

Sponsored by: Netflix


# ceb972cf 09-Oct-2017 Alan Somers <asomers@FreeBSD.org>

Remove embedded newlines from sysctl variable descriptions

PR: 112556
Submitted by: Willem Jan Withagen <wjw@digiware.nl> (earlier version)
Reported by: Willem Jan Withagen, ighighi@gmail.com
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp


# d4ed36cd 01-Aug-2017 Roger Pau Monné <royger@FreeBSD.org>

pci: fix write order when sizing BARs

According to the PCI Local Specification rev. 3.0 in case of a 64-bit
BAR both the low and the high parts of the register should be set to
~0 before attempting to read back the size.

So far I have found no single device that has problems with the
previous approach, but I think it's better to stay on the safe size.

This commit should not introduce any functional change.

MFC after: 3 weeks
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential revision: https://reviews.freebsd.org/D11750


# 1536a1b8 15-Jan-2017 Sepherosa Ziehau <sephe@FreeBSD.org>

alc: Add Killer E2500 support

Reviewed by: jhb, yongari
MFC after: 1 week
Sponsored by: Microsoft
Differential Revision: https://reviews.freebsd.org/D9058


# db4fcadf 15-Jan-2017 Conrad Meyer <cem@FreeBSD.org>

"Buses" is the preferred plural of "bus"

Replace archaic "busses" with modern form "buses."

Intentionally excluded:
* Old/random drivers I didn't recognize
* Old hardware in general
* Use of "busses" in code as identifiers

No functional change.

http://grammarist.com/spelling/buses-busses/

PR: 216099
Reported by: bltsrc at mail.ru
Sponsored by: Dell EMC Isilon


# fafbaf79 30-Dec-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Add MSIX rewrite table quirk for use with VMs.

This patch solves IRQ generation problems using the mlx5en(4) driver
with xenserver v6.5.0 in SRIOV and PCI-passthrough modes.

Until further the hw.pci.msix_rewrite_table quirk must be set manually
in /boot/loader.conf .

Reviewed by: jhb @
Sponsored by: Mellanox Technologies
MFC after: 2 weeks


# a7a560be 21-Oct-2016 Alexander Motin <mav@FreeBSD.org>

Add names for some DASP devices.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week


# 4d6e19e4 27-Sep-2016 Sepherosa Ziehau <sephe@FreeBSD.org>

pci: Clear the MEM/PORT_EN bit when updating PCI BAR

It's unsafe to update the BAR when the related EN bit is set.

Submitted by: Dexuan Cui <decui microsoft com>
Reviewed by: jhb
MFC after: 1 week
Sponsored by: Microsoft
Differential Revision: https://reviews.freebsd.org/D7914


# bd716692 21-Sep-2016 John Baldwin <jhb@FreeBSD.org>

Fix invalid vendor ID constant (typo).

During a bus rescan the check for an invalid vendor ID of a subfunction
used the wrong constant.

Submitted by: Dexuan Cui <decui@microsoft.com>
MFC after: 3 days


# da0fc925 06-Sep-2016 John Baldwin <jhb@FreeBSD.org>

Reset PCI pass through devices via PCI-e FLR during VM start and end.

Add routines to trigger a function level reset (FLR) of a PCI-express
device via the PCI-express device control register. This also includes
support routines to wait for pending transactions to complete as well
as calculating the maximum completion timeout permitted by a device.

Change the ppt(4) driver to reset pass through devices before attaching
to a VM during startup and before detaching from a VM during shutdown.

Reviewed by: imp, wblock (earlier version)
MFC after: 1 month
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D7751


# 64414cc0 06-Sep-2016 John Baldwin <jhb@FreeBSD.org>

Update the I/O MMU in bhyve when PCI devices are added and removed.

When the I/O MMU is active in bhyve, all PCI devices need valid entries
in the DMAR context tables. The I/O MMU code does a single enumeration
of the available PCI devices during initialization to add all existing
devices to a domain representing the host. The ppt(4) driver then moves
pass through devices in and out of domains for virtual machines as needed.
However, when new PCI devices were added at runtime either via SR-IOV or
HotPlug, the I/O MMU tables were not updated.

This change adds a new set of EVENTHANDLERS that are invoked when PCI
devices are added and deleted. The I/O MMU driver in bhyve installs
handlers for these events which it uses to add and remove devices to
the "host" domain.

Reviewed by: imp
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D7667


# 477cba21 21-Aug-2016 Pyun YongHyeon <yongari@FreeBSD.org>

Add Killer E2400 Gigabit Ethernet support.
It seems Killer E2200/E2400 has a BIOS misconfiguration or silicon
bug which triggers DMA write errors when driver uses advertised
maximum payload size. Force the maximum payload size to 128 bytes
in DMA configuration.
This change should fix occasional DMA write errors reported on
Killer E2200.

Tested by: <psy0nic@sys-tek.org>


# 2ab0398d 24-Jun-2016 John Baldwin <jhb@FreeBSD.org>

Add pci_get_max_payload() to fetch the PCI-express maximum payload size.

Approved by: re (gjb)
MFC after: 2 weeks
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D6951


# d7be980d 16-May-2016 Andrew Turner <andrew@FreeBSD.org>

Re-commit r299467 having fixed the build:

Add a new get_id interface to pci and pcib. This will allow us to both
detect failures, and get different PCI IDs.

For the former the interface returns an int to signal an error. The ID is
returned at a uintptr_t * argument.

For the latter there is a type argument that allows selecting the ID type.
This only specifies a single type, however a MSI type will be added
to handle the need to find the ID the hardware passes to the ARM GICv3
interrupt controller.

A follow up commit will be made to remove pci_get_rid.

Reviewed by: jhb, rstone (previous version)
Obtained from: ABT Systems Ltd
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D6239


# f41be0f0 11-May-2016 Conrad Meyer <cem@FreeBSD.org>

Revert r299467 to fix the kernel build.

$ svn merge -c -299467 .

Approved by: build being broken for six hours


# 9a36a337 11-May-2016 Andrew Turner <andrew@FreeBSD.org>

Add a new get_id interface to pci and pcib. This will allow us to both
detect failures, and get different PCI IDs.

For the former the interface returns an int to signal an error. The ID is
returned at a uintptr_t * argument.

For the latter there is a type argument that allows selecting the ID type.
This only specifies a single type, however a MSI type will be added
to handle the need to find the ID the hardware passes to the ARM GICv3
interrupt controller.

A follow up commit will be made to remove pci_get_rid.

Reviewed by: jhb, rstone
Obtained from: ABT Systems Ltd
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D6239


# 1963070c 06-May-2016 John Baldwin <jhb@FreeBSD.org>

Restore name=value format of PCI location strings.

When devctl was added, the location string for PCI devices was changed to
use the PCI "selector" that pciconf and devctl accept. However, devd
assumes that location strings are formatted as a list of name=value pairs.
As a result, devd is no longer parsing any of the values out of PCI
device events. Restore the previous format of the PCI location strings
to restore the location and slot keywords in case any devd scripts are
using this. Add the "selector" as a new 'dbsf' location variable.

Reviewed by: imp
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D6253


# 12b204a6 04-May-2016 Jung-uk Kim <jkim@FreeBSD.org>

Fix build without "options PCI_IOV".


# e402d55c 03-May-2016 John Baldwin <jhb@FreeBSD.org>

Save and restore SRIOV-related config registers.

Save the value of the IOV control and page size registers and restore
them (along with the VF count) in pci_cfg_save/pci_cfg_restore. This
ensures ARI remains enabled if a PF driver resets itself during the
PCI_IOV_INIT callback. This might also properly restore SRIOV state
across suspend/resume.

Reviewed by: rstone, vangyzen
Differential Revision: https://reviews.freebsd.org/D6192


# 453130d9 02-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: minor spelling fixes.

Most affect comments, very few have user-visible effects.


# a38f0daf 02-May-2016 John Baldwin <jhb@FreeBSD.org>

Fix an off by one error when remapping MSI-X vectors.

pci_remap_msix() can be used to alter the mapping of allocated
MSI-X vectors to the MSI-X table. The code had an off by one error
when adding the IRQ resources after performing a remap. This was
fatal for any vectors in the table that used the "last" valid IRQ as
those vectors were assigned a garbage IRQ value.

MFC after: 3 days


# 5e456636 27-Apr-2016 John Baldwin <jhb@FreeBSD.org>

Fix build for systems without PCI_RES_BUS.

Submitted by: vangyzen


# c91991a2 27-Apr-2016 John Baldwin <jhb@FreeBSD.org>

Fix PCI bus detach to delete child devices.

Differential Revision: https://reviews.freebsd.org/D6020


# 3d0338a0 27-Apr-2016 John Baldwin <jhb@FreeBSD.org>

Implement a PCI bus rescan method.

Rescanning a PCI bus uses the following steps:
- Fetch the current set of child devices and save it in the 'devlist'
array.
- Allocate a parallel array 'unchanged' initalized with NULL pointers.
- Scan the bus checking each slot (and each function on slots with a
multifunction device).
- If a valid function is found, look for a matching device in the 'devlist'
array. If a device is found, save the pointer in the 'unchanged' array.
If a device is not found, add a new device.
- After the scan has finished, walk the 'devlist' array deleting any
devices that do not have a matching pointer in the 'unchanged' array.
- Finally, fetch an updated set of child devices and explicitly attach any
devices that are not present in the 'unchanged' array.

This builds on the previous changes to move subclass data management into
pci_alloc_devinfo(), pci_child_added(), and bus_child_deleted().

Subclasses of the PCI bus use custom rescan logic explicitly override the
rescan method to disable rescans.

Differential Revision: https://reviews.freebsd.org/D6018


# 517960dc 26-Apr-2016 Conrad Meyer <cem@FreeBSD.org>

PCI Enhanced Allocation: Annotate an intentional switch fallthrough

This is a trivial follow-up to r296308. Annotate the intentional fallthrough
to make it clear for future readers and linters.

Reported by: Coverity
CID: 1352716
Discussed with: jhb
Sponsored by: EMC / Isilon Storage Division


# 6cd99ae8 14-Apr-2016 John Baldwin <jhb@FreeBSD.org>

Add a new PCI bus interface method to alloc the ivars (dinfo) for a device.

The ACPI and OFW PCI bus drivers as well as CardBus override this to
allocate the larger ivars to hold additional info beyond the stock PCI ivars.

This removes the need to pass the size to functions like pci_add_iov_child()
and pci_read_device() simplifying IOV and bus rescanning implementations.

As a result of this and earlier changes, the ACPI PCI bus driver no longer
needs its own device_attach and pci_create_iov_child methods but can use
the methods in the stock PCI bus driver instead.

Differential Revision: https://reviews.freebsd.org/D5891


# 496dfa89 05-Apr-2016 John Baldwin <jhb@FreeBSD.org>

Convert pci_delete_child() to a bus_child_deleted() method.

Instead of providing a wrapper around device_delete_child() that the PCI
bus and child bus drivers must call explicitly, move the bulk of the logic
from pci_delete_child() into a bus_child_deleted() method
(pci_child_deleted()). This allows PCI devices to be safely deleted via
device_delete_child().
- Add a bus_child_deleted method to the ACPI PCI bus which clears the
device_t associated with the corresponding ACPI handle in addition to
the normal PCI bus cleanup.
- Change cardbus_detach_card to call device_delete_children() and move
CardBus-specific delete logic into a new cardbus_child_deleted() method.
- Use device_delete_child() instead of pci_delete_child() in the SRIOV code.
- Add a bus_child_deleted method to the OpenFirmware PCI bus drivers which
frees the OpenFirmware device info for each PCI device.

Reviewed by: imp
Tested on: amd64 (CardBus and PCI-e hotplug)
Differential Revision: https://reviews.freebsd.org/D5831


# da1b038a 17-Mar-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.

On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).

Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.

Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)

Tested PAE and devinfo on virtualbox (live CD)

Special thanks to bz for his testing on ARM.

Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544


# 534ccd7b 02-Mar-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Replace all resource occurrences of '0UL/~0UL' with '0/~0'.

Summary:
The idea behind this is '~0ul' is well-defined, and casting to uintmax_t, on a
32-bit platform, will leave the upper 32 bits as 0. The maximum range of a
resource is 0xFFF.... (all bits of the full type set). By dropping the 'ul'
suffix, C type promotion rules apply, and the sign extension of ~0 on 32 bit
platforms gets it to a type-independent 'unsigned max'.

Reviewed By: cem
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D5255


# 4d185754 02-Mar-2016 Wojciech Macek <wma@FreeBSD.org>

Support for Enhanced Allocation in PCI

On some platforms, BAR entries are hardcoded and must not be accessed
using standard method. Add functionality to identify this situation
and configure the bus based on Enhanced Allocation structure.

Obtained from: Semihalf
Sponsored by: Cavium
Approved by: cognet (mentor)
Reviewed by: jhb
Differential revision: https://reviews.freebsd.org/D5242


# 2dd1bdf1 26-Jan-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Convert rman to use rman_res_t instead of u_long

Summary:
Migrate to using the semi-opaque type rman_res_t to specify rman resources. For
now, this is still compatible with u_long.

This is step one in migrating rman to use uintmax_t for resources instead of
u_long.

Going forward, this could feasibly be used to specify architecture-specific
definitions of resource ranges, rather than baking a specific integer type into
the API.

This change has been broken out to facilitate MFC'ing drivers back to 10 without
breaking ABI.

Reviewed By: jhb
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D5075


# ce204e1b 23-Dec-2015 John Baldwin <jhb@FreeBSD.org>

Add accessor methods to fetch the BAR holding the MSI-X table and PBA.

While here, explicitly note the requirement that the BAR(s) must be
allocated prior to calling pci_alloc_msix().

Reviewed by: andrew, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D4688


# 87dd2f95 05-Nov-2015 John Baldwin <jhb@FreeBSD.org>

Add a new helper function for PCI devices to locate the upstream
PCI-express root port of a given PCI device.

Reviewed by: kib, imp
MFC after: 1 week
Sponsored by: Chelsio
Differential Revision: https://reviews.freebsd.org/D4089


# ec603c72 05-Nov-2015 John Baldwin <jhb@FreeBSD.org>

Add helper routines for PCI device drivers to read, write, and modify
PCI-Express capability registers (that is, PCI config registers in the
standard PCI config space belonging to the PCI-Express capability
register set).

Note that all of the current PCI-e registers are either 16 or 32-bits,
so only widths of 2 or 4 bytes are supported.

Reviewed by: imp
MFC after: 1 week
Sponsored by: Chelsio
Differential Revision: https://reviews.freebsd.org/D4088


# bee4a63b 18-Oct-2015 John-Mark Gurney <jmg@FreeBSD.org>

drop a bunch of white space at end of lines and end of files...
-x -wb apparently doesn't hide end of file white space changes..

This is to reduce the amount of diff for my PCIe HP changes..


# 69baeadc 29-May-2015 Konstantin Belousov <kib@FreeBSD.org>

Remove several write-only variables, all reported by the gcc 4.9
buildkernel run.

Some of them were write-only under some kernel options, e.g. variables
keeping values only used by CTR() macros. It costs nothing to the
code readability and correctness to eliminate the warnings in those
cases too by removing the local cached values used only for
single-access.

Review: https://reviews.freebsd.org/D2665
Reviewed by: rodrigc
Looked at by: bjk
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# ad6f36f8 22-Apr-2015 John Baldwin <jhb@FreeBSD.org>

Update the pci_cfg_save/restore routines to operate on bridge devices
(type 1 and type 2) as well as leaf devices (type 0). In particular,
this allows the existing PCI bus logic to save and restore capability
registers such as MSI and PCI-express work for bridge devices rather than
requiring that code to be duplicated in bridge drivers. It also means
that bridge drivers no longer need to save and restore basic registers
such as the PCI command register or BARs nor manage powerstates for the
bridge device.

While here, pci_setup_secbus() has been changed to initialize the 'sec'
and 'sub' fields in the 'secbus' structure instead of requiring the pcib
and pccbb drivers to do this in the NEW_PCIB + PCI_RES_BUS case.

Differential Revision: https://reviews.freebsd.org/D2240
Reviewed by: imp, jmg
MFC after: 2 weeks


# 65c7c1b4 22-Apr-2015 John Baldwin <jhb@FreeBSD.org>

The minimim grant and maximum latency PCI config registers are only valid
for type 0 devices, not type 1 or 2 bridges. Don't read them for bridge
devices during bus scans and return an error when attempting to read them
as ivars for bridge devices.


# be2c6c0d 01-Mar-2015 Warner Losh <imp@FreeBSD.org>

Don't leak 'used' in a few error cases.

Reported by: Maxime Villard


# e9309eac 28-Feb-2015 Ryan Stone <rstone@FreeBSD.org>

Allocate PCI I/O memory spaces for VFs

When creating VFs, we must size each SR-IOV BAR on the PF and
allocate a configuous I/O memory window large enough for every VF.
However, the window only needs to be aligned to a boundary equal
to the size of the window for a single VF.

When a VF attempts to allocate an I/O memory resource, we must
intercept the request in the pci driver and pass it off to the
SR-IOV code, which will allocate the correct window from the
pre-allocated memory space for the PF.

Inform the pci driver about the size and address of the BARs on
the VF when the VF is created. This is required by pciconf -b and
bhyve.

Differential Revision: https://reviews.freebsd.org/D78
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Sandvine Inc.


# 5060ec97 28-Feb-2015 Ryan Stone <rstone@FreeBSD.org>

Emulate the Device ID and Vendor ID registers for VFs

The SR-IOV standard requires VFs to read all-ones when the VID
and DID registers are read. The VMM (hypervisor) is required to
emulate them instead. Make pci_read_config() do this emulation.

Change pci_user.c to use pci_read_config() to read config space
registers instead of going directly to the pcib so that the
emulated VID/DID registers work correctly on VFs. This is
required both for pciconf and bhyve PCI passthrough.

Differential Revision: https://reviews.freebsd.org/D77
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Sandvine Inc.


# 9bfb1e36 28-Feb-2015 Ryan Stone <rstone@FreeBSD.org>

Implement interface to create SR-IOV Virtual Functions

Implement the interace to create SR-IOV Virtual Functions (VFs).
When a driver registers that they support SR-IOV by calling
pci_setup_iov(), the SR-IOV code creates a new node in /dev/iov
for that device. An ioctl can be invoked on that device to
create VFs and have the driver initialize them.

At this point, allocating memory I/O windows (BARs) is not
supported.

Differential Revision: https://reviews.freebsd.org/D76
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Sandvine Inc.


# 5ce88dc6 28-Feb-2015 Ryan Stone <rstone@FreeBSD.org>

Refactor PCI resource allocation

Refactor PCI resource allocation code to allow a request for a
memory-mapped I/O window that is a multiple of a requested size.
This is needed by the SR-IOV code because the VF BARs are all
allocated contiguously. We can't just allocate a resource that is
a multiple of a single VF BAR because the size of an allocation
implies its alignment requirement.

Differential Revision: https://reviews.freebsd.org/D71
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Sandvine Inc.


# 2f5055a9 28-Feb-2015 Ryan Stone <rstone@FreeBSD.org>

Refactor PCI device creation

Refactor creation of PCI devices into helper methods that can be
used by the VF creation code.

Differential Revision: https://reviews.freebsd.org/D67
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Sandvine Inc.


# 69d4c287 16-Feb-2015 John-Mark Gurney <jmg@FreeBSD.org>

remove NULL check as M_WAITOK will not return NULL

Reviewed by: jhb
Sponsored by: FreeBSD Foundation


# 64de8019 06-Feb-2015 John Baldwin <jhb@FreeBSD.org>

Add a new device control utility for new-bus devices called devctl. This
allows the user to request administrative changes to individual devices
such as attach or detaching drivers or disabling and re-enabling devices.
- Add a new /dev/devctl2 character device which uses ioctls for device
requests. The ioctls use a common 'struct devreq' which is somewhat
similar to 'struct ifreq'.
- The ioctls identify the device to operate on via a string. This
string can either by the device's name, or it can be a bus-specific
address. (For unattached devices, a bus address is the only way to
locate a device.) Bus drivers register an eventhandler to claim
unrecognized device names that the driver recognizes as a valid address.
Two buses currently support addresses: ACPI recognizes any device
in the ACPI namespace via its full path starting with "\" and
the PCI bus driver recognizes an address specification of
'pci[<domain>:]<bus>:<slot>:<func>' (identical to the PCI selector
strings supported by pciconf).
- To make it easier to cut and paste, change the PnP location string
in the PCI bus driver to output a full PCI selector string rather
than 'slot=<slot> function=<func>'.
- Add a devctl(3) interface in libdevctl which provides a wrapper around
the ioctls and is the preferred interface for other userland code.
- Add a devctl(8) program which is a simple wrapper around the requests
supported by devctl(3).
- Add a device_is_suspended() function to check DF_SUSPENDED.
- Add a resource_unset_value() function that can be used to remove a
hint from the kernel environment. This is used to clear a
hint.<driver>.<unit>.disabled hint when re-enabling a boot-time
disabled device.

Reviewed by: imp (parts)
Requested by: imp (changing PCI location string)
Relnotes: yes


# 40438c47 27-Dec-2014 Marius Strobl <marius@FreeBSD.org>

- Make PCI_QUIRK_MSI_INTX_BUG work by using the ID of the actual PCI device
for the lookup.
- For devices affected by PCI_QUIRK_MSI_INTX_BUG, ensure PCIM_CMD_INTxDIS
is cleared when using MSI/MSI-X.
- Employ PCI_QUIRK_MSI_INTX_BUG for BCM5714(S)/BCM5715(S)/BCM5780(S) rather
than clearing PCIM_CMD_INTxDIS unconditionally for all devices in bge(4).

MFC after: 3 days


# 34b33398 19-Nov-2014 Dmitry Chagin <dchagin@FreeBSD.org>

Revert r274635 as it's completely wrong.
The parent of a pci dev device is a pciX device which do not
implement the PCIB_POWER_FOR_SLEEP method from pcib_if.m.


# 91bd62ca 17-Nov-2014 Dmitry Chagin <dchagin@FreeBSD.org>

Use the correct device as the power_for_sleep() method
always pass request up to parent bridge.

Reviewed by: jhb
MFC after: 1 week
xMFC: r274386,r274397


# 2da2ade0 11-Nov-2014 Adrian Chadd <adrian@FreeBSD.org>

Use the correct device (child) when asking the bus layer about which power
state said device should go into.

This was a snafu introduced in the ACPI/PCI awareness separation.

When putting a device into a power state, the bus (and thus firmware,
eg ACPI) should be asked before hand to check whether the device
can indeed go into that power state.

There's a set of nodes in ACPI under each device - the _SxD nodes - which
state which ACPI power state to put the device into when the system is
going into power save state 'x'. So when going into S3, the existence
of an _S3D node would override whatever the system was trying to do.

By default the PCI code wants to put devices into D3 before suspending.

I have a laptop here (Asus Zenbook - check the PR) whose EHCI controller
really wants to be in D2 during suspend, not D3. So if we put it into
D3 and then try to enter S3, everything hangs. The device itself
can go into D3 - it just can't be there when the call to ACPI to enter
S3 occurs. The PCI patch fixes this.

jkim@ noticed that the same is needed for the ACPI child device
enumeration.

Thankyou to Matt Dillon (the programmer, not the actor) for buying me
this particular laptop so I could debug the issues with the Atheros
AR9485 that is in it. It's his fault that I ended up with this
laptop and was sufficiently annoyed by the lack of USB suspend
to go down this rabbit hole.

Tested:

* Thinkpad T400
* Thinkpad X230
* Thinkpad T42
* Thinkpad T60
* Asus Zenbook (see PR)
* Asus EEEPC 701
* Asus EEEPC 1001PX

TODO:

* Figure out what we should do about devices we unload drivers for
that want to be in a specific state when entering S3 / S4 -
the "put devices into D3 if they're not bound to a driver" option
may also mess with things.

PR: kern/194884
Reviewed by: jhb, jkim
MFC after: 1 week
Relnotes: yes
Sponsored by: Matt Dillon <dillon@apollo.backplane.com> (hardware)


# 2be111bf 16-Oct-2014 Davide Italiano <davide@FreeBSD.org>

Follow up to r225617. In order to maximize the re-usability of kernel code
in userland rename in-kernel getenv()/setenv() to kern_setenv()/kern_getenv().
This fixes a namespace collision with libc symbols.

Submitted by: kmacy
Tested by: make universe


# ffcf962d 08-Oct-2014 Adrian Chadd <adrian@FreeBSD.org>

Add a bus method to fetch the VM domain for the given device/bus.

* Add a bus_if.m method - get_domain() - returning the VM domain or
ENOENT if the device isn't in a VM domain;
* Add bus methods to print out the domain of the device if appropriate;
* Add code in srat.c to save the PXM -> VM domain mapping that's done and
expose a function to translate VM domain -> PXM;
* Add ACPI and ACPI PCI methods to check if the bus has a _PXM attribute
and if so map it to the VM domain;
* (.. yes, this works recursively.)
* Have the pci bus glue print out the device VM domain if present.

Note: this is just the plumbing to start enumerating information -
it doesn't at all modify behaviour.

Differential Revision: D906
Reviewed by: jhb
Sponsored by: Norse Corp


# dd6d49aa 07-Oct-2014 Pyun YongHyeon <yongari@FreeBSD.org>

Oops, fix typo made in r272729.


# b19487df 07-Oct-2014 Pyun YongHyeon <yongari@FreeBSD.org>

Add new quirk PCI_QUIRK_MSI_INTX_BUG to pci(4).
QAC AR816x/E2200 controller has a silicon bug that MSI interrupt
does not assert if PCIM_CMD_INTxDIS bit of command register is set.

Reviewed by: jhb


# a1c16348 22-Sep-2014 Justin Hibbits <jhibbits@FreeBSD.org>

Stage one of multipass suspend/resume

Summary:
Add the beginnings of multipass suspend/resume, by introducing
BUS_SUSPEND_CHILD/BUS_RESUME_CHILD, and move the PCI driver to this.

Reviewers: jhb

Reviewed By: jhb

Differential Revision: https://reviews.freebsd.org/D590


# cd407ca2 22-Aug-2014 Roger Pau Monné <royger@FreeBSD.org>

pci: add a new pci_child_added newbus method.

This is needed so when running under Xen the calls to pci_child_added
can be intercepted and a custom Xen method can be used to register
those devices with Xen. This should not include any functional
change, since the Xen implementation will be added in a following
patch and the native implementation is a noop.

Sponsored by: Citrix Systems R&D
Reviewed by: jhb

dev/pci/pci.c:
dev/pci/pci_if.m:
dev/pci/pci_private.h:
dev/pci/pcivar.h:
- Add the pci_child_added newbus method.


# 073bf9dd 20-Aug-2014 Roger Pau Monné <royger@FreeBSD.org>

pci: make MSI(-X) enable and disable methods of the PCI bus

Make the functions pci_disable_msi, pci_enable_msi and pci_enable_msix
methods of the newbus PCI bus. This code should not include any
functional change.

Sponsored by: Citrix Systems R&D
Reviewed by: imp, jhb
Differential Revision: https://reviews.freebsd.org/D354

dev/pci/pci.c:
- Convert the mentioned functions to newbus methods.
- Fix the callers of the converted functions.

sys/dev/pci/pci_private.h:
dev/pci/pci_if.m:
- Declare the new methods.

dev/pci/pcivar.h:
- Add helpers to call the newbus methods.

ofed/include/linux/pci.h:
- Add define to prevent the ofed version of pci_enable_msix from
clashing with the FreeBSD native version.


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

These changes prevent sysctl(8) from returning proper output,
such as:

1) no output from sysctl(8)
2) erroneously returning ENOMEM with tools like truss(1)
or uname(1)
truss: can not get etype: Cannot allocate memory


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after: 2 weeks
Sponsored by: Mellanox Technologies


# e887c1de 20-May-2014 Alexander Motin <mav@FreeBSD.org>

Add IOMMU PCI subclass, found on Tyan S8236 motherboard.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 2 weeks


# 8197f45b 30-Apr-2014 Steven Hartland <smh@FreeBSD.org>

Make uninteresting PCI devices with no attached drivers only print out
on a verbose boot

MFC after: 2 weeks


# c8912fcb 03-Apr-2014 Ryan Stone <rstone@FreeBSD.org>

Correct a PCI enumeration bug introduced in r264011

Ensure that first_func is set to 0 on every iteration of the PCI slot
enumeration loop after the first. There is a continue statement that would
cause first_func to stay at 1 any PCI device where slot 0 has no functions
until we find a slot that does have a function. This would cause us to
not enumerate the first PCI function on the device.

Credit to markj@ for spotting the bug.

X-MFC-With: r264011


# 55d3ea17 01-Apr-2014 Ryan Stone <rstone@FreeBSD.org>

Add support for PCIe ARI

PCIe Alternate RID Interpretation (ARI) is an optional feature that
allows devices to have up to 256 different functions. It is
implemented by always setting the PCI slot number to 0 and
re-purposing the 5 bits used to encode the slot number to instead
contain the function number. Combined with the original 3 bits
allocated for the function number, this allows for 256 functions.

This is enabled by default, but it's expected to be a no-op on currently
supported hardware. It's a prerequisite for supporting PCI SR-IOV, and
I want the ARI support to go in early to help shake out any bugs in it.
ARI can be disabled by setting the tunable hw.pci.enable_ari=0.

Reviewed by: kib
MFC after: 2 months
Sponsored by: Sandvine Inc.


# 5605a99e 01-Apr-2014 Ryan Stone <rstone@FreeBSD.org>

Add a method to get the PCI RID for a device.

Reviewed by: kib
MFC after: 2 months
Sponsored by: Sandvine Inc.


# 7036ae46 01-Apr-2014 Ryan Stone <rstone@FreeBSD.org>

Revert PCI RID changes.

My PCI RID changes somehow got intermixed with my PCI ARI patch when I
committed it. I may have accidentally applied a patch to a non-clean
working tree. Revert everything while I figure out what went wrong.

Pointy hat to: rstone


# d773f48b 01-Apr-2014 Ryan Stone <rstone@FreeBSD.org>

Add a method to get the PCI Routing ID for a device

Reviewed by: kib
Sponsored by: Sandvine, Inc


# 4edef187 11-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Add support for managing PCI bus numbers. As with BARs and PCI-PCI bridge
I/O windows, the default is to preserve the firmware-assigned resources.
PCI bus numbers are only managed if NEW_PCIB is enabled and the architecture
defines a PCI_RES_BUS resource type.
- Add a helper API to create top-level PCI bus resource managers for each
PCI domain/segment. Host-PCI bridge drivers use this API to allocate
bus numbers from their associated domain.
- Change the PCI bus and CardBus drivers to allocate a bus resource for
their bus number from the parent PCI bridge device.
- Change the PCI-PCI and PCI-CardBus bridge drivers to allocate the
full range of bus numbers from secbus to subbus from their parent bridge.
The drivers also always program their primary bus register. The bridge
drivers also support growing their bus range by extending the bus resource
and updating subbus to match the larger range.
- Add support for managing PCI bus resources to the Host-PCI bridge drivers
used for amd64 and i386 (acpi_pcib, mptable_pcib, legacy_pcib, and qpi_pcib).
- Define a PCI_RES_BUS resource type for amd64 and i386.

Reviewed by: imp
MFC after: 1 month


# 0070c94b 05-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Add two tunables to ignore certain firmware-assigned resources. These
are mostly useful for debugging.
- hw.pci.clear_bars ignores all firmware-assigned ranges for BARs when
set.
- hw.pci.clear_pcib ignores all firmware-assigned ranges for PCI-PCI
bridge I/O windows when set.

MFC after: 1 week


# b986a7ec 05-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Simplify pci_reserve_map() by calling resource_list_reserve() to allocate
the resource after creating a resource list entry rather than reimplementing
it by hand.

MFC after: 1 week


# 8d280bcb 05-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Properly set the alignment flags when allocating the initial range for a
BAR. This only really matters when pci_do_realloc_bars is enabled and
the initial allocation of a specific range fails.

MFC after: 1 week


# 84b755df 20-Jan-2014 John Baldwin <jhb@FreeBSD.org>

Add support for displaying VPD for PCI devices via pciconf.
- Store the length of each read-only VPD value since not all values are
guaranteed to be ASCII values (though most are).
- Add a new pciio ioctl to fetch VPD for a single PCI device. The values
are returned as a list of variable length records, one for the device
name and each keyword.
- Add a new -V flag to pciconf's list mode which displays VPD data for
each device.

MFC after: 1 week


# c54a713f 24-Oct-2013 Konstantin Belousov <kib@FreeBSD.org>

Make pci_get_dma_tag() non-static. Since the function is only
referenced by pointer, making it non-static should not have even the
negligible impact on the existing code.

Reviewed by: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# feb96b46 24-Oct-2013 Konstantin Belousov <kib@FreeBSD.org>

Move the PCI_DMA_BOUNDARY definition into the pcivar.h.

Reviewed by: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# c825d4dc 18-Jul-2013 John Baldwin <jhb@FreeBSD.org>

Properly handle I/O windows in bridges with the ISA enable bit set. These
beasts still exist unfortunately. More details can be found in other
references, but the short version is that bridges with this bit set ignore
I/O port ranges that alias to valid ISA I/O port ranges. In the driver
this requires not allocating these alias regions from the parent device
(so they are free to be acquired by ISA devices), and ensuring no child
devices use resources from these alias regions.
- Change the pcib_window structure to allow for an array of backing
resources rather than a single resource and update the existing code
to cope with this. Some of the coping requires using the saved
base and limit values in pcib_window instead of using rman operations
on the backing resource.
- Add special handling for allocating and adjusting the I/O port window
of an ISA-enabled bridge to only allocate the non-alias ranges and
add those to the associated resource manager.
- Reject I/O port allocations for a fixed request that conflicts with an
ISA alias range.
- Remove the "no prefected decode" verbose printf during boot. The absence
of a "prefetched decode" line is sufficient.
- Replace the "subtractively decoded bridge" verbose printf with a single
printf that lists all the "special" decoding modes of a bridge: ISA,
subtractive, and VGA.
- Add a custom bus_release_resource() method to the PCI bus driver so that
it can properly free resources for I/O windows of PCI-PCI bridges.
(These resources are not stored in the bridge device's resource list.)

PR: misc/179033
MFC after: 2 weeks


# 68e9cbd3 09-Jul-2013 Marius Strobl <marius@FreeBSD.org>

- As it turns out, not only MSI-X is broken for devices passed through by
VMware up to at least ESXi 5.1. Actually, using INTx in that case instead
may still result in interrupt storms, with MSI being the only working
option in some configurations. So introduce a PCI_QUIRK_DISABLE_MSIX quirk
which only blacklists MSI-X but not also MSI and use it for the VMware
PCI-PCI-bridges. Note that, currently, we still assume that if MSI doesn't
work, MSI-X won't work either - but that's part of the internal logic and
not guaranteed as part of the API contract. While at it, add and employ
a pci_has_quirk() helper.
Reported and tested by: Paul Bucher
- Use NULL instead of 0 for pointers.

Submitted by: jhb (mostly)
Approved by: jhb
MFC after: 3 days


# e35ce1f2 27-Jun-2013 John Baldwin <jhb@FreeBSD.org>

Make detaching drivers from PCI devices more robust. While here, fix a
bug where a PCI device would be powered down if it failed to probe, but
not when its driver was detached (e.g. via kldunload).
- Add a new helper method resource_list_release_active() which forcefully
releases any active resources of a specified type from a resource list.
- Add a bus_child_detached method for the PCI bus driver which forces any
active resources to be released (and whines to the console if it finds
any) and then powers the device down.
- Call pci_child_detached() if we fail to probe a device when a driver
is kldloaded. This isn't perfect but can avoid leaking resources
from a probe() routine in the kldload case.

Reviewed by: imp, brooks
MFC after: 1 month


# 19e1c4d1 24-Jun-2013 John Baldwin <jhb@FreeBSD.org>

Disable hw.pci.realloc_bars by default. It wasn't needed for the original
tester of this fix, and realloc_bars breaks some other cases as a small
BAR that is reallocated can end up grabbing space needed by a much larger
BAR in the existing window of a PCI-PCI bridge.

MFC after: 3 days


# 5569a8b8 09-May-2013 John Baldwin <jhb@FreeBSD.org>

Revision 233677 broke certain machines. Specifically, if the firmware/BIOS
assigned conflicting ranges to BARs then leaving the BARs alone could
result in one device stealing mmio accesses intended to go to a second
device. Prior to 233677 the PCI bus driver attempted to handle this case
by clearing the BAR to 0 depending on BARs based at 0 not decoding (which
is not guaranteed to be true). Now when a conflicting BAR is detected the
following steps are taken:

1) If hw.pci.realloc_bars (a new tunable) is enabled (default is enabled),
then ignore the current BAR setting from the firmware and attempt to
allocate a fresh resource range for the BAR.

2) If 1) failed (or was disabled), disable decoding for the relevant
BAR type (e.g. disable mem decoding for a memory BAR) and emit a
warning if booting verbose.

Tested by: Alex Keda <admin@lissyara.su>
MFC after: 1 week


# 4495286f 02-Mar-2013 Marius Strobl <marius@FreeBSD.org>

- Complete r231621 by also blacklisting the bridge used by VMware for PCIe
devices. While at it, update the comment now that we know that MSI-X
doesn't work with ESXi 5.1 for Intel 82576 either and the underlying issue
is a bug in the MSI-X allocation code of the hypervisor.
Reported by: Harald Schmalzbauer
- Make the nomatch table const.

MFC after: 1 week


# 5bf80db6 27-Feb-2013 Neel Natu <neel@FreeBSD.org>

Remove the quirk to allow use of MSI when the guest is running inside bhyve.

This became redundant after the hostbridge presented to the guest started
advertising the PCI-E capability (r246846).

Obtained from: NetApp


# a61359a9 05-Jan-2013 Neel Natu <neel@FreeBSD.org>

Add quirk to indicate that the bhyve hostbridge is capable of supporting
MSI and MSI-X even though it does not advertise the PCI-E capability
itself.

Obtained from: NetApp


# 29658c96 05-Nov-2012 Dimitry Andric <dim@FreeBSD.org>

Remove duplicate const specifiers in many drivers (I hope I got all of
them, please let me know if not). Most of these are of the form:

static const struct bzzt_type {
[...list of members...]
} const bzzt_devs[] = {
[...list of initializers...]
};

The second const is unnecessary, as arrays cannot be modified anyway,
and if the elements are const, the whole thing is const automatically
(e.g. it is placed in .rodata).

I have verified this does not change the binary output of a full kernel
build (except for build timestamps embedded in the object files).

Reviewed by: yongari, marius
MFC after: 1 week


# 9b80cdf5 29-Oct-2012 Neel Natu <neel@FreeBSD.org>

Teach FreeBSD to detect that it is a guest running inside BHyVe.

Reviewed by: grehan
Obtained from: NetApp


# 3cdfd8d3 20-Sep-2012 Gavin Atkinson <gavin@FreeBSD.org>

The correct generic term for PCIS_STORAGE_NVM is "NVM" not "NVM Express".

Submitted by: jimharris
MFC after: 6 days


# a5c5eaae 19-Sep-2012 Gavin Atkinson <gavin@FreeBSD.org>

Recognise NVM Express devices and pretty-print their name.

MFC after: 1 week


# 389c8bd5 18-Sep-2012 Gavin Atkinson <gavin@FreeBSD.org>

Align the PCI Express #defines with the style used for the PCI-X
#defines. This also has the advantage that it makes the names more
compact, iand also allows us to correct the non-uniform naming of
the PCIM_LINK_* defines, making them all consistent amongst themselves.

This is a mostly mechanical rename:
s/PCIR_EXPRESS_/PCIER_/g
s/PCIM_EXP_/PCIEM_/g
s/PCIM_LINK_/PCIEM_LINK_/g

When this is MFC'd, #defines will be added for the old names to assist
out-of-tree drivers.

Discussed with: jhb
MFC after: 1 week


# d79a4775 23-May-2012 John Baldwin <jhb@FreeBSD.org>

Only check to see if a memory resource is a PCI ROM BAR when activating
and deactivating PCI resources. Previously, if a device had more than
48 MSI interrupts, then activating message 48 (which has a rid == PCIR_BIOS)
would incorrectly try to enable the PCI ROM BAR.

Tested by: Olivier Cinquin ocinquin uci edu
MFC after: 3 days


# 64d87e5b 29-Mar-2012 Jung-uk Kim <jkim@FreeBSD.org>

Fix couple of style nits.


# 5757b182 29-Mar-2012 Jung-uk Kim <jkim@FreeBSD.org>

Revert r233662 and generalize the hack. Writing zero to BAR actually does
not disable it and it is even harmful as hselasky found out. Historically,
this code was originated from (OLDCARD) CardBus driver and later leaked into
PCI driver when CardBus was newbus'ified and refactored with PCI driver.
However, it is not really necessary even for CardBus.

Reviewed by: hselasky, imp, jhb


# 0d95597c 29-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Use a more proper fix for enabling HT MSI mapping windows on Host-PCI
bridges. Rather than blindly enabling the windows on all of them, only
enable the window when an MSI interrupt is enabled for a device behind
the bridge, similar to what already happens for HT PCI-PCI bridges.

To implement this, each x86 Host-PCI bridge driver has to be able to
locate it's actual backing device on bus 0. For ACPI, use the _ADR
method to find the slot and function of the device. For the non-ACPI
case, the legacy(4) driver already scans bus 0 looking for Host-PCI
bridge devices. Now it saves the slot and function of each bridge that
it finds as ivars that the Host-PCI bridge driver can then use in its
pcib_map_msi() method.

This fixes machines where non-MSI interrupts were broken by the previous
round of HT MSI changes.

Tested by: bapt
MFC after: 1 week


# 0e854271 29-Mar-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix for boot issue: Don't disable BARs on AGP devices. In general:
Don't disable BARs on any PCI display devices, because doing that can
sometimes cause the main memory bus to stop working, causing all
memory reads to return nothing but 0xFFFFFFFF, even though the memory
location was previously written. After a while a privileged
instruction fault will appear and then nothing more can be debugged.
The reason for this behaviour is unknown.

MFC after: 1 week


# 96ec27d4 14-Mar-2012 Jung-uk Kim <jkim@FreeBSD.org>

Add a PCI quirk to ignore PCI map registers from configuration space.
For example, some BIOS for AMD SB600 south bridge may map HPET MMIO base
address as a memory BAR for SMBus controller depending on a PM register
configuration. Before r231161 (and r232086, subsequent MFC to stable/9),
it was not fatal but hpet(4) just failed to attach. Since we probe and
attach HPET earlier than PCI devices now, it caused unfortunate hard lockup.
With this patch, it does not hang any more and HPET works at the same time.
Clean up some style nits while I am in the neighborhood.

PR: kern/165647
Reviewed by: jhb
MFC after: 3 days


# 6e9dcee4 08-Mar-2012 Alexander Kabaev <kan@FreeBSD.org>

Save more of config space for PCI Express and PCI-X devices.

Expand pci_save_state and pci_restore_state to save more of
the config state for PCI Express and PCI-X devices. Various
writable control registers are present in PCI Express that
can potentially be lost over suspend/resume cycle.

This change is modeled after similar functionality in Linux.

Reviewed by: wlosh,jhb
MFC after: 1 month


# e80cc28c 07-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Remove the PAE-specific 2GB DMA boundary since HEAD now supports a proper 4G
boundary for PAE.


# 87663509 07-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Simplify the PCI bus dma tag code a bit. First, don't create a tag at
all for platforms that only have 32-bit bus addresses. Second, remove
the 'tag_valid' flag from the softc. Instead, if we don't create a
tag in pci_attach_common(), just cache the value of our parent's tag
so that we always have a valid tag to return.


# c668000b 03-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Expand the set of APIs available for locating PCI capabilities:
- pci_find_extcap() is repurposed to be used for fetching PCI-express
extended capabilities (PCIZ_* constants in <dev/pci/pcireg.h>).
- pci_find_htcap() can be used to locate a specific HyperTransport
capability (PCIM_HTCAP_* constants in <dev/pci/pcireg.h>).
- Cache the starting location of the PCI-express capability for PCI-express
devices in PCI device ivars.


# 180aa2f0 03-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Fix a typo.


# 1b1596a3 02-Mar-2012 John Baldwin <jhb@FreeBSD.org>

- Add a bus_dma tag to each PCI bus that is a child of a Host-PCI bridge.
The tag enforces a single restriction that all DMA transactions must not
cross a 4GB boundary. Note that while this restriction technically only
applies to PCI-express, this change applies it to all PCI devices as it
is simpler to implement that way and errs on the side of caution.
- Add a softc structure for PCI bus devices to hold the bus_dma tag and
a new pci_attach_common() routine that performs actions common to the
attach phase of all PCI bus drivers. Right now this only consists of
a bootverbose printf and the allocate of a bus_dma tag if necessary.
- Adjust all PCI bus drivers to allocate a PCI bus softc and to call
pci_attach_common() from their attach routines.

MFC after: 2 weeks


# 9415d1e0 01-Mar-2012 John Baldwin <jhb@FreeBSD.org>

Add pci_save_state() and pci_restore_state() wrappers around
pci_cfg_save() and pci_cfg_restore() for device drivers to use when
saving and restoring state (e.g. to handle device-specific resets).

Reviewed by: imp
MFC after: 2 weeks


# 49329d28 29-Feb-2012 John Baldwin <jhb@FreeBSD.org>

Use pci_printf() instead of a home-rolled version in the VPD parsing code.


# bb631bf9 13-Feb-2012 Marius Strobl <marius@FreeBSD.org>

- As it turns out, MSI-X is broken for at least LSI SAS1068E when passed
through by VMware so blacklist their PCI-PCI bridge for MSI/MSI-X here.
Note that besides currently there not being a quirk type that disables
MSI-X only and there's no evidence that MSI doesn't work with the VMware
pass-through, it's really questionable whether MSI generally works in
that setup as VMware only mention three know working devices [1, p. 4].
Also not that this quirk entry currently doesn't affect the devices
emulated by VMware in any way as these don't claim support MSI/MSI-X to
begin with. [2]
While at it, make the PCI quirk table const and static.
- Remove some duplicated empty lines.
- Use DEVMETHOD_END.

PR: 163812, http://forums.freebsd.org/showthread.php?t=27899 [2]
Reviewed by: jhb
MFC after: 3 days


# df4ce32f 19-Jan-2012 John Baldwin <jhb@FreeBSD.org>

Properly return success once a matching VPD entry is found in
pci_get_vpd_readonly_method(). Previously the loop was always running
to completion and falling through to failing with ENXIO.

PR: kern/164313
Submitted by: Chuck Tuffli chuck tuffli net
MFC after: 1 week


# ff11fd7f 22-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Add missing XHCI early takeover code. The XHCI takeover code
is supposed to disable the BIOS from using the XHCI controller
after bootup.

Approved by: re (kib)
Reported by: Mike Tancsa
MFC after: 1 week


# eb06e771 13-Jul-2011 Marius Strobl <marius@FreeBSD.org>

PCIB_ALLOC_MSIX() may already fail on the first pass, f.e. when the PCI-PCI
bridge is blacklisted. In that case just return from pci_alloc_msix_method(),
otherwise we continue without a single MSI-X resource, causing subsequent
attempts to use the seemingly available resource to fail or when booting
verbose a NULL-pointer dereference of rle->start when trying to print the
IRQ in pci_alloc_msix_method().

Reviewed by: jhb
MFC after: 1 week


# 141c08f9 09-Jul-2011 Konstantin Belousov <kib@FreeBSD.org>

Implement pci_find_class(9), the function to find a pci device by its class.

Sponsored by: The FreeBSD Foundation
Reviewed by: jhb
MFC after: 1 week


# 35d20010 21-Jun-2011 John Baldwin <jhb@FreeBSD.org>

Minor whitespace and style fixes.


# 0d439b5f 06-Jun-2011 John Baldwin <jhb@FreeBSD.org>

More properly handle Cardbus cards that that store their CIS in a BAR after
the recent changes to track BAR state explicitly. The code would now
attempt to add the same BAR twice in this case. Instead, change this so
that it recognizes this case and only adds it once and do not delete the
BAR outright after parsing the CIS.

Tested by: bschmidt


# 83c41143 03-May-2011 John Baldwin <jhb@FreeBSD.org>

Reimplement how PCI-PCI bridges manage their I/O windows. Previously the
driver would verify that requests for child devices were confined to any
existing I/O windows, but the driver relied on the firmware to initialize
the windows and would never grow the windows for new requests. Now the
driver actively manages the I/O windows.

This is implemented by allocating a bus resource for each I/O window from
the parent PCI bus and suballocating that resource to child devices. The
suballocations are managed by creating an rman for each I/O window. The
suballocated resources are mapped by passing the bus_activate_resource()
call up to the parent PCI bus. Windows are grown when needed by using
bus_adjust_resource() to adjust the resource allocated from the parent PCI
bus. If the adjust request succeeds, the window is adjusted and the
suballocation request for the child device is retried.

When growing a window, the rman_first_free_region() and
rman_last_free_region() routines are used to determine if the front or
end of the existing I/O window is free. From using that, the smallest
ranges that need to be added to either the front or back of the window
are computed. The driver will first try to grow the window in whichever
direction requires the smallest growth first followed by the other
direction if that fails.

Subtractive bridges will first attempt to satisfy requests for child
resources from I/O windows (including attempts to grow the windows). If
that fails, the request is passed up to the parent PCI bus directly
however.

The PCI-PCI bridge driver will try to use firmware-assigned ranges for
child BARs first and only allocate a "fresh" range if that specific range
cannot be accommodated in the I/O window. This allows systems where the
firmware assigns resources during boot but later wipes the I/O windows
(some ACPI BIOSen are known to do this) to "rediscover" the original I/O
window ranges.

The ACPI Host-PCI bridge driver has been adjusted to correctly honor
hw.acpi.host_mem_start and the I/O port equivalent when a PCI-PCI bridge
makes a wildcard request for an I/O window range.

The new PCI-PCI bridge driver is only enabled if the NEW_PCIB kernel option
is enabled. This is a transition aide to allow platforms that do not
yet support bus_activate_resource() and bus_adjust_resource() in their
Host-PCI bridge drivers (and possibly other drivers as needed) to use the
old driver for now. Once all platforms support the new driver, the
kernel option and old driver will be removed.

PR: kern/143874 kern/149306
Tested by: mav


# d2c9344f 02-May-2011 John Baldwin <jhb@FreeBSD.org>

Add implementations of BUS_ADJUST_RESOURCE() to the PCI bus driver,
generic PCI-PCI bridge driver, x86 nexus driver, and x86 Host to PCI bridge
drivers.


# 8adcbaed 27-Apr-2011 John Baldwin <jhb@FreeBSD.org>

Only align MSI message groups based on the number of messages being
allocated, not the maximum number of messages the device supports. The
spec only requires the former, and I believe I implemented the latter due
to misunderstanding an e-mail. In particular, this fixes an issue where
having several devices that all support 16 messages can run out of
IDT vectors on x86 even though the driver only uses a single message.

Submitted by: Bret Ketchum bcketchum of gmail
MFC after: 1 week


# a90dd577 31-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Explicitly track the state of all known BARs for each PCI device. The PCI
bus driver will now remember the size of a BAR obtained during the initial
bus scan and use that size when doing lazy resource allocation rather than
resizing the BAR. The bus driver will now also report unallocated BARs to
userland for display by 'pciconf -lb'. Psuedo-resources that are not BARs
(such as the implicit I/O port resources for master/slave ATA controllers)
will no longer be listed as BARs in 'pciconf -lb'. During resume, BARs are
restored from their new saved state instead of having the raw registers
saved and restored across resume. This also fixes restoring BARs at
unusual loactions if said BAR has been allocated by a driver.

Add a constant for the offset of the ROM BIOS BAR in PCI-PCI bridges and
properly handle ROM BIOS BARs in PCI-PCI bridges. The PCI bus now also
properly handles the lack of a ROM BIOS BAR in a PCI-Cardbus bridge.

Tested by: jkim


# e786cbfd 21-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Rename pci_find_extcap() to pci_find_cap(). PCI now uses the term
"extended capabilities" to refer to the new set of capability structures
starting at offset 0x100 in config space for PCI-express devices. For now
both function names will still work. I will merge this to older branches
to ease driver portability, but 9.0 will ship with a new pci_find_extcap()
function that locates extended capabilities instead.

Reviewed by: imp
MFC after: 1 week


# 54a03acb 18-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Partially revert previous change. Drop the quirk to disable MSI for HT
chipsets that do not have an HT slave at 0:0:0:0. The Linux quirk is
actually specific to Nvidia chipsets and the check I had added was in
the wrong place.

Prodded by: nathanw


# 8081bab7 17-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Fix a few issues with HyperTransport devices and MSI interrupts:
- Always enable the HyperTransport MSI mapping window for HyperTransport
to PCI bridges (these show up as HyperTransport slave devices).
The mapping windows in PCI-PCI bridges are enabled by existing code
in the PCI-PCI bridge driver as MSI requests propagate up the device
tree, but Host-PCI bridges don't really show up in that tree.
- If the PCI device at domain 0 bus 0 slot 0 function 0 is not a
HyperTransport device, then blacklist MSI on any other HT devices in
the system. Linux has a similar quirk.

PR: kern/155442
Tested by: Zack Dannar zdannar of gmail
MFC after: 1 week


# 6e2b68aa 22-Feb-2011 John Baldwin <jhb@FreeBSD.org>

Properly handle BARs bigger than 4G. The '1' was treated as an int
causing the size calculation to be truncated to the size of an int
(32-bits on all current architectures).

Submitted by: Anish akgupt3 of gmail
MFC after: 1 week


# bba39e10 13-Feb-2011 Marcel Moolenaar <marcel@FreeBSD.org>

Use the preload_fetch_addr() and preload_fetch_size() convenience
functions to obtain the address and size of the PCI vendor data.

Sponsored by: Juniper Networks.


# f68ff88c 22-Nov-2010 Jung-uk Kim <jkim@FreeBSD.org>

Resume critical PCI devices (and their children) first, then everything else
later. This give us better chance to catch device driver problems.


# 495ed64c 25-Oct-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

The EHCI_CAPLENGTH and EHCI_HCIVERSION registers are actually sub-registers
within the first 4 bytes of the EHCI memory space. For controllers that
use big-endian MMIO, reading them with 1- and 2-byte reads would then
return the wrong values. Instead, read the combined register with a 4-byte
read and mask out the interesting quantities.


# ba577448 22-Oct-2010 John Baldwin <jhb@FreeBSD.org>

- Add a new PCI quirk to whitelist an old chipset that doesn't support
PCI-express or PCI-X capabilities if we are running in a virtual machine.
- Whitelist the Intel 82440 chipset used by QEMU.

Tested by: jfv
MFC after: 1 week


# fb2439a6 21-Oct-2010 John Baldwin <jhb@FreeBSD.org>

Clarify a misleading comment. The test in pci_reserve_map() was meant to
ignore BARs that are invalid due to having a size of zero, not to ignore
BARs with an existing base of zero. While here, reorganize the code
slightly to make the intent clearer.

Reported by: avg
MFC after: 1 week


# d815d0ab 20-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Update PCI power management registers per PCI Bus Power Management Interface
Specification Rev. 1.2. Rename pp_pcmcsr field of PM capabilities to pp_bse
to avoid further confusions and adjust some comments accordingly. The real
PMCSR (Power Management Control/Status Register) is PCIR_POWER_STATUS and
it is actually BSE (PCI-to-PCI Bridge Support Extensions) register.


# f3e0b109 20-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Introduce a new tunable 'hw.pci.do_power_suspend'. This tunable lets you
avoid PCI power state transition from D0 to D3 for suspending case. Default
is 1 or enabled.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 6d018c85 19-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Remove PCI header type 0 restriction from power state changes. PCI config.
registers for bridges are saved and restored since r200341.

OK'ed by: imp, jhb


# b56b7525 19-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Do not apply do_power_resume for suspending case. When do_powerstate was
splitted into do_power_resume and do_power_nodriver, it became stale.


# debfe32c 15-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Remove unnecessary castings and fix couple of style(9) nits.


# 6e877573 15-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Move setting power state for children into a separate function as they were
essentially the same. This also restores hw.pci.do_power_resume tunable,
which was broken since r211430.

Reviewed by: jhb


# 62508c53 17-Aug-2010 John Baldwin <jhb@FreeBSD.org>

Add a new method to the PCI bridge interface, PCIB_POWER_FOR_SLEEP(). This
method is used by the PCI bus driver to query the power management system
to determine the proper device state to be used for a device during suspend
and resume. For the ACPI PCI bridge drivers this calls
acpi_device_pwr_for_sleep(). This removes ACPI-specific knowledge from
the PCI and PCI-PCI bridge drivers.

Reviewed by: jkim


# f39cf57f 29-Jul-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Consistently check header type after reading PCIR_HDRTYPE register.
While I'm here use defined macro instead of using magic numbers for
header type.

Reviewed by: jhb


# 93fc07b4 14-Jun-2010 Alexander Motin <mav@FreeBSD.org>

Virtualize pci_remap_msi_irq() call from general MSI code. It allows MSI
(FSB interrupts) to be used by non-PCI devices, such as HPET.


# 502a50e4 22-May-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

MFC r208149,208285:

Add support for the U4 PCI-Express bridge chipset used in late-generation
Powermac G5 systems. MSI and several other things are not presently
supported.

The U3/U4 internal device support portions of this change were contributed
by Andreas Tobler.


# 75f53851 21-May-2010 Alexander Motin <mav@FreeBSD.org>

Honor hw.pci.do_power_nodriver on resume. Power-down devices without
driver attached.


# ca2c1931 16-May-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Add support for the U4 PCI-Express bridge chipset used in late-generation
Powermac G5 systems. MSI and several other things are not presently
supported.

The U3/U4 internal device support portions of this change were contributed
by Andreas Tobler.

MFC after: 1 week


# e9fa4254 30-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

MFC rev 198431:
Have the early USB takeover only enabled for i386 and amd64
by default. This also avoids a panic on PowerPC.


# 210a19d0 19-Feb-2010 Alexander Motin <mav@FreeBSD.org>

MFC r203528:
Add pci_get|set_max_read_req() helper functions to control maximum PCIe
read request size.


# 24d6a5ed 05-Feb-2010 Alexander Motin <mav@FreeBSD.org>

Add pci_get|set_max_read_req() helper functions to control maximum PCIe
read request size.

Reviewed by: jhb@


# af827f96 05-Jan-2010 John Baldwin <jhb@FreeBSD.org>

Move the PCI-specific logic of removing a cardbus device into a
pci_delete_child() function called by the cardbus driver. The new function
uses resource_list_unreserve() to release the BARs decoded by the device
being removed.

Reviewed by: imp
Tested by: brooks


# 4e8790e9 30-Dec-2009 John Baldwin <jhb@FreeBSD.org>

Teach the PCI bus driver to handle PCIR_BIOS BARs properly and remove special
handling for the PCIR_BIOS decoding enable bit from the cardbus driver.
The PCIR_BIOS BAR does include type bits like other BARs. Instead, it is
always a 32-bit non-prefetchable memory BAR where the low bit is used as a
flag to enable decoding.

Reviewed by: imp


# 1280c119 30-Dec-2009 John Baldwin <jhb@FreeBSD.org>

Remove no longer used pci_release_resource().


# e36af292 09-Dec-2009 Jung-uk Kim <jkim@FreeBSD.org>

Implement a rudimentary suspend/resume methods for PCI P2P bridge.

Reviewed by: jhb, imp


# fd29c5e0 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199814

Disable interrupts after doing early takeover of the usb controller in case usb
isnt actually compiled in (or kldloaded) as the controller could cause spurious
interrupts.


# 42a346fa 09-Dec-2009 John Baldwin <jhb@FreeBSD.org>

For some buses, devices may have active resources assigned even though they
are not allocated by the device driver. These resources should still appear
allocated from the system's perspective so that their assigned ranges are
not reused by other resource requests. The PCI bus driver has used a hack
to effect this for a while now where it uses rman_set_device() to assign
devices to the PCI bus when they are first encountered and later assigns
them to the actual device when a driver allocates a BAR. A few downsides of
this approach is that it results in somewhat confusing devinfo -r output as
well as not being very easily portable to other bus drivers.

This commit adds generic support for "reserved" resources to the resource
list API used by many bus drivers to manage the resources of child devices.
A resource may be reserved via resource_list_reserve(). This will allocate
the resource from the bus' parent without activating it.
resource_list_alloc() recognizes an attempt to allocate a reserved resource.
When this happens it activates the resource (if requested) and then returns
the reserved resource. Similarly, when a reserved resource is released via
resource_list_release(), it is deactivated (if it is active) and the
resource is then marked reserved again, but is left allocated from the
bus' parent. To completely remove a reserved resource, a bus driver may
use resource_list_unreserve(). A bus driver may use resource_list_busy()
to determine if a reserved resource is allocated by a child device or if
it can be unreserved.

The PCI bus driver has been changed to use this framework instead of
abusing rman_set_device() to keep track of reserved vs allocated resources.

Submitted by: imp (an older version many moons ago)
MFC after: 1 month


# e6af527c 25-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

Disable interrupts after doing early takeover of the usb controller in case usb
isnt actually compiled in (or kldloaded) as the controller could cause spurious
interrupts.

Tested by: Florian Smeets


# 1ea6a20c 29-Oct-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r198151

Workaround buggy BIOS code in USB regard. By doing the BIOS to OS handover for
all host controllers at the same time, we avoid problems where the BIOS will
actually write to the USB registers of all the USB host controllers every time
we handover one of them, and consequently reset the OS programmed values.


# d6eb44c8 23-Oct-2009 Marcel Moolenaar <marcel@FreeBSD.org>

BIOSes, buggy or otherwise, are i386 or amd64 specific.
Have the early USB takeover enabled for i386 and amd64
by default.
This also avoids a panic on PowerPC where the resource
isn't released properly and we find a busy resource
when the USB host controller wants to allocate it...


# 1def609a 15-Oct-2009 Andrew Thompson <thompsa@FreeBSD.org>

Workaround buggy BIOS code in USB regard. By doing the BIOS to OS handover for
all host controllers at the same time, we avoid problems where the BIOS will
actually write to the USB registers of all the USB host controllers every time
we handover one of them, and consequently reset the OS programmed values.

Submitted by: avg
Reviewed by: jhb


# b10d205d 25-Sep-2009 John Baldwin <jhb@FreeBSD.org>

MFC 197406:
Don't reread the command register to see if enabling I/O or memory
decoding "took". Other OS's that I checked do not do this and it breaks
some amdpm(4) devices. Prior to 7.2 we did not honor the error returned
when this failed anyway, so this in effect restores previous behavior.

Approved by: re (kib)


# ce95033d 22-Sep-2009 John Baldwin <jhb@FreeBSD.org>

Don't reread the command register to see if enabling I/O or memory
decoding "took". Other OS's that I checked do not do this and it breaks
some amdpm(4) devices. Prior to 7.2 we did not honor the error returned
when this failed anyway, so this in effect restores previous behavior.

PR: kern/137668
Tested by: Aurelien Mere aurelien.mere amc-os.com
MFC after: 3 days


# fada2a86 21-Jul-2009 Marius Strobl <marius@FreeBSD.org>

Add a MD __PCI_BAR_ZERO_VALID which denotes that BARs containing 0
actually specify valid bases that should be treated just as normal.
The PCI specifications have no indication that 0 would be a magic value
indicating a disabled BAR as commonly used on at least amd64 and i386
but not sparc64. It's unclear what to do in pci_delete_resource()
instead of writing 0 to a BAR though as there's no (other) way do
disable individual BARs so its decoding is left enabled in case of
__PCI_BAR_ZERO_VALID for now.

Approved by: re (kib), jhb
MFC after: 1 week


# d456f534 22-Jun-2009 John Baldwin <jhb@FreeBSD.org>

Enable MSI in the MSI capability registers any time that the first message
in an MSI group is enabled, not just if the address/data pair are not
initialized.

Reported by: rnoland
MFC after: 1 week


# 129d3046 05-Jun-2009 Jung-uk Kim <jkim@FreeBSD.org>

Import ACPICA 20090521.


# aaac7452 02-Jun-2009 Jung-uk Kim <jkim@FreeBSD.org>

Chase ACPICA API changes (for kernel and boot loader).


# 11632ace 01-Jun-2009 John Baldwin <jhb@FreeBSD.org>

Include <machine/stdarg.h> for va_*(). I'm not sure how this compiled
on amd64 without this.


# 287078dd 01-Jun-2009 John Baldwin <jhb@FreeBSD.org>

Add an internal pci_printf() routine similar to device_printf() except
that it prefixes the output with 'pci<domain>:<bus>:<device>:<function>: '.


# 89c81b88 20-May-2009 Warner Losh <imp@FreeBSD.org>

Revert junk from last commit. These are WIP and not ready (and don't
match the description of the last commit).


# 00b4e54a 20-May-2009 Warner Losh <imp@FreeBSD.org>

We no longer need to use d_thread_t, migrate to struct thread *.


# bfee0576 14-Apr-2009 John Baldwin <jhb@FreeBSD.org>

- Consolidate duplicated code for reading and sizing BARs and writing base
addresses to BARs into new pci_read_bar() and pci_write_bar() routines.
pci_add_map(), pci_alloc_map(), and pci_delete_resource() now use these
routines to work with BARs.
- Just pass the device_t for the new PCI device to various routines instead
of passing the device, bus, slot, and function.

Reviewed by: imp


# c1304399 03-Apr-2009 Stanislav Sedov <stas@FreeBSD.org>

- Fix spacing in the comment.

Reported by: jhb


# 3dc489ee 03-Apr-2009 Stanislav Sedov <stas@FreeBSD.org>

- Correct the comment.

MFC after: 3 days


# d175be46 10-Mar-2009 Marcel Moolenaar <marcel@FreeBSD.org>

Fix a buglet in revision 189401: when restoring a 64-bit BAR,
write the upper 32-bits in the adjacent bar. The consequences
of the buglet were severe enough though: a machine check.


# 41b3a232 06-Mar-2009 Robert Noland <rnoland@FreeBSD.org>

Invert the logic error for the MSI/MSIX vs INTx case.

Pointyhat to: me

MFC after: 3 days


# c4e8c9df 05-Mar-2009 John Baldwin <jhb@FreeBSD.org>

Always read/write the full 64-bit value of 64-bit BARs. Specifically,
when determining the size of a BAR by writing all 1's to the BAR and
reading back the result, always operate on the full 64-bit size.

Reviewed by: imp
MFC after: 1 month


# d004885d 05-Mar-2009 John Baldwin <jhb@FreeBSD.org>

Honor the prefetchable flag in memory BARs by setting the RF_PREFETCHABLE
flag when calling bus_alloc_resource() to allocate resources from a parent
PCI bridge. For PCI-PCI bridges this asks the bridge to satisfy the
request using the prefetchable memory range rather than the normal
memory range.

Reviewed by: imp
Reported by: scottl
MFC after: 1 week


# a9f33b97 04-Mar-2009 Robert Noland <rnoland@FreeBSD.org>

Extend the management of PCIM_CMD_INTxDIS.

We now explicitly enable INTx during bus_setup_intr() if it is needed.
Several of the ata drivers were managing this bit internally. This is
better handled in pci and it should work for all drivers now.

We also mask INTx during bus_teardown_intr() by setting this bit.

Reviewed by: jhb
MFC after: 3 days


# 6b0ff427 03-Mar-2009 John Baldwin <jhb@FreeBSD.org>

Further refine the handling of resources for BARs in the PCI bus driver.

A while back, Warner changed the PCI bus code to reserve resources when
enumerating devices and simply give devices the previously allocated
resources when they call bus_alloc_resource(). This ensures that address
ranges being decoded by a BAR are always allocated in the nexus0 device
(or whatever device the PCI bus gets its address space from) even if a
device driver is not attached to the device. This patch extends this
behavior further:
- To let the PCI bus distinguish between a resource being allocated by
a device driver vs. merely being allocated by the bus, use
rman_set_device() to assign the device to the bus when it is owned
by the bus and to the child device when it is allocated by the child
device's driver. We can now prevent a device driver from allocating
the same device twice. Doing so could result in odd things like
allocating duplicate virtual memory to map the resource on some
archs and leaking the original mapping.
- When a PCI device driver releases a resource, don't pass the request
all the way up the tree and release it in the nexus (or similar device)
since the BAR is still active and decoding. Otherwise, another device
could later allocate the same range even though it is still in use.
Instead, deactivate the resource and assign it back to the PCI bus
using rman_set_device().
- pci_delete_resource() will actually completely free a BAR including
attemping to disable it.
- Disable BAR decoding via the command register when sizing a BAR in
pci_alloc_map() which is used to allocate resources for a BAR when
the BIOS/firmware did not assign a usable resource range during boot.
This mirrors an earlier fix to pci_add_map() which is used when to
size BARs during boot.
- Move the activation of I/O decoding in the PCI command register into
pci_activate_resource() instead of doing it in pci_alloc_resource().
Previously we could actually enable decoding before a BAR was
initialized via pci_alloc_map().

Glanced at by: bsdimp


# 5884a846 02-Mar-2009 Robert Noland <rnoland@FreeBSD.org>

Disable INTx when enabling MSI/MSIX

This addresses interrupt storms that were noticed after enabling MSI
in drm. I think this is due to a loose interpretation of the PCI 2.3
spec, which states that a function using MSI is prohibitted from using
INTx. It appears that some vendors interpretted that to mean that they
should handle it in hardware, while others felt it was the drivers
responsibility.

This fix will also likely resolve interrupt storm related issues with
devices other than drm.

Reviewed by: jhb@
MFC after: 3 days


# 34a839f1 26-Feb-2009 John Baldwin <jhb@FreeBSD.org>

Don't throw away upper 32-bits of the HT MSI address window. In practice
this is harmless since the address window for MSI on x86 is in the lower
4 GB.

Submitted by: mav
MFC after: 1 week


# f5a78b2f 19-Jan-2009 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Change the probe priority for PCI and I2C generic bus modules from
numerical constants to BUS_PROBE_GENERIC.

Suggested by: jhb


# 589d604b 16-Jan-2009 John Baldwin <jhb@FreeBSD.org>

Disable decoding of BARs by devices before we trash the value in the BAR
by writing all 1's to it to determine its length. This fixes issues with
MCFG on at least some machines where a trashed BAR claimed subsequent
attempts at PCI config transactions because the addresses in the MCFG
window fell in the decoding range of the BAR.

In general it is a bad idea to leave the BARs enabled while we are
frobbing with them in this manner.

Sleuthing by: tegge
MFC after: 1 week


# 2e013ce0 13-Nov-2008 Alexander Motin <mav@FreeBSD.org>

Add ADMA, SATA and SAS mass storage subclasses reporting.


# c5343d09 21-Oct-2008 Alexander Motin <mav@FreeBSD.org>

Add HDA multimedia subclass.


# a9217b5f 21-Oct-2008 Alexander Motin <mav@FreeBSD.org>

Add "SD host controller" subclass name.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 696771ee 23-Aug-2008 Warner Losh <imp@FreeBSD.org>

Cope with errors from device_get_children(). These errors can happen
only in low memory situations, so the error fork of these fixes is
lightly tested, but they should do the least-wrong thing...

Submitted by: Hans Petter Selasky


# de5d443f 23-Aug-2008 Warner Losh <imp@FreeBSD.org>

Cosmetic nit.


# e33abcc5 08-Aug-2008 Warner Losh <imp@FreeBSD.org>

Change -1 to 0xfffffffful since the interface returns uint32_t.


# 73492bc0 05-Aug-2008 John Baldwin <jhb@FreeBSD.org>

Remove the second check for a 64-bit BAR value on a 32-bit system in
pci_add_map(). First, this condition is already handled earlier in
the function. Second, as written the check would never fire as the
'start' value was overwritten with a long value (rman_get_start() returns
long) before the comparison was done.

Discussed with: imp
MFC after: 2 weeks


# e29bfa9e 05-Aug-2008 John Baldwin <jhb@FreeBSD.org>

If the kernel fails to allocate resources for the initial value of a BAR
for a PCI device during the boot-time probe of the parent PCI bus, then
zero the BAR and clear the resource list entry for that BAR. This forces
the PCI bus driver to request a valid resource range from the parent bridge
driver when the device driver tries to allocate the BAR. Similarly, if the
initial value of a BAR is a valid range but it is > 4GB and the current OS
only has 32-bit longs, then do a full teardown of the initial value of the
BAR to force a reallocation.

Reviewed by: imp
MFC after: 1 week


# 4522ac77 23-Jul-2008 Luoqi Chen <luoqi@FreeBSD.org>

SATA device on some nForce based boards could get confused if MSI is not
used but MSI to HyperTransport IRQ mapping is enabled, and would act as
if MSI is turned on, resulting in interrupt loss.

This commit will,
1. enable MSI mapping on a device only when MSI is enabled for that
device and the MSI address matches the HT mapping window.
2. enable MSI mapping on a bridge only when a downstream device is
allocated an MSI address in the mapping window

PR: kern/118842
Reviewed by: jhb
MFC after: 1 week


# 138e8d08 01-Feb-2008 John Baldwin <jhb@FreeBSD.org>

Relax the check for a PCI-express chipset by assuming the system is a
PCI-express chipset (and thus has functional MSI) if there are any
PCI-express devices in the system, not requiring a root port device.

With PCI-X the chipset detection has to be very conservative because there
are known systems with PCI-X devices that do not appear to have PCI-X
chipsets. However, with PCI-express I'm not sure it is possible to have
a PCI-express device in a system with a non-PCI-express chipset. If we
assume that is the case then this change is valid. It is also required
for at least some PCI-express systems that don't have any devices with
a root port capability (some ICH9 systems).

MFC after: 1 week
Reported by: jfv


# 4ea603ec 16-Nov-2007 Jung-uk Kim <jkim@FreeBSD.org>

Make VPD register access more robust:

- Implement timing out of VPD register access.[1]
- Fix an off-by-one error of freeing malloc'd space when checksum is invalid.
- Fix style(9) bugs, i.e., sizeof cannot be followed by space.
- Retire now obsolete 'hw.pci.enable_vpd' tunable.

Submitted by: cokane (initial revision)[1]
Reviewed by: marius (intermediate revision)
Silence from: jhb, jmg, rwatson
Tested by: cokane, jkim
MFC after: 3 days


# 55aaf894 30-Sep-2007 Marius Strobl <marius@FreeBSD.org>

Make the PCI code aware of PCI domains (aka PCI segments) so we can
support machines having multiple independently numbered PCI domains
and don't support reenumeration without ambiguity amongst the
devices as seen by the OS and represented by PCI location strings.
This includes introducing a function pci_find_dbsf(9) which works
like pci_find_bsf(9) but additionally takes a domain number argument
and limiting pci_find_bsf(9) to only search devices in domain 0 (the
only domain in single-domain systems). Bge(4) and ofw_pcibus(4) are
changed to use pci_find_dbsf(9) instead of pci_find_bsf(9) in order
to no longer report false positives when searching for siblings and
dupe devices in the same domain respectively.
Along with this change the sole host-PCI bridge driver converted to
actually make use of PCI domain support is uninorth(4), the others
continue to use domain 0 only for now and need to be converted as
appropriate later on.
Note that this means that the format of the location strings as used
by pciconf(8) has been changed and that consumers of <sys/pciio.h>
potentially need to be recompiled.

Suggested by: jhb
Reviewed by: grehan, jhb, marcel
Approved by: re (kensmith), jhb (PCI maintainer hat)


# 7f67bed6 28-Jul-2007 Marcel Moolenaar <marcel@FreeBSD.org>

In pci_alloc_map(), restore the original value of the BAR for
the duration of the function. The device we would otherwise
have left in an useless state may just as well be the low-level
console. When booting verbose, we do need it addressable if we
want to avoid a MCA.

Approved by: re (kensmith)


# 81c8102c 16-May-2007 John Baldwin <jhb@FreeBSD.org>

Don't completely skip pci_cfg_save() in the PCI nomatch routine if
the power_nodriver tunable is off. pci_cfg_save() already checks the
tunable internally, and no other callers of pci_cfg_save() check the
tunable.

Reviewed by: imp


# f1182514 07-May-2007 John Baldwin <jhb@FreeBSD.org>

Fix a typo in a bootverbose printf.

MFC after: 3 days
Submitted by: yongari


# e706f7f0 02-May-2007 John Baldwin <jhb@FreeBSD.org>

Revamp the MSI/MSI-X code a bit to achieve two main goals:
- Simplify the amount of work that has be done for each architecture by
pushing more of the truly MI code down into the PCI bus driver.
- Don't bind MSI-X indicies to IRQs so that we can allow a driver to map
multiple MSI-X messages into a single IRQ when handling a message
shortage.

The changes include:
- Add a new pcib_if method: PCIB_MAP_MSI() which is called by the PCI bus
to calculate the address and data values for a given MSI/MSI-X IRQ.
The x86 nexus drivers map this into a call to a new 'msi_map()' function
in msi.c that does the mapping.
- Retire the pcib_if method PCIB_REMAP_MSIX() and remove the 'index'
parameter from PCIB_ALLOC_MSIX(). MD code no longer has any knowledge
of the MSI-X index for a given MSI-X IRQ.
- The PCI bus driver now stores more MSI-X state in a child's ivars.
Specifically, it now stores an array of IRQs (called "message vectors" in
the code) that have associated address and data values, and a small
virtual version of the MSI-X table that specifies the message vector
that a given MSI-X table entry uses. Sparse mappings are permitted in
the virtual table.
- The PCI bus driver now configures the MSI and MSI-X address/data
registers directly via custom bus_setup_intr() and bus_teardown_intr()
methods. pci_setup_intr() invokes PCIB_MAP_MSI() to determine the
address and data values for a given message as needed. The MD code
no longer has to call back down into the PCI bus code to set these
values from the nexus' bus_setup_intr() handler.
- The PCI bus code provides a callout (pci_remap_msi_irq()) that the MD
code can call to force the PCI bus to re-invoke PCIB_MAP_MSI() to get
new values of the address and data fields for a given IRQ. The x86
MSI code uses this when an MSI IRQ is moved to a different CPU, requiring
a new value of the 'address' field.
- The x86 MSI psuedo-driver loses a lot of code, and in fact the separate
MSI/MSI-X pseudo-PICs are collapsed down into a single MSI PIC driver
since the only remaining diff between the two is a substring in a
bootverbose printf.
- The PCI bus driver will now restore MSI-X state (including programming
entries in the MSI-X table) on device resume.
- The interface for pci_remap_msix() has changed. Instead of accepting
indices for the allocated vectors, it accepts a mini-virtual table
(with a new length parameter). This table is an array of u_ints, where
each value specifies which allocated message vector to use for the
corresponding MSI-X message. A vector of 0 forces a message to not
have an associated IRQ. The device may choose to only use some of the
IRQs assigned, in which case the unused IRQs must be at the "end" and
will be released back to the system. This allows a driver to use the
same remap table for different shortage values. For example, if a driver
wants 4 messages, it can use the same remap table (which only uses the
first two messages) for the cases when it only gets 2 or 3 messages and
in the latter case the PCI bus will release the 3rd IRQ back to the
system.

MFC after: 1 month


# 361cf3bd 02-May-2007 John Baldwin <jhb@FreeBSD.org>

Use more specific local variable pointers to narrow some expressions.

MFC after: 1 week


# d68b1825 25-Apr-2007 John Baldwin <jhb@FreeBSD.org>

- HT 2.00b added a new flag to the MSI mapping HT capability to indicate
that the MSI mapping window is fixed at 0xfee00000 and the capability
does not include two more dwords used to program the address. Supporting
this mostly results in quieting spurious warnings during boot about
non-default MSI mapping windows.
- HT 2.00b also added a new HT capability type, so support that in pciconf.

MFC after: 3 days
Tested by: jmg


# 4dc5078f 31-Mar-2007 John Baldwin <jhb@FreeBSD.org>

Add constants for the fields in a BAR. Also, add two new macros
PCI_BAR_(IO|MEM)() that return true if the passed in value from a BAR
is for an IO or memory BAR, respectively.

Reviewed by: imp


# 657d9f9f 31-Mar-2007 John Baldwin <jhb@FreeBSD.org>

- Add missing constants for subclasses.
- Add a few progif constants as well.


# b2bfac4c 26-Mar-2007 John Baldwin <jhb@FreeBSD.org>

Change the VPD code to read the VPD data on-demand when a driver asks for
it via pci_get_vpd_*() rather than always reading it for each device during
boot. I've left the tunable so that it can still be turned off if a device
driver causes a lockup via a query to a broken device, but devices whose
drivers do not use VPD (the vast majority) should no longer result in
lockups during boot, and most folks should not need to tweak the tunable
now.

Tested on: bge(4)
Silence from: jmg


# d8a4c26c 05-Mar-2007 John Baldwin <jhb@FreeBSD.org>

- Use constants for VPD capability register offsets.
- Add missing ()'s around return values.


# cfaed55f 17-Feb-2007 Søren Schmidt <sos@FreeBSD.org>

Add support for chipsets that has NULL'd BAR's for legacy ports.
This allows DMA to be used on a fine little geode system I got here and
most like on lots of older systems like that.

HW donated by: Paul Ghering


# f13fc7c8 14-Feb-2007 John Baldwin <jhb@FreeBSD.org>

Adjust the global MSI blacklisting strategy so we don't have to explicitly
blacklist a bunch of old chipsets. If a system contains a PCI-PCI bridge
that supports PCI-X, assume the chipset supports PCI-X. If a system
contains a PCI-express root port, assume the chipset supports PCI-express.
If the chipset doesn't support either PCI-X or PCI-express, then blacklist
it by default. We should now only need to explicitly blacklist PCI-X or
PCI-express chipsets that don't properly handle MSI.


# ea3f5083 14-Feb-2007 John Baldwin <jhb@FreeBSD.org>

- Fix an off by one error in pci_remap_msix_method() that effectively
broke the method as all the MSI-X table indices were off by one in
the backend MD code.
- Fix a cosmetic nit in the bootverbose printf in pci_alloc_msix_method().


# 8474d26b 14-Feb-2007 John Baldwin <jhb@FreeBSD.org>

Add missing 'break' that in this case is harmless.


# 7222b402 08-Feb-2007 Robert Watson <rwatson@FreeBSD.org>

As VPD support still causes hard hangs on boot with some hardware, add a
tunable allowing automatic parsing of VPD data to be disabled. The
default is left as-is; if you are having problems with hard hangs at boot
due to VPD, try setting hw.pci.enable_vpd=0. A proper architectural
solution has been under discussion for some time, but this allows me to
boot my test machines in the mean time.

Submitted by: bz
Head nod: jmg


# 5fe82bca 22-Jan-2007 John Baldwin <jhb@FreeBSD.org>

Expand the MSI/MSI-X API to address some deficiencies in the MSI-X support.
- First off, device drivers really do need to know if they are allocating
MSI or MSI-X messages. MSI requires allocating powerof2() messages for
example where MSI-X does not. To address this, split out the MSI-X
support from pci_msi_count() and pci_alloc_msi() into new driver-visible
functions pci_msix_count() and pci_alloc_msix(). As a result,
pci_msi_count() now just returns a count of the max supported MSI
messages for the device, and pci_alloc_msi() only tries to allocate MSI
messages. To get a count of the max supported MSI-X messages, use
pci_msix_count(). To allocate MSI-X messages, use pci_alloc_msix().
pci_release_msi() still handles both MSI and MSI-X messages, however.
As a result of this change, drivers using the existing API will only
use MSI messages and will no longer try to use MSI-X messages.
- Because MSI-X allows for each message to have its own data and address
values (and thus does not require all of the messages to have their
MD vectors allocated as a group), some devices allow for "sparse" use
of MSI-X message slots. For example, if a device supports 8 messages
but the OS is only able to allocate 2 messages, the device may make the
best use of 2 IRQs if it enables the messages at slots 1 and 4 rather
than default of using the first N slots (or indicies) at 1 and 2. To
support this, add a new pci_remap_msix() function that a driver may call
after a successful pci_alloc_msix() (but before allocating any of the
SYS_RES_IRQ resources) to allow the allocated IRQ resources to be
assigned to different message indices. For example, from the earlier
example, after pci_alloc_msix() returned a value of 2, the driver would
call pci_remap_msix() passing in array of integers { 1, 4 } as the
new message indices to use. The rid's for the SYS_RES_IRQ resources
will always match the message indices. Thus, after the call to
pci_remap_msix() the driver would be able to access the first message
in slot 1 at SYS_RES_IRQ rid 1, and the second message at slot 4 at
SYS_RES_IRQ rid 4. Note that the message slots/indices are 1-based
rather than 0-based so that they will always correspond to the rid
values (SYS_RES_IRQ rid 0 is reserved for the legacy INTx interrupt).
To support this API, a new PCIB_REMAP_MSIX() method was added to the
pcib interface to change the message index for a single IRQ.

Tested by: scottl


# abc007f0 16-Jan-2007 John Baldwin <jhb@FreeBSD.org>

Disable MSI for the Intel 845 and 865 chipsets and update comment for
E7210 to note it is the same devid as the 875 chipset.


# 8bbeb212 16-Jan-2007 John Baldwin <jhb@FreeBSD.org>

Fix the subvendor ID for PCI-PCI bridges.
- Retire the PCI_SUB*_1 constants and don't try to read a subvendor ID out
of them. There isn't a standard subvendor ID field for PCI-PCI bridges.
Instead, the dword at offset 0x34 is actually mostly reserved except for
the LSB which is the capabilities pointer.
- Add support for the PCI-PCI bridge subvendor ID capability (13) and use
it to set the subvendor ID for PCI-PCI bridges.

MFC after: 1 month


# 22bf1c7f 12-Jan-2007 John Baldwin <jhb@FreeBSD.org>

- Add a new flag to the PCI-PCI driver to disable MSI on devices behind the
bridge if it doesn't pass MSI messages up correctly. We set the flag
in pcib_attach() if the device ID is disabled via a PCI quirk.
- Disable MSI for devices behind the AMD 8131 HT-PCIX bridge. Linux has
the same quirk.

Tested by: no one despite repeated calls for testers


# 77312b56 12-Jan-2007 John Baldwin <jhb@FreeBSD.org>

Disable MSI for two ServerWorks chipsets. The first is based on a user
report. The second is blacklisted in Linux.


# 854923ae 12-Jan-2007 John Baldwin <jhb@FreeBSD.org>

Blacklist a few more Intel chipsets re: MSI based on user reports:
E7500 and 855.


# af07bd56 12-Jan-2007 John Baldwin <jhb@FreeBSD.org>

- Condense the comment for Intel chipset MSI blacklist entries.
- Blacklist the E7210.

PR: kern/105768 (2)
Reported by: marcus (2)


# 9d1f363d 27-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Disable MSI on the Intel E7505 chipset. It is reported broken on a Tyan
S2665ANF motherboard.

Reported by: "Eugene M. Kim" <blue at white lv>


# cc4f30e1 14-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Disable MSI for the Intel E7501 chipset.

Reported by: jdp


# e31182d9 14-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Add a first pass at a way to blacklist MSI on systems where it doesn't
work:
- A new PCI quirk (PCI_QUIRK_DISABLE_MSI) is added to the quirk table.
- A new pci_msi_device_blacklisted() determines if a passed in device
matches an MSI quirk in the quirk table. This can be overridden (all
quirks ignored) by setting the hw.pci.honor_msi_blacklist to 0.
- A global blacklist check is performed in the MI PCI bus code by checking
to see if the device at 0:0:0 is blacklisted.

Tested by: jdp


# 2bbf9462 14-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Replace #define<space> with #define<tab> so the code is consistent with
style(9) and avoids mixing the two formats.


# 3dcca303 12-Dec-2006 John Baldwin <jhb@FreeBSD.org>

- Add constants for HT PCI capability registers including the various
subtypes of HT capabilities.
- Add constants for the MSI mapping window HT PCI capability.
- On i386 and amd64, enable the MSI mapping window on any HT bridges we
encounter and report any non-standard mapping window addresses.


# 0003a3f0 12-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Give the WREG() macro the same lifetime as the REG() macro.


# 31075693 12-Dec-2006 John Baldwin <jhb@FreeBSD.org>

Add some bootverbose printf's to detail how many MSI messages are allocated
and to which IRQs.

Requested by: scottl


# b318e849 20-Nov-2006 John-Mark Gurney <jmg@FreeBSD.org>

don't mark the cksum as invalid here... off is incorrect when we get
here, it's either unset, or it's valid, so we don't need to do anything
different...

Reported by: Neterion (via rwatson)


# 3bea4efe 16-Nov-2006 John Baldwin <jhb@FreeBSD.org>

Look for capabilities in PCI-PCI bridges using the same CAP PTR register
as for type 0 devices.

Submitted by: grehan
MFC after: 1 week


# 9bf4c9c1 13-Nov-2006 John Baldwin <jhb@FreeBSD.org>

First cut at MI support for PCI Message Signalled Interrupts (MSI):
- Add 3 new functions to the pci_if interface along with suitable wrappers
to provide the device driver visible API:
- pci_alloc_msi(dev, int *count) backed by PCI_ALLOC_MSI(). '*count'
here is an in and out parameter. The driver stores the desired number
of messages in '*count' before calling the function. On success,
'*count' holds the number of messages allocated to the device. Also on
success, the driver can access the messages as SYS_RES_IRQ resources
starting at rid 1. Note that the legacy INTx interrupt resource will
not be available when using MSI. Note that this function will allocate
either MSI or MSI-X messages depending on the devices capabilities and
the 'hw.pci.enable_msix' and 'hw.pci.enable_msi' tunables. Also note
that the driver should activate the memory resource that holds the
MSI-X table and pending bit array (PBA) before calling this function
if the device supports MSI-X.
- pci_release_msi(dev) backed by PCI_RELEASE_MSI(). This function
releases the messages allocated for this device. All of the
SYS_RES_IRQ resources need to be released for this function to succeed.
- pci_msi_count(dev) backed by PCI_MSI_COUNT(). This function returns
the maximum number of MSI or MSI-X messages supported by this device.
MSI-X is preferred if present, but this function will honor the
'hw.pci.enable_msix' and 'hw.pci.enable_msi' tunables. This function
should return the largest value that pci_alloc_msi() can return
(assuming the MD code is able to allocate sufficient backing resources
for all of the messages).
- Add default implementations for these 3 methods to the pci_driver generic
PCI bus driver. (The various other PCI bus drivers such as for ACPI and
OFW will inherit these default implementations.) This default
implementation depends on 4 new pcib_if methods that bubble up through
the PCI bridges to the MD code to allocate IRQ values and perform any
needed MD setup code needed:
- PCIB_ALLOC_MSI() attempts to allocate a group of MSI messages.
- PCIB_RELEASE_MSI() releases a group of MSI messages.
- PCIB_ALLOC_MSIX() attempts to allocate a single MSI-X message.
- PCIB_RELEASE_MSIX() releases a single MSI-X message.
- Add default implementations for these 4 methods that just pass the
request up to the parent bus's parent bridge driver and use the
default implementation in the various MI PCI bridge drivers.
- Add MI functions for use by MD code when managing MSI and MSI-X
interrupts:
- pci_enable_msi(dev, address, data) programs the MSI capability address
and data registers for a group of MSI messages
- pci_enable_msix(dev, index, address, data) initializes a single MSI-X
message in the MSI-X table
- pci_mask_msix(dev, index) masks a single MSI-X message
- pci_unmask_msix(dev, index) unmasks a single MSI-X message
- pci_pending_msix(dev, index) returns true if the specified MSI-X
message is currently pending
- Save the MSI capability address and data registers in the pci_cfgreg
block in a PCI devices ivars and restore the values when a device is
resumed. Note that the MSI-X table is not currently restored during
resume.
- Add constants for MSI-X register offsets and fields.
- Record interesting data about any MSI-X capability blocks we come
across in the pci_cfgreg block in the ivars for PCI devices.

Tested on: em (i386, MSI), bce (amd64/i386, MSI), mpt (amd64, MSI-X)
Reviewed by: scottl, grehan, jfv
MFC after: 2 months


# ee03a332 09-Nov-2006 John-Mark Gurney <jmg@FreeBSD.org>

fix hanging on invalid data... (This doesn't fix hanging due to broken
hardware)...

Tested by: Ian Dowse, Adam K Kirchhoff and Vladimir Kushnir


# d6592688 07-Nov-2006 John Baldwin <jhb@FreeBSD.org>

Various whitespace cleanups.


# 8e6c8e8c 03-Nov-2006 Warner Losh <imp@FreeBSD.org>

Doh! Actually commit checking against NULL for res.

Noticed by: dougb@


# a12fb4e6 30-Oct-2006 Warner Losh <imp@FreeBSD.org>

Assign start to the value we were able to allocate and use that to
write out the BAR. Otherwise, we were trying to shift a 32-bit
quantity on 32-bit platforms. Also, 'start' check sanity to where it
is known.


# b0a2d4b8 30-Oct-2006 Warner Losh <imp@FreeBSD.org>

More fully support 64-bit bars. Prior to this commit, we supported
only those bars that had addresses assigned by the BIOS and where the
bridges were properly programmed. Now even unprogrammed ones work.
This was needed for sun4v. We still only implement up to 2GB memory
ranges, even for 64-bit bars. PCI standards at least through 2.2 say
that this is the max (or 1GB is, I only know it is < 32bits).

o Always define pci_addr_t as uint64_t. A pci address is always 64-bits,
but some hosts can't address all of them.
o Preserve the upper half of the 64-bit word during resource probing.
o Test to make sure that 64-bit values can fit in a u_long (true on some
platforms, but not others). Don't use those that can't.
o minor pedantry about data sizes.
o Better bridge resource reporting in bootverbose case.
o Minor formatting changes to cope with different data types on different
platforms.

Submitted by: jmg, with many changes by me to fully support 64-bit
addresses.


# 8946c282 20-Oct-2006 John-Mark Gurney <jmg@FreeBSD.org>

fix tab indentation for CP and RV...

If the length is zero, catch this early, instead of making dflen go negative
and letting bad things happen... We also check to see if RV (checksum) is
0, and handle that has a checksum failure...

Properly handle checksum failures by not processing read-write VPD data,
and removing all the found read-only data...

Tested by: oleg (dflen going negative)


# 667dc26e 09-Oct-2006 John-Mark Gurney <jmg@FreeBSD.org>

provide routines to access VPD data at the PCI layer...

remove sk's own implementation, and use the new calls to get the data...

Reviewed by: -arch


# b70c1daf 20-Sep-2006 John-Mark Gurney <jmg@FreeBSD.org>

spell PCIS_CRYPTO_ENTERTAIN properly...

MFC after: 3 days


# 19e9205a 12-Jul-2006 John Baldwin <jhb@FreeBSD.org>

Simplify the pager support in DDB. Allowing different db commands to
install custom pager functions didn't actually happen in practice (they
all just used the simple pager and passed in a local quit pointer). So,
just hardcode the simple pager as the only pager and make it set a global
db_pager_quit flag that db commands can check when the user hits 'q' (or a
suitable variant) at the pager prompt. Also, now that it's easy to do so,
enable paging by default for all ddb commands. Any command that wishes to
honor the quit flag can do so by checking db_pager_quit. Note that the
pager can also be effectively disabled by setting $lines to 0.

Other fixes:
- 'show idt' on i386 and pc98 now actually checks the quit flag and
terminates early.
- 'show intr' now actually checks the quit flag and terminates early.


# 70bc2d3f 11-May-2006 John Baldwin <jhb@FreeBSD.org>

Fixup some comments to allow for the fact that PCI domains are not specific
to Alpha hoses.


# d95bd0c3 26-Apr-2006 Marcel Moolenaar <marcel@FreeBSD.org>

The size of I/O ranges can be anything from 16 bytes to 2G bytes.
Lower the minimum for memory mapped I/O from 32 bytes to 16 bytes.
This fixes bus enumeration on ia64 now that the Diva auxiliary
serial port is attached to.


# 5aa58b3e 20-Jan-2006 John Baldwin <jhb@FreeBSD.org>

Make the 'pci_devclass' pointer variable private (drivers really shouldn't
share devclass pointers, a mistake I've encouraged in the past) and
move the declaration of the pci_driver kobj class from cardbus.c to
pci_private.h so that other drivers can inherit from pci_driver.


# a48895a7 01-Jan-2006 Warner Losh <imp@FreeBSD.org>

Use __HAVE_ACPI and __PCI_REROUTE_INTERRUPT as appropriate rather than
the complicated #ifdefs.


# 98b78107 01-Jan-2006 Warner Losh <imp@FreeBSD.org>

Remove stray debug from p4 integration.


# 0c4246bd 30-Dec-2005 Warner Losh <imp@FreeBSD.org>

Remove debug now that I've looped back the big changes into my p4 tree.


# a9883bc8 30-Dec-2005 Warner Losh <imp@FreeBSD.org>

Expose pci_add_resources to the outside world, add a 'force' flag to
force allocation of unallocated BARs (cardbus uses this to preallocate
everything). Add a prefetchmask to allow for busses that get prefetch
hints to set them. Addjust pci_add_map and pci_ata_maps to take a new
force flag which pci_add_resources will pass in. Implement 'force' in
pci_add_map. Write new value of allocated resource into the bar, if
the allocation succeeded (we should have done this before, but with
the new force the bug was very obvious).


# 4f9795b9 20-Dec-2005 John Baldwin <jhb@FreeBSD.org>

Add a new method PCI_FIND_EXTCAP() to the pci bus interface that is used
to search for a specific extended capability. If the specified capability
is found for the given device, then the function returns success and
optionally returns the offset of that capability. If the capability is
not found, the function returns an error.


# 24ea970a 08-Nov-2005 Warner Losh <imp@FreeBSD.org>

Improve diagnostic message.


# e5baeed6 28-Oct-2005 Warner Losh <imp@FreeBSD.org>

MFp4: When doing lazy allocation, it turns out that we need to record the
actual resource values we received from the system rather than the range
we requested. Since we request a range starting at 0, we would record
that number. Later, since this == 0, we'd allocate again. However,
we wouldn't write the new resource into the BAR. This resulted in
a resource leak as well as a BAR that couldn't access the resource at
all since rman_get_start, et al, were wrong.

MFC After: 1 week (assuming RELENG_6 is open for business)


# 87623e8d 28-Oct-2005 Warner Losh <imp@FreeBSD.org>

Use symbolic name rather thanhard coding the cap pointer offset for
type two devices.


# 46dfab17 27-Oct-2005 Warner Losh <imp@FreeBSD.org>

Minor style(9) nitage.


# 85155d23 25-Oct-2005 Bill Paul <wpaul@FreeBSD.org>

Add a 1 microsecond delay in pci_add_children(), right before the read
of the PCIR_HDRTYPE register. It's the value returned from this
read access that determines whether or not we decide a device is
present at the current slot index. For some reason that I can't
adequately explain, this read fails on my machine when probing the
USB controller on my machine (which happens a multifunction device
at slot index 3 hung off the PCI-PCI bridge on the AMD8111 (bus
index 1)). The read will return 0xFF even though it should return
0x80 to indicate the presence of a multifunction device.

As near as I can tell, there's some timing issue involved with reading
the 'dead' slot indexes 0 through 2 that causes the read of the actual
device at slot 3 to fail. I tried a couple of different tricks to
correct the problem (the patch to amd64/pci/pci_cfgreg.c fixes it
for the amd64 arch), but adding this delay is the only thing that
always allows the USB controllers to be correctly probed 100% of the
time. Whatever the problem is, it's likely confined to the AMD8111
chipset. However, a simple 1us delay is fairly harmless and should
have no side effects for other hardware. I consider this to be
voodoo, but it's fairly benign voodoo and it makes my USB keyboard
and mouse work again.

Note that this is the second time that I've had to resort to a
1us delay to fix a PCI-related problem with this AMD8111/Opteron
system (the first being a fix I made a while back to the NDISulator).
It's possible the delay really belongs in the cfgreg code itself,
or that pci_cfgreg needs some custom hackery for an errata in the
8111. (I checked but couldn't find any documented errata on AMD's
site that could account for these problems.)


# 85266973 29-Sep-2005 John Baldwin <jhb@FreeBSD.org>

- Consolidate duplicated code for assigning interrupts to PCI devices via
routing, etc. in a static pci_assign_interrupt() function.
- Add a sledgehammer that allows the user to override the interrupt
assignment of any PCI device via a tunable (e.g. "hw.pci0.7.INTB=5" would
force any functions on the pci device in slot 7 of bus 0 that use B# to
use IRQ 5). This should be used with great caution! Generally, if the
interrupt routing in use provides specific tunables (such as hard-wiring
the IRQ for a given $PIR or ACPI PCI link device), then those should be
used instead. One instance where this tunable might be useful is if a
box has an MPTable with duplicate entries for the same PCI device with
different IRQs.

MFC after: 1 week


# 50757d2f 21-Sep-2005 Warner Losh <imp@FreeBSD.org>

Split power state control into two variables. hw.pci.do_powerstate
has been removed. It has been replaced by hw.pci.do_power_nodriver
and hw.pci.do_power_resume. The former defaults to 0 while the latter
defaults to 1.

When do_powerstate was set to 0, it broke suspend/resume for a lot of
people as an unintended consequence. This change will only affect the
areas that were intended to affect. This change will have no effect on
servers, but will help laptops quite a bit.

MFC After: 3 days.


# 6c996a00 10-Sep-2005 Warner Losh <imp@FreeBSD.org>

Change hw.pci.do_powerstate from a boolean to a range. 0 means the
same as today: do no power management. 1 means be conservative about
what you power down (any device class that has caused problems gets
added here). 2 means be agressive about what gets powered down (any
device class that's fundamental to the system is here). 3 means power
them all down, reguardless. The default is 1.

The effect in the default system is to add mass storage devices to the
list that we don't power down. From all the pciconf -l lists that
I've seen for the aac and amr issue, the bad device has been a mass
storage device class.

This is an attempt at a compromise between the very small number of
systems that have extreme issues with powerdown, and the very large
number of systems that gain real benefits from powerdown (I get about
20% more battery life when I attach a minimal set of drivers on my
Sony). Hopefully it will strike the proper balance.

MFC After: 3 days (before next beta)


# 6de560ab 10-Sep-2005 Warner Losh <imp@FreeBSD.org>

Allow one to access the cached values for CMDREG, CACHELNSZ, MINGNT,
MAXLAT and LATTIMER.

Improve error message when a bogus RID type is requested for a bar.


# a8cbc96c 03-Sep-2005 Warner Losh <imp@FreeBSD.org>

More consistantly return the correct BAR size. Before, we'd only
return the correct bar size if we encountered a 64-bit BAR that had
its resources already assigned. If the resources weren't yet
assigned, we'd bogusly assume it was a 32-bit bar and return 1.


# 9a1bbc52 01-Sep-2005 John Baldwin <jhb@FreeBSD.org>

Typo in comment.


# b81b5c06 31-Aug-2005 Warner Losh <imp@FreeBSD.org>

Treat resources that are 0xfffff.... as being 'unassigned'.

Reviewed by: jhb
Tested by: Mark Kirkwood
MFC After: 3 days


# f9937ed8 03-Jun-2005 Warner Losh <imp@FreeBSD.org>

Mask off the bar's value after the probe test write before testing
against 0 in pci_alloc_map, just like we do in pci_add_map. Also,
make sure that we restore the value to the BAR that was there before
if the bar is 0. Chances are that it was 0 before the write too and
that the restoration is a nop, but better safe than sorry.

Notice by: dwhite


# f1e1aa9b 01-Jun-2005 John Baldwin <jhb@FreeBSD.org>

Typo.

Submitted by: njl


# 40811086 31-May-2005 John Baldwin <jhb@FreeBSD.org>

Don't enable I/O or memory mode in a device's command register if the BAR
we are processing has a base address of zero. Note that this will only
change behavior for devices where all the BARs of a given type have a base
address of 0 since we will enable the appropriate access when we encounter
the first BAR with a base that is not 0. Specifically, this allows certain
Toshiba laptops to no longer require 'hw.pci.enable_io_modes=0' to avoid
hangs during boot.

PR: kern/20040
PR: i386/63776 (possibly)
PR: i386/68900 (possibly)
PR: i386/74532 (possibly)
MFC after: 1 week


# 4e30440d 29-Apr-2005 Warner Losh <imp@FreeBSD.org>

Add a detach for pci bridge and pci bus drivers. This allows one to
theoretically unload pci bridges or pci drivers. It will also allow
detach to work if one needed to detach a subtree.

This is inspired by looking at the p4 commits from bms to his 5.4
tree, but I didn't look at the final results.


# 9e605855 14-Apr-2005 John Baldwin <jhb@FreeBSD.org>

Call pci_print_verbose() before pci_add_resources() so that the order of
printf's during a verbose boot is more intuitive (the BAR listings and
interrupt routing info now comes after the config header dump rather than
just before it).


# ca44abec 10-Apr-2005 Warner Losh <imp@FreeBSD.org>

It isn't a whinable offence to want memory when the bar says ioport.
Put that behind bootverbose to make the ata driver less chatty on
advanced hardware.

Requested by: sos


# 69c5c40b 10-Apr-2005 Warner Losh <imp@FreeBSD.org>

Go ahead and try to allocate PCI_BAR(5) for ata devices.


# 5da5a253 01-Apr-2005 John-Mark Gurney <jmg@FreeBSD.org>

move the statement about switching power states to just before we do it, so
we don't print a false statement if the destination powerstate is
unsupported...


# 4ea3b0e7 26-Mar-2005 John-Mark Gurney <jmg@FreeBSD.org>

add some additional pci classes and sub-classes..

Reviewed by: imp (almost 6 months ago)


# 244f64d0 23-Mar-2005 John-Mark Gurney <jmg@FreeBSD.org>

relocate the power state transition statements to the
pci_set_powerstate_method function...

Reviewed by: imp
MFC after: 1 week


# 36fed965 17-Mar-2005 Warner Losh <imp@FreeBSD.org>

Use STAILQ in preference to SLIST for the resources. Insert new resources
last in the list rather than first.

This makes the resouces print in the 4.x order rather than the 5.x order
(eg fdc0 at 0x3f0-0x3f5,0x3f7 is 4.x, but 0x3f7,0x3f0-0x3f5 is 5.x). This
also means that the pci code will once again print the resources in BAR
ascending order.


# 463ec0ac 15-Mar-2005 Warner Losh <imp@FreeBSD.org>

If bus_generic_susped returns an error, devlist is not freed. Free it.

Submitted by: Ted Unangst (using the Coverity Prevent analysis tool)


# c3c08f30 27-Feb-2005 Warner Losh <imp@FreeBSD.org>

Expose pci_cfg_safe/restore for subclasses of pci to use.


# aedaf6e2 25-Feb-2005 Sam Leffler <sam@FreeBSD.org>

kill unused variable

Noticed by: Coverity Prevent analysis tool


# b542a023 06-Feb-2005 Bernd Walter <ticso@FreeBSD.org>

Enable interrupt routing as first choice on alpha.
The alpha default handler knows how to trigger a fallback.


# 73c58ad1 29-Jan-2005 Nate Lawson <njl@FreeBSD.org>

Fix typo.


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# 02906099 31-Dec-2004 Warner Losh <imp@FreeBSD.org>

Fix last second typos that crept in :-(.


# 4ee5d2f1 31-Dec-2004 Warner Losh <imp@FreeBSD.org>

Implement mimimum system software delays, per PCI PM 1.1 spec, as
suggested by Peter Edwards. This seems to fix my fxp problems and
likely will fix his as well. Use DELAY rather than *sleep because we
can be called from any context.


# e50dccae 07-Dec-2004 Warner Losh <imp@FreeBSD.org>

Fix comments to match last commit, and minor reformatting...


# 6f215654 07-Dec-2004 Warner Losh <imp@FreeBSD.org>

It turns out that a lot of newer systems have 'base peripherals' on
the PCI bus. We presently have no drivers for these devices, so they
are powered down. This is undesirable behavior since it breaks the
system when the base peripherals go away suddenly in the middle of
boot.

# if we ever get generic drivers for memory and/or base peripherals, then
# we can remove the tests here.


# 8526ed73 03-Dec-2004 Nate Lawson <njl@FreeBSD.org>

ACPI is not on pc98 either.

Informed by: nyan


# 161ad64e 03-Dec-2004 Nate Lawson <njl@FreeBSD.org>

Non-x86 platforms cannot use the ACPI includes. This should be fixed but
for now, only include the headers for i386, amd64, or ia64.

Pointed out by: grehan


# 10ce62b9 02-Dec-2004 Nate Lawson <njl@FreeBSD.org>

Turn ACPI and PCI devices off or to a lower power state in suspend and
back on again in resume. Override the default of D3 with the value the
BIOS specifies in _SxD, if present. Skip serial devices (PNP05xx) since
they seem to hang when set to D3 and may require special driver support.
Also, skip non-type 0 PCI devices (i.e., bridges) since our we don't yet
save/restore their config space and that seems to be necessary.

If this gives you trouble with suspend/resume, you can disable the new
ACPI and PCI power behavior separately with these tunables & sysctls:
debug.acpi.do_powerstate
hw.pci.do_powerstate

Approved by: imp (pci)
Tested by: acpi@ (numerous)


# 4ae6f4a6 09-Nov-2004 Warner Losh <imp@FreeBSD.org>

Make pci_do_powerstate default to 1 now that we've done the release to
get more testing. This should help things a little.


# d39d4a6e 01-Nov-2004 John Baldwin <jhb@FreeBSD.org>

- Change the ddb paging "support" to use a variable (db_lines_per_page) to
control the number of lines per page rather than a constant. The variable
can be examined and changed in ddb as '$lines'. Setting the variable to
0 will effectively turn off paging.
- Change db_putchar() to force out pending whitespace before outputting
newlines and carriage returns so that one can rub out content on the
current line via '\r \r' type strings.
- Change the simple pager to rub out the --More-- prompt explicitly when
the routine exits.
- Add some aliases to the simple pager to make it more compatible with
more(1): 'e' and 'j' do a single line. 'd' does half a page, and
'f' does a full page.

MFC after: 1 month
Inspired by: kris


# 9b4fab9e 13-Oct-2004 Brian Feldman <green@FreeBSD.org>

Fix a spelling error in a panic string.


# b19d97eb 23-Sep-2004 Olivier Houchard <cognet@FreeBSD.org>

Re-route interrupts on arm as well.


# 828a0b71 02-Jul-2004 Warner Losh <imp@FreeBSD.org>

Disable native ata support for now, too much breaks


# d485c7bc 29-Jun-2004 Søren Schmidt <sos@FreeBSD.org>

Update the special handling code for ATA devices to allow usage of
PCI native addressing. That means that if the HW says that using "real"
addresses instead of the hardwired legacy compat ones is allowed, we will
use them.


# 89c9c53d 16-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# ef77fe1a 24-May-2004 Warner Losh <imp@FreeBSD.org>

Use PCI_BAR() in preference to PCI_MAPS + x * 4.

Submitted by: jhb


# 7138b71d 24-May-2004 Warner Losh <imp@FreeBSD.org>

Do not write to those config registers that are unambiguously defined
in the various pci specifications as readonly. vendor, subvendor,
device and subdevice are required to be loaded in hardware by some
means that isn't the system BIOS or other system software (although
some devices do have ways of accomplishing this). class and subclass
are defined to be read-only in section 6.2.1 (v2.2). Apart from the
status register, which we weren't touching, these are the only
read-only registers I could find in the 2.2 spec.

progif is also defined as being read-only in section 6.2.1. However,
the PCI IDE programming document specifically states that some of the
bits are read/write. Since we may have to restore registers before we
have a driver attached, go ahead and restore this one byte when
transitioning between D3 and D0.

The PCI spec also says that writes to reserved and unimplemented
registers must be completed normally. It makes no statements about
writes to read-only registers, so be as conservative as possible,
while covering the exception to the rule that is documented in a
subpart of the standard.

Requested by: socttl


# c5b82061 21-May-2004 Warner Losh <imp@FreeBSD.org>

Fix cutNpasto in last commit.


# d776e116 21-May-2004 Warner Losh <imp@FreeBSD.org>

ifdef writing to registers that the base pci standard says are
read-only on D3->D0 power state transition. Add a define to enable
them, but include a comment to contact me if there's a problem.


# 17249aab 21-May-2004 Warner Losh <imp@FreeBSD.org>

Compeletely rewrite the description of hw.pci.do_powerstate to sound
better.


# 4c04937d 21-May-2004 Warner Losh <imp@FreeBSD.org>

Improve the English somewhat.

Prodded by: ru@


# cd677980 21-May-2004 Warner Losh <imp@FreeBSD.org>

Ooops, forgot to commit the updated definition for hw.pci.do_powerstate
when I committed code that changed its meaning.


# b17653cf 21-May-2004 Warner Losh <imp@FreeBSD.org>

MFp4:

Split the baby. For idepci devices, now both legacy mode bits need
not be set. We can run an idepci in a split mode. However, it only
works better than before, not works. It works better in that when one
device is legacy and the other isn't and disabled, we now operate
correctly.

sos submitted a version of this patch.


# ae8b157f 21-May-2004 Warner Losh <imp@FreeBSD.org>

Move pci_do_powerstate up a level. Now it just means 'do not turn devices
off into d3 state when there's no driver for the device'. This should
help suspend/resume in the default case.


# e5af1ba8 21-May-2004 Warner Losh <imp@FreeBSD.org>

MFp4: o save/restore subvendor, subdevice, vendor, device, baseclass,
subclass, progif and revid. While these are typically read
only fields, they aren't always read-only. progif is writable
for ata devices, for example. It does no harm when they are
read only, and helps when they aren't.


# d53b2554 21-May-2004 Warner Losh <imp@FreeBSD.org>

make the pci power state and resource code a lot less chatty. The
chattiness was left in for debugging, but now that nearly all of the
problems relating to the changes have been fixed, it is only annoying. It
is still available via bootverbose.

Prodded by: jhb


# fe2c6101 28-Apr-2004 Thomas Moestl <tmm@FreeBSD.org>

Remove the EBus stopgap of r1.248; a proper fix is in place now.


# 1c168bb7 25-Apr-2004 Warner Losh <imp@FreeBSD.org>

Fix two typos from PR: 65694

1) In pci.c, we need to check the child device's state, not the parent
device's state.
2) In acpi_pci.c, we have to run the power state change after the acpi
method when the old_state is > new state, not the other way around.

Submitted by: Dmitry Remesov
PR: 65694


# 27c2013e 23-Apr-2004 Marius Strobl <marius@FreeBSD.org>

Add a stopgap for the EBus breakage on sparc64 since the PCI code does
resource pre-allocation. The problem is that the BARs of the EBus bridges
contain the ranges for the resources for the EBus devices beyond the bridge.
So when the EBus code tries to allocate the resource for an EBus device
it's already allocated by the PCI code.
To be removed again as soon as we have a proper solution in the EBus Code.

Reviewed by: tmm
Approved by: marcel (mentor)


# 206995a1 21-Apr-2004 Warner Losh <imp@FreeBSD.org>

ata devices in legacy are special, and we must treat them as such.
While I would have prefered to have a solution that didn't move
knowledge of this into the pci layer. However, this is literally the
only exception that's listed in the PCI standard to the usual way of
decoding BARs. atapci devices in legacy mode now ignore the first 4
bars and hard code the values to the legacy ide values (well, for each
of the controllers that are in legacy mode). The 5th bar is handled
normally.

Remove the zero bar handling. zero bars should be ignored at all
other times, and since we handle that specially, we don't need the
older workaround.


# 470fcc93 20-Apr-2004 Søren Schmidt <sos@FreeBSD.org>

Do not pre-allocate resources for BAR's on ATA MASTERDEV's thats on
the standard ATA primary and secondary addresses.

Reintroduce the size 1 ALTIO space so that we can have both ATA and
floppies back working.


# f77ad99d 16-Apr-2004 Warner Losh <imp@FreeBSD.org>

ooops. I disabled pci_enable_io_modes not pci_do_powerstate in the last
commit. That was in error.

Noticed by: sos


# b24afb17 15-Apr-2004 Warner Losh <imp@FreeBSD.org>

make the bad bar warning less scary, and toss it behind a bootverbose.
It is harmless, but freaking people out.


# d9664287 15-Apr-2004 Warner Losh <imp@FreeBSD.org>

Turn off the power stuff for a little while longer. There appears to be
something subtle wrong with it.


# b0855e45 14-Apr-2004 Warner Losh <imp@FreeBSD.org>

Now that the dust has settled on the resource issues, turn on the
power parts of my patches and see what breaks. Don't (yet) throw
the chatty messages behind a if (bootverbose).


# d9f6718e 13-Apr-2004 Warner Losh <imp@FreeBSD.org>

Some devices have what appear to be invalid BARs. They are invalid in
the sense that any write to them reads back as a 0. This presents a
problem to our resource allocation scheme. If we encounter such vars,
the code now treats them as special, allowing any allocation against
them to succeed. I've not seen anything in the standard to clearify
what host software should do when it encounters these sorts of BARs.

Also cleaned up some output while I'm here and add commmented out
bootverbose lines until I'm ready to reduce the verbosity of boot
messages.

This gets a number of south bridges and ata controllers made mostly by
VIA, AMD and nVidia working again. Thanks to Soren Schmidt for his
help in coming up with this patch.


# e3d51284 11-Apr-2004 Warner Losh <imp@FreeBSD.org>

Add system tunable to turn off power state changes. Default to off until
we get the resource allocation stuff hammered out.

Fix and off by one error that caused unnecessary filtering of valid
BARs for only 4 bytes than ICH3 and other PCI IDE controllers have.
Andrew Gallatin submitted this, although it doesn't solve the problems
ICH3 controllers have with the new code, it does restore the former
resource list on the probe line.


# bbecd97c 09-Apr-2004 Warner Losh <imp@FreeBSD.org>

Only print state change message for real state changes. When we set a
device in D0 to D0, that's a no-op, however the messages seem to be
confusing some people. Eventually, these messages will be parked
behind a if (bootverbose).

# I don't think this will fix any real bugs...


# cd8b53ed 09-Apr-2004 Warner Losh <imp@FreeBSD.org>

Omnibus PCI commit:
o Save and restore bars for suspend/resume as well as for D3->D0
transitions.
o preallocate resources that the PCI devices use to avoid resource
conflicts
o lazy allocation of resources not allocated by the BIOS.
o set unattached drivers to state D3. Set power state to D0
before probe/attach. Right now there's two special cases
for this (display and memory devices) that need work in other
areas of the tree.

Please report any bugs to me.


# f54a290f 23-Dec-2003 Warner Losh <imp@FreeBSD.org>

Minor whitespace changes to conform better to stlye(9) and reduce diffs
with uncommitted changes I have in p4.


# 0d2a2989 17-Nov-2003 Peter Wemm <peter@FreeBSD.org>

Initial landing of SMP support for FreeBSD/amd64.

- This is heavily derived from John Baldwin's apic/pci cleanup on i386.
- I have completely rewritten or drastically cleaned up some other parts.
(in particular, bootstrap)
- This is still a WIP. It seems that there are some highly bogus bioses
on nVidia nForce3-150 boards. I can't stress how broken these boards
are. I have a workaround in mind, but right now the Asus SK8N is broken.
The Gigabyte K8NPro (nVidia based) is also mind-numbingly hosed.
- Most of my testing has been with SCHED_ULE. SCHED_4BSD works.
- the apic and acpi components are 'standard'.
- If you have an nVidia nForce3-150 board, you are stuck with 'device
atpic' in addition, because they somehow managed to forget to connect the
8254 timer to the apic, even though its in the same silicon! ARGH!
This directly violates the ACPI spec.


# 4311d1d3 03-Nov-2003 John Baldwin <jhb@FreeBSD.org>

Enable PCI interrupt routing for i386 SMP kernels.


# aec21b56 31-Oct-2003 Doug Rabson <dfr@FreeBSD.org>

Make the cardbus driver a derived class of the pci driver. In theory, this
should allow many of the pci methods to be re-staticised.


# 526b5e65 17-Sep-2003 Mitsuru IWASAKI <iwasaki@FreeBSD.org>

Add pci_resume() to reestablish interrupt routing after
suspend/resume.
Especially after hibernation, interrupt routing went back to initial
status on some machines.


# ec40a9f9 14-Sep-2003 Scott Long <scottl@FreeBSD.org>

Teach the PCI code to parse MSI extended capabilities. Re-arrange the
pcicfg struct a bit to hold extcap structures instead of structure members.


# cadbc399 14-Sep-2003 Scott Long <scottl@FreeBSD.org>

Remove most of the magic constants from the extcap parsing code.


# ab551d91 03-Sep-2003 John Baldwin <jhb@FreeBSD.org>

Replace another instance of PCIR_MAPS with PCIR_BAR(x).

Reminded by: dfr


# e27951b2 02-Sep-2003 John Baldwin <jhb@FreeBSD.org>

Use PCIR_BAR(x) instead of PCIR_MAPS.

Glanced over by: imp, gibbs
Tested by: i386 LINT


# d37a68d0 01-Sep-2003 Doug Rabson <dfr@FreeBSD.org>

Don't try to enable io or memory access for non-standard resource
addresses. This stops resource allocations for e.g. amdpm failing - this
has its own special ways of enabling access.


# 729d7ffb 28-Aug-2003 John Baldwin <jhb@FreeBSD.org>

- Rename PCIx_HEADERTYPE* to PCIx_HDRTYPE* so the constants aren't so long.
- Add a new PCIM_HDRTYPE constant for the field in PCIR_HDRTYPE that holds
the header type.
- Replace several magic numbers with appropriate constants for the header
type register and a couple of PCI_FUNCMAX.
- Merge to amd64 the fix to the i386 bridge code to skip devices with
unknown header types.

Requested by: imp (1, 2)


# b0cb115f 21-Aug-2003 Warner Losh <imp@FreeBSD.org>

Prefer the uintXX_t to the u_intXX_t names.


# 8d50cc0e 01-Aug-2003 Warner Losh <imp@FreeBSD.org>

Define PCI_MAXHDRTYPE to be 2. We know about header types 0, 1 and 2.
Update the MI device scanning code to use PCI_MAXHDRTYPE rather than
the hard coded 2.


# 3f2a1b06 31-Jul-2003 John Baldwin <jhb@FreeBSD.org>

Update the 'ps', 'show pci', and 'show ktr' ddb commands to use the new
pager callout instead of homerolling their own paging facility.


# 3920999d 01-Jul-2003 Thomas Moestl <tmm@FreeBSD.org>

Add a new PCI interface method, assign_interrupt, to determine the
interrupt to be used for a device. This is intended solely for internal
use of PCI bus implementations, and exists so that PCI bus drivers
implementing special interrupt assignment methods which require
additional work at the bus level to work right can be easily derived
from the generic driver (or any other one) without resorting to hacks.

It will be used in the sparc64 ofw_pcibus driver, which will be
committed shortly.

Make use of this method in the generic implementation, and add it to
the method table of bus drivers derived from the PCI one.

Reviewed by: imp, -hackers


# 036c2cfb 01-Jul-2003 Thomas Moestl <tmm@FreeBSD.org>

Allow to write the intpin ivar using the pci_set_intpin() accessor. There
are some Sun PCI devices around which bogusly set intpin to 0, although
they use the intline mechanism; this allows the device driver to correct
that.

Reviewed by: imp


# 40357931 22-Jun-2003 Yoshihiro Takahashi <nyan@FreeBSD.org>

Re-enabled PCI irq routing on pc98.


# e3ee6a27 21-Jun-2003 John-Mark Gurney <jmg@FreeBSD.org>

use a REG macro that was already defined.

Reorder how the pci probing in handled. before adding devices, check to
see if the slot is a multi-function device to see if we should probe all
the functions.

Original idea by: imp


# bd77aaf9 09-Jun-2003 John Baldwin <jhb@FreeBSD.org>

When we re-route a PCI interrupt, write the new IRQ value into the intline
register.

Reviewed by: imp


# 82cdd526 08-Jun-2003 Yoshihiro Takahashi <nyan@FreeBSD.org>

Don't route PCI irq on pc98.


# 1beb3816 07-Jun-2003 John Baldwin <jhb@FreeBSD.org>

- Adjust the comment about re-routing PCI interrupts to be less
ia64-specific.
- When trying to re-route interrupts, don't change cfg->intline if the
re-route fails by returning an invalid vector. This fixes machines
without any way of routing interrupts such as older PC's without a
$PIR table.

We do not currently write the new intline value back to the hardware, but
we should. That will likely be added in a later commit.


# ba90ccc6 04-Jun-2003 John Baldwin <jhb@FreeBSD.org>

Batton down the hatches!!!

Always route PCI interrupts on i386 UP machines. I was planning to enable
this for i386 anyways once SMP support is done. Having this enabled fixes
problems on many people's laptops.

Requested by: imp


# 60db3b9e 31-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unused variable(s).
Remove break after return;

Found by: FlexeLint


# c047e5b1 15-Apr-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Return status for PCI methods '{enable,disable}_{io,busmaster}'.

Reviewed by: imp


# 7f2af527 15-Apr-2003 Warner Losh <imp@FreeBSD.org>

When the driver allocates memory or I/O ports, enable that bit in the
command config register. At the present, this represents a nop
because these bits should have been set earlier in the process. In
the future, we'll only set these bits when the driver requests the
resource, not when the bus code detects the resource.

Reviewed by: mdodd


# a163d034 18-Feb-2003 Warner Losh <imp@FreeBSD.org>

Back out M_* changes, per decision of the TRB.

Approved by: trb


# 2c422e46 17-Feb-2003 Warner Losh <imp@FreeBSD.org>

Include class designation in pnpinfo for generic driver loading


# 5794c593 17-Feb-2003 Warner Losh <imp@FreeBSD.org>

Move the pnp and location info into the common pci bus. Make all known
pci busses implement this.

Also minor comment smithing in cardbus. Fix copyright to this year
with my name on it since I've been doing a lot to this file.

Reviewed by: jhb


# 18081146 17-Feb-2003 Warner Losh <imp@FreeBSD.org>

These don't need to be semi-public after all.


# 594b5aeb 15-Feb-2003 Warner Losh <imp@FreeBSD.org>

Use rman_get_device rather than rle->resl->r_dev.
make pci_hdrtypedata and pci_read_extcap accessible (but maybe in the end
we'll make them private again).


# 44956c98 21-Jan-2003 Alfred Perlstein <alfred@FreeBSD.org>

Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.


# ba5fc4ee 26-Nov-2002 Warner Losh <imp@FreeBSD.org>

Add a new cardbus specific ivar: PCI_IVAR_ETHADDR. Some pci-like
buses support querying the MAC address in a standard-for-that-bus way.
The base pci bus returns NULL for this IVAR always.

Submitted by: sam
Approved by: re (blanket for NEWCARD)


# 04211a9b 13-Nov-2002 Matthew N. Dodd <mdodd@FreeBSD.org>

Staticize local variable.

Submitted by: Hiten Pandya <hiten@angelica.unixdaemons.com>
Obtained from: re (murray)


# f371d460 16-Oct-2002 John Baldwin <jhb@FreeBSD.org>

Whitespace.


# 7e3998a3 01-Oct-2002 Bruce Evans <bde@FreeBSD.org>

Removed the only PCI_DEBUG ifdef in the kernel. PCI_DEBUG was not a
supported option and it disabled a whole 2 lines of bootverbose messages.
I wanted to see 1 of the messages (about the latency timers). This
is a wrong place to decode pci configurations, but the code is already
here and handles more details than pciconf(8).


# b1386640 01-Oct-2002 Poul-Henning Kamp <phk@FreeBSD.org>

The bus number is unsigned, it cannot be less than zero.

Found by: FlexeLint


# b28a0fe1 28-Sep-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Don't use GCC shorthand for ?: unless it really matters.


# dd699396 03-Sep-2002 John Baldwin <jhb@FreeBSD.org>

Fix up a comment.


# 1d621313 03-Sep-2002 John Baldwin <jhb@FreeBSD.org>

- Make pci_load_vendor_data() static and do it during MOD_LOAD instead of
when the first PCI bus attaches.
- Create /dev/pci during MOD_LOAD as well.
- Destroy /dev/pci during MOD_UNLOAD (not that you can kldunload pci, but
might as well get the code right)


# 7251aa20 28-Aug-2002 Guido van Rooij <guido@FreeBSD.org>

Add a new command: show pciregs, equivalent to pciconf -l

Reviewed by: Doug Rabson (quite some time ago)
MFC after: 1 week


# 2ccfc932 26-Aug-2002 John Baldwin <jhb@FreeBSD.org>

Overhaul the ACPI PCI bridge driver a bit:
- Add an ACPI PCI-PCI bridge driver (the previous driver just handled
Host-PCI bridges) that is a PCI driver that is a subclass of the generic
PCI-PCI bridge driver. It overrides probe, attach, read_ivar, and
pci_route_interrupt.
- The probe routine only succeeds if our parent is an ACPI PCI bus which
we test for by seeing if we can read our ACPI_HANDLE as an ivar.
- The attach routine saves a copy of our handle and calls the new
acpi_pcib_attach_common() function described below.
- The read_ivar routine handles normal PCI-PCI bridge ivars and adds an
ivar to return the ACPI_HANDLE of the bus this bridge represents.
- The route_interrupt routine fetches the _PRT (PCI Interrupt Routing
Table) from the bridge device's softc and passes it off to
acpi_pcib_route_interrupt() to route the interrupt.
- Split the old ACPI Host-PCI bridge driver into two pieces. Part of
the attach routine and most of the route_interrupt routine remain in
acpi_pcib.c and are shared by both ACPI PCI bridge drivers.
- The attach routine verifies the PCI bridge is present, reads in
the _PRT for the bridge, and attaches the child PCI bus.
- The route_interrupt routine uses the passed in _PRT to route a PCI
interrupt.
The rest of the driver is the ACPI Host-PCI bridge specific bits that
live in acpi_pcib_acpi.c.
- We no longer duplicate pcib_maxslots but use it directly.
- The driver now uses the pcib devclass instead of its own devclass.
This means that PCI busses are now only children of pcib devices.
- Allow the ACPI_HANDLE for the child PCI bus to be read as an ivar
of the child bus.
- Fetch the _PRT for routing PCI interrupts directly from our softc
instead of walking the devclass to find ourself and then fetch our
own softc.

With this change and the new ACPI PCI bus driver, ACPI can now properly
route interrupts for devices behind PCI-PCI bridges. That is, the
Itanium2 with like 10 PCI busses can now boot ok and route all the PCI
interrupts. Hopefully this will also fix problems people are having with
CardBus bridges behind PCI-PCI bridges not properly routing interrupts
when ACPI is used.

Tested on: i386, ia64


# 42dbeaee 26-Aug-2002 John Baldwin <jhb@FreeBSD.org>

Various changes to make it easier to subclass the PCI bus device.
- Make the pci devclass a global variable.
- Add child devices in pci_attach() instead of pci_probe(). Change
pci_probe() to just check for a valid bus number from the associated
bridge and return -1000 if successful. This allows subclasses of the
PCI bus driver to override the generic driver.
- Move the code to load the vendor data into its own public function.
Really though, doing this at attach is just plain wrong. This should
really be done in the module load routine instead. As a side effect,
the 'busno' variable in pci_attach() is now no longer static (minor
bug that was harmless so far.)
- Change pci_add_children() to take an extra argument that is the size of
the device info structure passed to pci_read_device() and make it public
so subclasses of the PCI bus can call it in their attach routines.
- Move the bits to attach a probed PCI child to a PCI bus into a global
pci_add_child() function. This will allow subclasses that can detect
a PCI device not found in the normal PCI probe to add those devices in
their own attach routine. (I have seen this in the ACPI tree on my
laptop for example.) As a side effect, change the static function
pci_add_resources() to get the busno, slot, and func from the passed
in dinfo structure instead of requiring them as function arguments.

Tested on: i386, alpha, ia64, sparc64


# b8182b24 02-Aug-2002 Warner Losh <imp@FreeBSD.org>

While PCI interrupts are shareable, this should not have been committed just
yet.


# a850203d 26-Jul-2002 Warner Losh <imp@FreeBSD.org>

Make PCI_ENABLE_IO_MODES a sysctl hw.pci.enable_io_modes. It can also
be set at boot time. It defaults to 1 now since it can be set in the
boot loader. If this proves unwise, we can reset it to defaulting to 0.


# d508dd34 31-May-2002 Warner Losh <imp@FreeBSD.org>

Use PCI_INTERRUPT_VALI in stead of hard coded 255


# 3c2d2c7c 31-May-2002 Warner Losh <imp@FreeBSD.org>

More style(9) nits


# c9579f73 31-May-2002 Warner Losh <imp@FreeBSD.org>

Make this file mostly conform to style(9).

Approved by: msmith in principle before walkabout


# 10e38949 16-Apr-2002 Matthew N. Dodd <mdodd@FreeBSD.org>

Add MODULE_VERSION.


# 2334e409 10-Apr-2002 Nick Hibma <n_hibma@FreeBSD.org>

intline == 0 is not a valid intline on 386. See pci_cfgintr() in
sys/i386/pci/pci_cfgreg.c.

This should resolve some cases where adding USB support to the kernel
produced an interrupt storm.


# 20fe0073 13-Mar-2002 Warner Losh <imp@FreeBSD.org>

Add 5th parameter to pci_read_device specifying the size of the object
to create.


# 7ba175ac 26-Feb-2002 Warner Losh <imp@FreeBSD.org>

Use the pci.c code wherever possible, rather than copying all the pci
code into cardbus and s/pci/cardbus. This exposes a few pci_*
functions that are now static.

This work is similar to work Justin posted to the mobile list about a
year or two ago, which I have neglected since then.

This is a subset of his current work with the multiple inheritance
newbus architecutre. When completed, that will eliminate the need for
pci/pci_private.h.

Similar work is needed for the cardbus_cis and pccard_cis code as well.


# ced8202c 09-Jan-2002 Matthew N. Dodd <mdodd@FreeBSD.org>

Implement 2 small helper functions:
pci_find_bsf() - Find a device_t by bus/slot/function.
pci_find_device() - Find a device_t by vendor/device ID.


# b7c69fe4 21-Dec-2001 Thomas Moestl <tmm@FreeBSD.org>

Use the new resource_list_print_type() function to print resource list
contents, and the new __BUS_ACCESSOR macro to construct the accessor
functions.


# 417c87d1 20-Dec-2001 Jim Pirzyk <pirzyk@FreeBSD.org>

Add support for the Intel 82443MX chipset

PR: kern/33032
MFC after: 1 month


# 47676b53 19-Dec-2001 Matthew N. Dodd <mdodd@FreeBSD.org>

Don't put variable declarations in header files, put prototypes.

'pci_devq' provides useful information now.


# ae4da688 24-Oct-2001 Jonathan Lemon <jlemon@FreeBSD.org>

Add PCI_ENABLE_IO_MODES option, for BIOSen that neglect this.

Submitted by: Andrew R. Reiter arr@watson.org


# aa553869 05-Oct-2001 Doug Rabson <dfr@FreeBSD.org>

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).


# c2d7a52a 01-Sep-2001 Nick Hibma <n_hibma@FreeBSD.org>

Small nit: Make both prints use 'at device %d.%d'.


# 3577f582 27-Aug-2001 Warner Losh <imp@FreeBSD.org>

Ugggg. I thought I'd already committed this to -current:

If the intline is 0 or 255, then it needs an interrupt routed. Some
Sony laptops improperly flag devices that need an interrupt with 0 :-(.


# 6dc5259a 31-May-2001 Andrew Gallatin <gallatin@FreeBSD.org>

Backout previous revision. While it fixed many platforms, it broke
all alphas with devices behind ppb's. I'm working on a better solution now.

Note that all alphas that use per-platform interrupt mapping are broken
again (as they have been for several months)


# d6a516cf 27-May-2001 Andrew Gallatin <gallatin@FreeBSD.org>

finally fix intr routing on alphas such as the as500 after months of
breakage:

- call PCIB_ROUTE_INTERRUPT() regardless of how valid the intline looks.
Some alphas leave garbage in the intline and leave the intr mapping
to OS platform support routines that map slots/buses to intlines
- Down in the alpha pci code, first try platform.pci_intr_route() and
if it doesn't exist or returns garbage, just read the intline out of
config space.

tested on AS500 (garbage in intline) and UP1000 (PC-like, intline is valid)

Note that a nice little hack like the APIC_IO section of pci_cfgregread()
is not workable. This is because the calling interface for
alpha_pci_route_interrupt() requires us to figure out the bus/slot/etc
from a device_t. At pci_read_device() time, we don't have a device_t
for the bus/slot/func in question.


# 3e481a77 14-Mar-2001 Peter Wemm <peter@FreeBSD.org>

The serverworks OSB4 pci->isa bridge has the same mapping register at
offset 0x90 for the SMBus device as the PIIX4.


# 9eb13b39 27-Feb-2001 Peter Wemm <peter@FreeBSD.org>

Slightly reimplement some recently added helper functions as methods, so
that drivers are not reaching into the internals of the pci bus. There
are no driver changes, the public interface is the same.


# f09deb69 06-Feb-2001 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>

Fix typo: wierd -> weird.

There is no such thing as wierd in the english language.


# afd27fce 01-Jan-2001 Matt Jacob <mjacob@FreeBSD.org>

Sanity check ptr for legal values so it is less likely
(but not impossible) to get stuck in an infinite loop.

Obtained from: msmith@freebsd.org


# 70b5f189 12-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Remove a redundant prototype.


# 3742d6ca 12-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Don't try to free the now-nonexistent hdrspec field. This one snuck by
me in the previous round of patches. Oops.


# 8983cfbf 12-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Next round of PCI subsystem updates:

- Break out the /dev/pci driver into a separate file.
- Kill the COMPAT_OLDPCI support.
- Make the EISA bridge attach a bit more like the old code; explicitly
check for the existence of eisa0/isa0 and only attach if they don't
already exist. Only make one bus_generic_attach() pass over the
bridge, once both busses are attached. Note that the stupid Intel
bridge's class is entirely unpredictable.
- Add prototypes and re-layout the core PCI modules in line with
current coding standards (not a major whitespace change, just moving
the module data to the top of the file).
- Remove redundant type-2 bridge support from the core PCI code; the
PCI-CardBus code does this itself internally. Remove the now
entirely redundant header-class-specific support, as well as the
secondary and subordinate bus number fields. These are bridge
attributes now.
- Add support for PCI Extended Capabilities.
- Add support for PCI Power Management. The interface currently
allows a driver to query and set the power state of a device.
- Add helper functions to allow drivers to enable/disable busmastering
and the decoding of I/O and memory ranges.
- Use PCI_SLOTMAX and PCI_FUNCMAX rather than magic numbers in some
places.
- Make the PCI-PCI bridge code a little more paranoid about valid
I/O and memory decodes.
- Add some more PCI register definitions for the command and status
registers. Correct another bogus definition for type-1 bridges.


# fc3438d8 09-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Cosmetic nit; separate slot/function with '.' not ':'


# 2961fc5a 09-Dec-2000 Mike Smith <msmith@FreeBSD.org>

- Fix the device database parsing code so that it actually works.
- Improve the formatting for devices identified by the database.
- Fix the pcib_route_interrupt method definition, as an old version
snuck in here somehow 8(
- Remove a couple of the vendor/device IDs for PCI:ISA bridges which
correctly identify themselves.

Submitted by: peter


# bb0d0a8e 08-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Next phase in the PCI subsystem cleanup.

- Move PCI core code to dev/pci.
- Split bridge code out into separate modules.
- Remove the descriptive strings from the bridge drivers. If you
want to know what a device is, use pciconf. Add support for
broadly identifying devices based on class/subclass, and for
parsing a preloaded device identification database so that if
you want to waste the memory, you can identify *anything* we know
about.
- Remove machine-dependant code from the core PCI code. APIC interrupt
mapping is performed by shadowing the intline register in machine-
dependant code.
- Bring interrupt routing support to the Alpha
(although many platforms don't yet support routing or mapping
interrupts entirely correctly). This resulted in spamming
<sys/bus.h> into more places than it really should have gone.
- Put sys/dev on the kernel/modules include path. This avoids
having to change *all* the pci*.h includes.


# 1581afb3 28-Nov-2000 Matthew N. Dodd <mdodd@FreeBSD.org>

Reduce code duplication by using the GET_RESOURCE_LIST bus method and related
generic resource_list management functions.

I'll deal with the EISA bits later.

Not objected to by: new-bus


# 72371ff2 29-Oct-2000 Darren Reed <darrenr@FreeBSD.org>

fix warning compile error about unused variable


# db403596 29-Oct-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Fix params passed to pci_porten() and pci_memen().


# f53e8493 28-Oct-2000 Mike Smith <msmith@FreeBSD.org>

Unconditionally turning on the I/O and memory enable bits in the PCI
command register is too aggressive. Revert to the previous behaviour, but
leave the new behaviour available as an undocumented option. It's not
clear what the Right, Right Thing is to do here, but the more conservative
approach is safer.


# 011d43cd 28-Oct-2000 Mike Smith <msmith@FreeBSD.org>

Allow PCI busses to be connected to host bridges detected by ACPI as well.


# c7e95d0a 19-Oct-2000 Mike Smith <msmith@FreeBSD.org>

Write the routed interrupt back to PCI configuration space.


# 68ab2e86 16-Oct-2000 Andrew Gallatin <gallatin@FreeBSD.org>

The previous commit broke kernel builds on alpha (and probably ia64).
#ifdef away the offending code until somebody with more newbus fu than
me can figure out where to put a default function that returns 255
without touching each alpha chipset driver..


# 9bf4bbca 16-Oct-2000 Warner Losh <imp@FreeBSD.org>

When a pci device hasn't had an interrupt routed to it (signified by
the intline of 255) go ahead and route the interrupt when we allocate
an interrupt.

Submitted by: msmith


# 0441aa9a 08-Oct-2000 Mike Smith <msmith@FreeBSD.org>

Validate the PCI bus number that we fetch from our parent, since there's no
guarantee that everything attached to *it* is a PCI bus.


# 28ea1bf8 04-Sep-2000 Peter Wemm <peter@FreeBSD.org>

When dumping the 'found devices' list in verbose mode, actually show the
bus/slot/function numbers. The old PCI code used other markers or
something, but without it here under the new pci code it is very hard to
tell which device is which (this only affects bootverbose mode).


# f7c7ba14 01-Sep-2000 Mike Smith <msmith@FreeBSD.org>

If a base address register has been set up by the BIOS, but the relevant
enable bit hasn't been set in the command register, set the bit and
honour the register. It seems that quite a few lazy BIOS writers
aren't bothering to do this, which upsets the existing code and causes
us to miss out on properly-configured devices.


# 54613737 31-Aug-2000 Peter Wemm <peter@FreeBSD.org>

Remove duplicate static definition of pci_devclass


# 21c3015a 28-Aug-2000 Doug Rabson <dfr@FreeBSD.org>

* Completely rewrite the alpha busspace to hide the implementation from
the drivers.
* Remove legacy inx/outx support from chipset and replace with macros
which call busspace.
* Rework pci config accesses to route through the pcib device instead of
calling a MD function directly.

With these changes it is possible to cleanly support machines which have
more than one independantly numbered PCI busses. As a bonus, the new
busspace implementation should be measurably faster than the old one.


# f1954f57 09-Jun-2000 Doug Rabson <dfr@FreeBSD.org>

Nuke the useless chip driver. It gets in the way when you want to load
a functional driver for the device.


# 30d1c11e 28-May-2000 Peter Wemm <peter@FreeBSD.org>

Encapsulate the old PCI compatability support and APIs completely under
"options COMPAT_OLDPCI". This option already existed, but now also tidies
up the declarations in #include <pci/pci*.h>. It is amazing how much stuff
was using the old pre-FreeBSD 3.x names and going silently undetected.


# e3975643 25-May-2000 Jake Burkholder <jake@FreeBSD.org>

Back out the previous change to the queue(3) interface.
It was not discussed and should probably not happen.

Requested by: msmith and others


# 740a1973 23-May-2000 Jake Burkholder <jake@FreeBSD.org>

Change the way that the queue(3) structures are declared; don't assume that
the type argument to *_HEAD and *_ENTRY is a struct.

Suggested by: phk
Reviewed by: phk
Approved by: mdodd


# 2e9a65c4 18-May-2000 Doug Rabson <dfr@FreeBSD.org>

Print the correct value for the map type on a verbose boot.

PR: kern/18662
Submitted by: tamaru@ap.t.u-tokyo.ac.jp


# ec3da347 06-May-2000 Matt Jacob <mjacob@FreeBSD.org>

Update 'hose' (actually, MCPCIA instance #) for Alpha Rawhide systems.
We have *got* to fix this bogosity of trying to steal part of the PCI
address space for this stuff.


# 3aae7b16 30-Apr-2000 Bruce Evans <bde@FreeBSD.org>

Fixed the type of some ivar access functions. Ivars have type uintptr_t,
not u_long. On i386's with 64-bit longs, returning u_longs indirectly
in (more than) the space reserved for uintptr_t's tended to corrupt the
previous frame pointer in the stack frame, so it was not easy to debug.
The type mismatches are hidden by the bogus cast in DEVMETHOD().


# ed6aff73 18-Apr-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unneeded <sys/buf.h> includes.

Due to some interesting cpp tricks in lockmgr, the LINT kernel shrinks
by 924 bytes.


# f7b77691 08-Apr-2000 Doug Rabson <dfr@FreeBSD.org>

* Factor out the object system from new-bus so that it can be used by
non-device code.
* Re-implement the method dispatch to improve efficiency. The new system
takes about 40ns for a method dispatch on a 300Mhz PII which is only
10ns slower than a direct function call on the same hardware.

This changes the new-bus ABI slightly so make sure you re-compile any
driver modules which you use.


# 80060e88 19-Mar-2000 Peter Wemm <peter@FreeBSD.org>

Connect the ISA and PCI compatability shims to an option. In this case
it's options COMPAT_OLDISA and COMPAT_OLDPCI. This is meant to be a
fairly strong incentive to update the older drivers to newbus, but doesn't
(quite) leave anybody hanging with no hardware support. I was talking with
a few folks and I was encouraged to simply break or disable the shims but
that was a bit too drastic for my liking.


# e5399702 18-Mar-2000 Nick Hibma <n_hibma@FreeBSD.org>

Print the PCI resources even if they are disabled. This shows more clearly
when the BIOS is forgetful about initialising the USB controllers.


# 17d75f8e 15-Mar-2000 Matt Jacob <mjacob@FreeBSD.org>

Alpha 8200 port: Until we fix things better, determine which alpha CPU
platform we're running on so we know how many bits to reserve at the top
end for the 'hose' value. It turns out that there's *just* enough room
to support all possible hoses on TurboLaser.
Reviewed by: gallatin@freebsd.org, dfr@free3bsd.org


# bebfe1ca 22-Feb-2000 Bill Fumerola <billf@FreeBSD.org>

o No need to print the vendor/device ID for things that matched succesfully.
o ``<device name>'' versus ``device name'' for things that fall under nomatch.

Reviewed by: dfr (in principle)
Approved by: Baron von Hubbard


# 6874d629 19-Feb-2000 Doug Rabson <dfr@FreeBSD.org>

Remove the vga-pci driver. It serves no purpose and it hides the hardware
from useful drivers such as the 3D DRI drivers I will be porting for
hardware accelerated OpenGL. The hardware will still be reported during
boot using the nomatch system.

Approved by: jkh


# 483df2dd 01-Feb-2000 Peter Wemm <peter@FreeBSD.org>

Spell "pci_delete_resource" correctly.

Approved by: jkh (who must be very sick of requests now :-)


# cebf86fa 29-Jan-2000 Peter Wemm <peter@FreeBSD.org>

Put a FYI in the compatability shims so that people are aware that they
are using an old unconverted driver. Most (if not all) of the drivers
for common hardware are newbus these days. However, we don't want
to encourage people to take the easy way out and write new drivers
using the shims. This is just passive "encouragement".

Reviewed by: phk


# f671bf82 08-Jan-2000 Peter Wemm <peter@FreeBSD.org>

Show the port/mem/irq of pci devices too.


# dfea8af9 10-Dec-1999 Peter Wemm <peter@FreeBSD.org>

Make the usb and ide/ata device identification a little saner. Rather than
attaching to the device via chip*, use the newbus nomatch method to report
the device. This leaves them unattached so that a driver can be easily
loaded to grab them later.


# 64ae346b 08-Dec-1999 Kenneth D. Merry <ken@FreeBSD.org>

[ repository copy of sys/pci/pci_ioctl.h to sys/sys/pciio.h happened in the
background ]

Rename sys/pci/pci_ioctl.h to sys/sys/pciio.h to make it easier for
userland programs to use this interface. Reformat the file, and add a
BSD-style copyright to it.

Add a new man page for pci(4). The PCIOCGETCONF, PCIOCREAD, and PCIOCWRITE
ioctls are documented, but the PCIOCATTACHED ioctl is not documented
because it is not implemented.

Change includes of <pci/pci_ioctl.h> to <sys/pciio.h> or remove them
altogether. In many cases, pci_ioctl.h was unused.

Reviewed by: steve


# 150e2115 05-Dec-1999 Peter Wemm <peter@FreeBSD.org>

Raise the pci compat driver match priority a bit so that it's not
quite so close to the chip* drivers.


# fe0d4089 03-Dec-1999 Matthew N. Dodd <mdodd@FreeBSD.org>

Remove the 'ivars' arguement to device_add_child() and
device_add_child_ordered(). 'ivars' may now be set using the
device_set_ivars() function.

This makes it easier for us to change how arbitrary data structures are
associated with a device_t. Eventually we won't be modifying device_t
to add additional pointers for ivars, softc data etc.

Despite my best efforts I've probably forgotten something so let me know
if this breaks anything. I've been running with this change for months
and its been quite involved actually isolating all the changes from
the rest of the local changes in my tree.

Reviewed by: peter, dfr


# 5700c63b 29-Nov-1999 Peter Wemm <peter@FreeBSD.org>

Make the pci driver compat shim return a preference for probe
rather than an "it's mine!" so that other newbus-aware drivers can
bid for the device too. This should allow the sym driver to out-bid
the ncr driver for devices it supports without having to modify ncr.c
at all. ncr would then function as a catch-all.


# c577d56d 22-Nov-1999 Nick Hibma <n_hibma@FreeBSD.org>

Feh, kind of went wrong the previous commit. dev should child (in some
cases) plus a typo.


# aa7e2ba7 21-Nov-1999 Nick Hibma <n_hibma@FreeBSD.org>

Move the pretty printing of the description for USB controllers to
pci_probe_nomatch, so it won't be in the way when loading USB as a module.

The reason for them being there in the first place is that every
motherboard comes with USB kit and this way it looks more pretty (peter).
The real solution will be to define some method of detaching a driver
after it has attached.


# 5ab05143 20-Nov-1999 Peter Wemm <peter@FreeBSD.org>

Allow NULL for startp and/or countp in bus_get_resource() so that you can
get one of the two without having to use a dummy variable.


# 870c4cf8 03-Nov-1999 Andrew Gallatin <gallatin@FreeBSD.org>

now that a map's base addr is 64-bits, the alpha multi-hose hack needs
to be cast to 64-bits in pci_add_map. This should allow XP1000s and
DS20s to boot -current again.


# 02c58685 30-Oct-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Change useracc() and kernacc() to use VM_PROT_{READ|WRITE|EXECUTE} for the
"rw" argument, rather than hijacking B_{READ|WRITE}.

Fix two bugs (physio & cam) resulting by the confusion caused by this.

Submitted by: Tor.Egge@fast.no
Reviewed by: alc, ken (partly)


# 7254edcf 29-Oct-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Don't test boolean return against != 1.
Don't needlessly assign the error variable in an if statement.


# f8ef46e9 28-Oct-1999 Doug Rabson <dfr@FreeBSD.org>

Fix some resource allocation peculiarities of the intpm device.


# 4ed33d15 26-Oct-1999 Doug Rabson <dfr@FreeBSD.org>

Make sure we add an interrupt resource if intline!=255.


# 9091387f 17-Oct-1999 Doug Rabson <dfr@FreeBSD.org>

Correct a stupid type which prevented us from working with any device
which needed port resources.


# 45f0aa1f 14-Oct-1999 Doug Rabson <dfr@FreeBSD.org>

* Implement bus_set/get/delete_resource for pci.
* Change the hack used on the alpha for mapping devices into DENSE or
BWX memory spaces to a simpler one. Its still a hack and should be
a seperate api to explicitly map the resource.
* Add $FreeBSD$ as necessary.


# da7ca2d9 12-Oct-1999 Andrew Gallatin <gallatin@FreeBSD.org>

allow pci_ioctl to work with multi-hose alphas.
Rather than teaching pci_ioctl about hoses, we just pass down a magic number
& let the platform code figure out what the hose is based on what the bus
number is.

concept approved by dfr


# 9b2591a0 03-Oct-1999 Andrew Gallatin <gallatin@FreeBSD.org>

A band-aid to prevent multi-hose alpha chipsets (aka tsunami) from
panic'ing because the hose is not filled in. We should probably extend the
pciioctl interface to take hoses into account..


# 70d32847 01-Oct-1999 Roger Hardiman <roger@FreeBSD.org>

Backout part of the changes made in 1.111

For unknown devices the output will now be
pci0: unknown card (vendor=0x109e, dev=0x0878) at 14.1 irq 19
instead of
pci0: unknown card DD^0878 (vendor=0x109e, dev=0x0878) at 14.1 irq 19

Before this change, the code used to take the PCI vendor id and translate it
into a three letter ASCII name.
For PnP devices, the vendor id _does_ map to a nice ASCII name
(eg Creative Labs PnP ID maps to "CTL", ESS PnP ID maps to "ESS")

But there is no such mapping for PCI devices, as can be seen by the
example above where the Brooktree PCI vendor ID maps to "DD^"

The PCI Special Interest Group confirmed they do not have any mappings
from vendor ID to ASCII.


# d6a0e38a 25-Sep-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Remove five now unused fields from struct cdevsw. They should never
have been there in the first place. A GENERIC kernel shrinks almost 1k.

Add a slightly different safetybelt under nostop for tty drivers.

Add some missing FreeBSD tags


# cb899cd4 02-Sep-1999 Luoqi Chen <luoqi@FreeBSD.org>

Handle for passthru resource release correctly.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 9dcbe240 23-Aug-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Convert DEVFS hooks in (most) drivers to make_dev().

Diskslice/label code not yet handled.

Vinum, i4b, alpha, pc98 not dealt with (left to respective Maintainers)

Add the correct hook for devfs to kern_conf.c

The net result of this excercise is that a lot less files depends on DEVFS,
and devtoname() gets more sensible output in many cases.

A few drivers had minor additional cleanups performed relating to cdevsw
registration.

A few drivers don't register a cdevsw{} anymore, but only use make_dev().


# 15317dd8 28-Jul-1999 Matthew N. Dodd <mdodd@FreeBSD.org>

Alter the behavior of sys/kern/subr_bus.c:device_print_child()

- device_print_child() either lets the BUS_PRINT_CHILD
method produce the entire device announcement message or
it prints "foo0: not found\n"

Alter sys/kern/subr_bus.c:bus_generic_print_child() to take on
the previous behavior of device_print_child() (printing the
"foo0: <FooDevice 1.1>" bit of the announce message.)

Provide bus_print_child_header() and bus_print_child_footer()
to actually print the output for bus_generic_print_child().
These functions should be used whenever possible (unless you can
just use bus_generic_print_child())

The BUS_PRINT_CHILD method now returns int instead of void.

Modify everything else that defines or uses a BUS_PRINT_CHILD
method to comply with the above changes.

- Devices are 'on' a bus, not 'at' it.
- If a custom BUS_PRINT_CHILD method does the same thing
as bus_generic_print_child(), use bus_generic_print_child()
- Use device_get_nameunit() instead of both
device_get_name() and device_get_unit()
- All BUS_PRINT_CHILD methods return the number of
characters output.

Reviewed by: dfr, peter


# aa595acc 28-Jul-1999 Doug Rabson <dfr@FreeBSD.org>

Add support for SYS_RES_DENSE and SYS_RES_BWX resource types. These are
equivalent to SYS_RES_MEMORY for x86 but for alpha, the rman_get_virtual()
address of the resource is initialised to point into either dense-mapped
or bwx-mapped space respectively, allowing direct memory pointers to be
used to device memory.

Reviewed by: Andrew Gallatin <gallatin@cs.duke.edu>


# 0158b2dc 26-Jul-1999 Matthew N. Dodd <mdodd@FreeBSD.org>

Case matters.

DEv_METHOD to DEV_METHOD.


# 5a8cee9a 26-Jul-1999 Matthew N. Dodd <mdodd@FreeBSD.org>

Implement the BUS_PROBE_NOMATCH method for the PCI bus.

This function is called for each device for which no driver
was found.

Output is similar to the eisa_probe_nomatch() function but with the
added benefit of displaying the assigned IRQ (since PCI gives us
this information up front.)

Output is like so:

pci0: unknown card CPQ0508 (vendor=0x0e11, dev=0x0508) at 11.0 irq 9
pci0: unknown card DFZ0508 (vendor=0x10da, dev=0x0508) at 11.0 irq 9
pci0: unknown card DBL0508 (vendor=0x104c, dev=0x0508) at 11.0 irq 9
pci0: unknown card DDM0011 (vendor=0x108d, dev=0x0011) at 11.0 irq 9

I'm not happy with the 3 lines of macro cruft that got added but
I consider it a temporary annoyance as those bits will be moved to
some place where PCI, EISA and ISAPNP code will be able to use them.

(Not surprisingly, this message is longer than the code in question.)

Reviewed by: peter, dfr


# 9929d2a0 03-Jul-1999 Peter Wemm <peter@FreeBSD.org>

Eliminate a bunch of #include "pci.h" and #if NPCI > 0 around entire
files. config will leave the whole file out if configured to do so.


# f078b1e0 01-Jul-1999 Peter Wemm <peter@FreeBSD.org>

#include <machine/md_var.h> to bring the prototype for
alpha_platform_assign_pciintr() into scope (!).


# 153eb46f 31-May-1999 Roger Hardiman <roger@FreeBSD.org>

On the new Meteor cards, the Philips SAA 7116 is connected to the PCI bus
via an IBM PCI-PCI bridge (82351 or 82352 or 82353)

The driver must identify if it is on a secondary PCI bus, which is
created via the IBM PCI-PCI bridge. If it is, then it must initialise
the IBM PCI-PCI bridge correctly.

To do this, the following new functions are added.
Because they use the pcici_t tag, they are considered 2.2 compatibility APIs
pcici_t * pci_get_parent_from_tag(pcici_t tag);
int pci_get_bus_from_tag(pcici_t tag);

(The _from_tag suffix is used to prevent clashes with similarly named
newbus PCI API functions)

Submitted by: Anton Berezin <tobez@plab.ku.dk>
Reviewed by: Doug Rabson <dfr@nlsystems.com>
Reworked by: Me (roger)


# 2447bec8 31-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Simplify cdevsw registration.

The cdevsw_add() function now finds the major number(s) in the
struct cdevsw passed to it. cdevsw_add_generic() is no longer
needed, cdevsw_add() does the same thing.

cdevsw_add() will print an message if the d_maj field looks bogus.

Remove nblkdev and nchrdev variables. Most places they were used
bogusly. Instead check a dev_t for validity by seeing if devsw()
or bdevsw() returns NULL.

Move bdevsw() and devsw() functions to kern/kern_conf.c

Bump __FreeBSD_version to 400006

This commit removes:
72 bogus makedev() calls
26 bogus SYSINIT functions

if_xe.c bogusly accessed cdevsw[], author/maintainer please fix.

I4b and vinum not changed. Patches emailed to authors. LINT
probably broken until they catch up.


# 4e2f199e 30-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

This commit should be a extensive NO-OP:

Reformat and initialize correctly all "struct cdevsw".

Initialize the d_maj and d_bmaj fields.

The d_reset field was not removed, although it is never used.

I used a program to do most of this, so all the files now use the
same consistent format. Please keep it that way.

Vinum and i4b not modified, patches emailed to respective authors.


# bcbb365b 30-May-1999 Doug Rabson <dfr@FreeBSD.org>

In pci_alloc_resource() only check start and end to see if its a default.


# aa6de8e0 20-May-1999 Andrew Gallatin <gallatin@FreeBSD.org>

Add support for multiple PCI "hoses" used on various alpha platforms.
The specific intent of this commit is to pave the way for importing
Compaq XP1000 support. These changes should not affect the i386 port.

Reviewed by: Doug Rabson <dfr@nlsystems.com>
(actually, he walked me through most of it & deserves more than reviewd-by
credit )


# 41787a35 10-May-1999 Doug Rabson <dfr@FreeBSD.org>

Add missing suspend/resume methods.


# cc97c921 09-May-1999 Peter Wemm <peter@FreeBSD.org>

For the ioctl that reads the pci configuration, look up the name and unit
on the fly so that we can see the driver assignment of new pci devices
as well in the 'pciconf -l' display.


# c0ccf7c6 09-May-1999 Peter Wemm <peter@FreeBSD.org>

Argh, don't clobber the pci device list if there are multiple busses!
(An AGP counts as a PCI bus, it seems...)
This stopped 'pciconf -l' from working on AGP or PCI->PCI bridge systems.


# 566643e3 08-May-1999 Doug Rabson <dfr@FreeBSD.org>

Move the declaration of the interrupt type from the driver structure
to the BUS_SETUP_INTR call.


# 141ed062 08-May-1999 Peter Wemm <peter@FreeBSD.org>

Print 'irq nn' on the device attach line like the old pci code did.
However, we are not printing 'int a/b/c/d' yet, is it worth it on non-SMP
systems? (It's useful when tracing PCI->IO-APIC routing on SMP systems)


# 31c82d83 08-May-1999 Peter Wemm <peter@FreeBSD.org>

GC pci_bushigh() - no longer used.


# 2850fee5 06-May-1999 Peter Wemm <peter@FreeBSD.org>

Fix a goof on my part; s/struct moduledata */struct module */


# 46f40af0 24-Apr-1999 Peter Wemm <peter@FreeBSD.org>

Replace the pcidevice_set linker set based configuration mechanism for old
style pci drivers with a simple one-line change to use a module that
registers itself under new-bus and should in theory enable just about all
of the pci drivers to be loadable (kldload and loader(8)) but without
having the impact of converting the APIs yet.

This also fixes the problem of having undefined variables when only
new-style pci drivers are present.


# 6182fdbd 16-Apr-1999 Peter Wemm <peter@FreeBSD.org>

Bring the 'new-bus' to the i386. This extensively changes the way the
i386 platform boots, it is no longer ISA-centric, and is fully dynamic.
Most old drivers compile and run without modification via 'compatability
shims' to enable a smoother transition. eisa, isapnp and pccard* are
not yet using the new resource manager. Once fully converted, all drivers
will be loadable, including PCI and ISA.

(Some other changes appear to have snuck in, including a port of Soren's
ATA driver to the Alpha. Soren, back this out if you need to.)

This is a checkpoint of work-in-progress, but is quite functional.

The bulk of the work was done over the last few years by Doug Rabson and
Garrett Wollman.

Approved by: core


# 66235db5 10-Apr-1999 Eivind Eklund <eivind@FreeBSD.org>

Staticize.


# 441e39d7 19-Jan-1999 Stefan Eßer <se@FreeBSD.org>

Fix problem with zero valued map registers followed by valid map entries.
The previous code just ignored the invalid map register, but this gave
surprising results because of the way pci_map_port() associated the map
register offset supplied with a map entry in the map array.


# 44b74eef 11-Jan-1999 Eivind Eklund <eivind@FreeBSD.org>

Remove 'pci_bridgeto' - it was just an empty placeholder.


# 96fca41f 09-Nov-1998 Peter Wemm <peter@FreeBSD.org>

s/%#p/%p/ to fix a warning. This looks like a leftover of once being
%#x, which causes a leading 0x to be prepended. %p has this by default
and the '#' is ignored by the kernel prinf code for %p.


# cd8ab93c 03-Nov-1998 Julian Elischer <julian@FreeBSD.org>

In the cyrix Cx5530, there are null (empty) Base address registers before the
base register that controls Ultra-DMA, so we need to examine all possible
base registers instead of just giving up at the first empty one.
Also, looking at the source code to the BIOS, I see that they are also
checking for 0xffffffff as an invalid value so do the same. Stefan may like
to clean this up, but at least now I can find my PCI IDE registers.


# 98ffb0c4 16-Sep-1998 Doug Rabson <dfr@FreeBSD.org>

Some workarounds for a common DEC pci-pci bridge found on alphas.
Fix printf format errors which show up on the alpha.


# 5ee58402 15-Sep-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

Correct printf format bugs.


# 06915ea6 15-Sep-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

Revive PCIConf.

Submitted by: "Kenneth D. Merry" <ken@plutotech.com>


# 572d053e 06-Sep-1998 Tor Egge <tegge@FreeBSD.org>

Maintain a mapping from irq number to (ioapic number, int pin) tuple,
and use this when masking/unmasking interrupts.

Maintain a mapping from (iopaic number, int pin) tuple to irq number,
and use this when configuring devices and programming the ioapics.

Previous code assumed that irq number was equal to int pin number, and
that the ioapic number was 0.

Don't let an AP enter _cpu_switch before all local apics are initialized.


# 188fafbc 13-Aug-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

Use "baseclass" instead of "class" for storing the contents of PCI register
0xB so that C++ programs can use the PCI conf interface.


# e8669bcd 22-Jul-1998 Doug Rabson <dfr@FreeBSD.org>

Add a call to a platform-specific irq remapping function for alpha platforms
which don't record the correct irqs in PCI config space.

Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>


# ecbb00a2 07-Jun-1998 Doug Rabson <dfr@FreeBSD.org>

This commit fixes various 64bit portability problems required for
FreeBSD/alpha. The most significant item is to change the command
argument to ioctl functions from int to u_long. This change brings us
inline with various other BSD versions. Driver writers may like to
use (__FreeBSD_version == 300003) to detect this change.

The prototype FreeBSD/alpha machdep will follow in a couple of days
time.


# 5758c2de 01-Apr-1998 Tor Egge <tegge@FreeBSD.org>

Add two workarounds for broken MP tables:

- Attempt to handle PCI devices where the interrupt is
an ISA/EISA interrupt according to the mp table.

- Attempt to handle multiple IO APIC pins connected to
the same PCI or ISA/EISA interrupt source. Print a
warning if this happens, since performance is suboptimal.
This workaround is only used for PCI devices.

With these two workarounds, the -SMP kernel is capable of running on
my Asus P/I-P65UP5 motherboard when version 1.4 of the MP table is disabled.


# 7b778b5e 23-Jan-1998 Eivind Eklund <eivind@FreeBSD.org>

Make all file-system (MFS, FFS, NFS, LFS, DEVFS) related option new-style.

This introduce an xxxFS_BOOT for each of the rootable filesystems.
(Presently not required, but encouraged to allow a smooth move of option *FS
to opt_dontuse.h later.)

LFS is temporarily disabled, and will be re-enabled tomorrow.


# 4a11ca4e 07-Nov-1997 Poul-Henning Kamp <phk@FreeBSD.org>

Remove a bunch of variables which were unused both in GENERIC and LINT.

Found by: -Wunused


# 35b8b2dd 13-Sep-1997 Peter Wemm <peter@FreeBSD.org>

Update select -> poll in drivers.


# 1fd0b058 02-Aug-1997 Bruce Evans <bde@FreeBSD.org>

Removed unused #includes.


# 91f7398b 25-Jun-1997 Steve Passe <fsmp@FreeBSD.org>

Modified to use renamed get_pci_apic_irq() -> pci_apic_pin() function.


# 1a26f4c0 02-Jun-1997 Stefan Eßer <se@FreeBSD.org>

Move call of pci_addcfg() before test of cfg->subordinatebus, since the
device probe of a host to PCI bridge may modify that value, based on
its knowledge of device specific registers. This makes the Intel XXpress
work, as verified by: Terje Marthinussen <terjem@cc.uit.no>.


# a9ad9373 28-May-1997 Stefan Eßer <se@FreeBSD.org>

Two minor changes to the code that builds the pci map array:
1) Stop at the first map register that contains a zero value.
2) When testing for the map size work up from low values, since
this works around a bug in some BusLogic SCSI card, which has
the 16 upper port base address bits hardwired to zero.

The config register dump printed in the bootverbose case has
been slightly rearranged.


# 6ef807e5 27-May-1997 Steve Passe <fsmp@FreeBSD.org>

Minor cleanup of APIC_IO code.

Submitted by: Stefan Esser <se@freebsd.org>


# ce595b36 26-May-1997 Steve Passe <fsmp@FreeBSD.org>

Add support for APIC_IO to pci IRQ configuration.

The support for APIC_IO was lost in the new set of pci modules. This patch
restores the ability to build SMP/APIC_IO kernels.


# 5bec6157 26-May-1997 Stefan Eßer <se@FreeBSD.org>

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).


# b038679c 03-May-1997 Poul-Henning Kamp <phk@FreeBSD.org>

Initialize PCI/CardBus bridges.

Tested on: HP Omnibook 800 / TI PCI1130
Reviewed by: se


# 477a642c 26-Apr-1997 Peter Wemm <peter@FreeBSD.org>

Man the liferafts! Here comes the long awaited SMP -> -current merge!

There are various options documented in i386/conf/LINT, there is more to
come over the next few days.

The kernel should run pretty much "as before" without the options to
activate SMP mode.

There are a handful of known "loose ends" that need to be fixed, but
have been put off since the SMP kernel is in a moderately good condition
at the moment.

This commit is the result of the tinkering and testing over the last 14
months by many people. A special thanks to Steve Passe for implementing
the APIC code!


# 7cb74fcf 23-Apr-1997 Stefan Eßer <se@FreeBSD.org>

Add preliminary support for PCI config header type 2:
Fetch subvendor/device ID from config space register 0x40.


# 6072387d 25-Mar-1997 Stefan Eßer <se@FreeBSD.org>

Fix printing of map sizes: large numbers got a negative sign before.


# ee886457 25-Mar-1997 Stefan Eßer <se@FreeBSD.org>

Add a few vendor IDs and class and sub-class encodings.

Submitted by: phk


# 6875d254 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not
ready for it yet.


# 19637884 05-Feb-1997 Andrey A. Chernov <ache@FreeBSD.org>

Fix misspelled variable name, -current build stopper


# cfc23ad4 04-Feb-1997 Stefan Eßer <se@FreeBSD.org>

Add interface revision field to pci_register_lkm parameter list.pci.c pcibus.h
This parameter is intended to allow new kernels to work with old LKM binaries,
provided the revision ID is incremented whenever the PCI LKM interface is
changed. The revision ID does not at all protect against changes in data
structures accesses by the driver.


# e8bfed6d 24-Jan-1997 Stefan Eßer <se@FreeBSD.org>

Improve on previous fix: Clean up getirq() as well, and remove redundant
warning messages.


# a67fa103 23-Jan-1997 Stefan Eßer <se@FreeBSD.org>

Make IRQ 0 invalid in pci_map_int(), since it is hardwired to the
programmable interval timer chip in PC systems.


# 993dec9d 21-Jan-1997 Stefan Eßer <se@FreeBSD.org>

Add PCI LKM support.


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 576b74fc 12-Nov-1996 Stefan Eßer <se@FreeBSD.org>

Add support for header type == 1 devices (PCI 2.1 compatible PCI to PCI
bridges with support for 64 bit memory addresses and 32 bit I/O addresses).

The code is not complete. It ignores the upper half of the long addresses.
This is not a problem on PC compatible systems, but has to be fixed for
real computers.


# c88529d0 12-Nov-1996 Stefan Eßer <se@FreeBSD.org>

Fix PCI to PCI bridge register bit field masks.

Thanks to "Mike Durian" <durian@plutotech.com> for the very good
problem report and his support as a beta tester of this patch.


# 10e966fa 22-Oct-1996 Stefan Eßer <se@FreeBSD.org>

Add support for ioctl() accesses to PCI config space registers.
Garrett Wollman sent me this code a few weeks ago for review, and I made
some significant changes, which he in turn accepted ...

In order to make use of these changes, a device entry has to added to /dev.

Submitted by: wollman


# b86a81e4 14-Oct-1996 Stefan Eßer <se@FreeBSD.org>

pci_map_mem() did a too restrictive check on the mapping type:
PCI_MAP_MEMORY_TYPE_32BIT_1M should be accepted as well as
PCI_MAP_MEMORY_TYPE_32BIT (and now is).
(Problem reported by David Greenman.)


# b568ea4e 10-Sep-1996 Bruce Evans <bde@FreeBSD.org>

Removed more devconf leftovers.


# bfbb029d 06-Sep-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Remove devconf, it never grew up to be of any use.


# 77b3da75 05-Sep-1996 Stefan Eßer <se@FreeBSD.org>

Fix code that deals with multiple host to PCI bridges by making the next
one use the highest seen bus number plus 1 as its starting point.


# 7fa8a688 02-Sep-1996 Stefan Eßer <se@FreeBSD.org>

Add preliminary support for the Orion PCI chip set. It is special in the
way it attaches multiple PCI buses directly to the CPU, instead of having
them hanging off from PCI to PCI bridges. This code is a hack, and will
be obsoleted by the planned rework of the PCI code, which will change the
dealing with PCI to PCI bridges and other special devices significantly.

The patch also adds a kern_devconf entry for PCI bus 0 which is assumed
to be a child of cpu0. The new PCI code will make it possible to hand out
the kern_devconf structure to a pci device being attached, since this is
(regretably, IMHO) required by a few ISA devices.

Finally there are new PCI ids for some Intel chip set devices, which had
already been known to 2.1.5R, but did not make it into -current. This closes
"kern/1558: PCI probe seems to have lost a device in -current".


# 58e025d5 09-Jun-1996 Satoshi Asami <asami@FreeBSD.org>

Scan PCI buses in order the BIOS has assigned them. This is sometimes
necessary to boot from a SCSI disk connected to a twin-channel adapter,
and you have multiple of them (disks and adapters).

Reviewed by: se


# 4beaf036 18-May-1996 Stefan Eßer <se@FreeBSD.org>

Fix range check to actually test the variable that will be used as
an index later.

Submitted by: Erich Stefan Boleyn <erich@uruk.org>


# f8176d83 25-Apr-1996 Satoshi Asami <asami@FreeBSD.org>

Fix logic bug in pci bridge code. For a PCI-PCI bridge, secondary
should be <= than subordinate, not the other way around.

They are both true if the bridge is not cascaded (i.e., twin-channel
scsi/e-net adapters won't be affected by this bug), which is probably why
it was unnoticed until today.


# 68159c89 14-Apr-1996 Stefan Eßer <se@FreeBSD.org>

Update PCI bus code from my current sources:

- always use pci_conf_read() and pci_conf_write(). (This is required to
simulate non-existant devices in my system for PCI bridge code tests.)

- reorder some functions (put the main functions at the end).

- correct off by one bug in the code dealing with unitialized PCI to PCI
bridge chips. (Bug found by ASAMI Satoshi.)

- print function number for multi-function devices.


# 3157adc8 07-Apr-1996 Bruce Evans <bde@FreeBSD.org>

Removed now-unused #includes of <machine/cpu.h>. They were for bootverbose
being declared in the wrong place.


# 8ec7a852 18-Feb-1996 Stefan Eßer <se@FreeBSD.org>

Remove limit of port I/O addresses to 65K, since PCI specifies 32 bit
port addresses (even though the PC architecture doesn't support them).

Add code to limit the I/O map size based on the lowest set bit of the
address. This cures the problem with the BT946C only having a 16 bit
map register, in voiolation of the PCI specs, without giving up the
general support of >65K port regions.


# 07d9d14a 17-Feb-1996 Stefan Eßer <se@FreeBSD.org>

Add generic PCI to PCI bridge support.
Improve verbose boot messages for unidentified chips.


# dcf289cd 29-Jan-1996 Stefan Eßer <se@FreeBSD.org>

Add heuristic to detect multi-function devices that don't announce this
feature in the header type register, though it is required by the PCI spec.
This should correctly probe both functions of the Intel 82371FB chip,
without the need for a special case based on the device ID.


# 31c56328 27-Jan-1996 Garrett Wollman <wollman@FreeBSD.org>

Decode configuration for the IDE part of the Triton chipset. This
includes a hack in the probe code: the 82371FB is a multifuction
device, but doesn't properly set the configuration bit which
indicates this. So, we just hard-wire all 82371FBs as multifunction
devices.

This does not actually make the bus-master IDE stuff work, although
if anyone wants to work on that, I have the databooks that tell
how to use it.


# e653d76e 25-Jan-1996 Stefan Eßer <se@FreeBSD.org>

Add support for multi-function devices.


# dd7610fc 23-Jan-1996 Stefan Eßer <se@FreeBSD.org>

Make PCI interrupt handlers return void like everybody else does.

Reviewed by: davidg


# e66a4e40 19-Jan-1996 Stefan Eßer <se@FreeBSD.org>

Improve PCI probe messages by printing the bus number.
Add missing newline to PCI to PCI bridge message.

Submitted by: Matt Thomas <matt@lkg.dec.com>


# 6ea3e9d8 15-Dec-1995 Bruce Evans <bde@FreeBSD.org>

Completed function declarations and/or added prototypes and/or added
#includes to get prototypes.

pci now uses a different interrupt handler type for interrupts that it
dispatches and the isa interrupt handler type for the interrupts that
it handles.


# 6549c8c9 15-Dec-1995 Stefan Eßer <se@FreeBSD.org>

Fix the off-by-one error in the calculation of the valid port range.
Reduce default value of pcicb_membase to 0x2000000 (from 0x4000000)
since this seems to be the lower bound used by many systems.

Submitted by: Mihoko Tanaka <m_tanaka@pa.yokogawa.co.jp>


# f708ef1b 14-Dec-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Another mega commit to staticize things.


# efeaf95a 06-Dec-1995 David Greenman <dg@FreeBSD.org>

Untangled the vm.h include file spaghetti.


# 94fed3c1 06-Dec-1995 Stefan Eßer <se@FreeBSD.org>

Set default burst length limit to 32 bytes, since this seems to be
an acceptable value for all current chip sets (just a hint to PCI
device drivers, used in the NCR driver, for example).
Add PCI Vendor ID of ACER.


# 8be8b2a1 21-Nov-1995 Bruce Evans <bde@FreeBSD.org>

Made pci.c compile again. It unfortunately depends on the isa interrupt
interface. Adding prototypes just made the dependency explicit.


# 4b2af45f 19-Nov-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Mega commit for sysctl.
Convert the remaining sysctl stuff to the new way of doing things.
the devconf stuff is the reason for the large number of files.
Cleaned up some compiler warnings while I were there.


# df31aac5 02-Oct-1995 David Greenman <dg@FreeBSD.org>

Fixed bug where wrong thing was being checked for NULL before calling
free(), resulting in a panic. This happend whenever an irq had already
been allocated by another device (like something on the ISA bus).


# da42a6e8 14-Sep-1995 Stefan Eßer <se@FreeBSD.org>

Add vendor ID of Compaq, now that I found what it is ...


# 7324a7b3 14-Sep-1995 Stefan Eßer <se@FreeBSD.org>

Minor changes to the PCI probe messages.


# ab2e900f 07-Sep-1995 Stefan Eßer <se@FreeBSD.org>

Make mapping messages depend on bootverbose flag.
Add PCI subclass to unknown device message.


# fa8d3a82 29-Jul-1995 David Greenman <dg@FreeBSD.org>

Initialize "name" to quiet compiler.


# bd919217 27-Jul-1995 Stefan Eßer <se@FreeBSD.org>

Add a few vendor IDs.


# 54a21634 27-Jul-1995 Stefan Eßer <se@FreeBSD.org>

Get rid of references to the linker supplied set length field.
Use the terminating NULL pointer as the end of list marker instead.


# c411726b 28-Jun-1995 Stefan Eßer <se@FreeBSD.org>

Change message "not supported" to "no driver assigned", because
people tend to assume their devices won't work if they see this
message, though it may indicate that those devices just don't
need any PCI driver (e.g. devices that emulate an ISA card, or
that have been initialised by the BIOS and need no further care).


# 78e44466 28-Jun-1995 Stefan Eßer <se@FreeBSD.org>

Failure of the consistency checks for BIOS assigned mappings of busses
connected via PCI to PCI bridges is considered non fatal for now.


# 9b2e5354 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# cbb15d7c 04-May-1995 David Greenman <dg@FreeBSD.org>

bzero the malloced pci_devconf structure. This should fix the problem with
several of freefall's recent crashes.


# a54907a1 22-Mar-1995 David Greenman <dg@FreeBSD.org>

Restore my changes to initialize the kdc_shutdown routine pointer. Stefan
clobbered it in his previous commit and not having it causes the machine
to panic during reboot (as well as not doing the important shutdown callout).


# 8673e05a 21-Mar-1995 Stefan Eßer <se@FreeBSD.org>

Completely new PCI code:

1) Supports PCI to PCI bridge devices (and tries to initialise them,
even if the BIOS is brain dead).
2) Supports shared PCI interrupts. Interrupt handlers now MUST return
'0' if they found nothing to do, '1' otherwise.

New features tested with i486 systems based on the Intel Saturn and
a DEC 4channel Ethernet card only, but expected to work on most systems.

The option PCI_REMAP has been removed !

Submitted by: Wolfgang Stanglmeier <wolf@kintaro.cologne.de>


# cb09d35c 16-Mar-1995 David Greenman <dg@FreeBSD.org>

Added a new field to the pci_device struct called pd_shutdown to specify
a device specific shutdown routine for devconf. Assign the value of this
to the kern_devconf struct. Implement a device shutdown routine for if_de
that disables the device. This will stop the device from corrupting memory
after a reboot.


# 79a6470e 02-Mar-1995 Stefan Eßer <se@FreeBSD.org>

Speed up PCI attach code by ommiting test if its result is ignored anyway.


# 04dbb408 27-Feb-1995 Stefan Eßer <se@FreeBSD.org>

First try to add support for PCI-PCI bridge chips (written for the
DEC 21050 chip in particular, don't have specs of other such chips).

This should add support for Multiple-Ethernet PCI cards (e.g. Znyx 314).

Reviewed by: se
Submitted by: <wolf@kintaro.cologne.de> Wolfgang Stanglmeier


# ef2dee21 25-Feb-1995 Stefan Eßer <se@FreeBSD.org>

Deal with systems, that lack a fully decoded PCI configuration space.

Submitted by: <wolf@kintaro.cologne.de> Wolfgang Stanglmeier


# d9dc2f74 22-Feb-1995 Stefan Eßer <se@FreeBSD.org>

New PCI attach code:

PCI BIOS mappings are retained, except if option PCI_REMAP
is specified in the kernel config file.
There is now a list of attach addresses, and the first
address that seems to make some device registers appear
is chosen.

Reviewed by: se
Submitted by: wolf


# 9ddf9699 14-Feb-1995 Stefan Eßer <se@FreeBSD.org>

ncr.c:

New config option "NCR_IOMAPPED" makes the driver use port I/O.
Put back in 53c815 defines, submitted by Mikael Hybsch <micke@dynas.se>.
These had got lost between cvs rev. 1.14 and now ...

pci.c:

Really write config space register.
Assign ports starting at 0xbc00.

Submitted by: wolf
Reviewed by: se


# a14b2c28 13-Feb-1995 Poul-Henning Kamp <phk@FreeBSD.org>

YFfix


# fd65acba 09-Feb-1995 Stefan Eßer <se@FreeBSD.org>

Try to detect overlapping PCI memory assignment.
(This can only happen with devices that are mapped
by the BIOS.)

Reviewed by: se
Submitted by: wolf (Wolfgang Stanglmeier)


# 6398cf31 02-Feb-1995 David Greenman <dg@FreeBSD.org>

Reapplied all of Stefan's changes. What a mess - the files were modified
and moved at the same time. This made it *very* difficult to fix the
revision log lossage that happend when the files were moved. SIGH.


# 77e50733 01-Feb-1995 David Greenman <dg@FreeBSD.org>

Fixed up include paths after copying these in the repository.


# 66da5964 02-Nov-1994 Stefan Eßer <se@FreeBSD.org>

Submitted by:
Added hooks for "lsdev" ...
PCI devices should need no individual code for lsdev.


# 422cdd61 25-Oct-1994 Stefan Eßer <se@FreeBSD.org>

Modified fifth parameter (imask) to register_intr() according to
new definition of that function.


# 65772aee 11-Oct-1994 Stefan Eßer <se@FreeBSD.org>

Submitted by: Wolfgang Stanglmeier <wolf@dentaro.GUN.de>
Bug fixed, that caused system hang on first interrupt on some motherboards.

New version of PCI bus configuration code, now supports dynamic interrupt
configuration (using BIOS supplied values).
NCR SCSI and DEC Ethernet driver patched to use this feature.
*** Remove PCI IRQ specifications from your kernel config file ! ***


# e902866c 30-Sep-1994 Garrett Wollman <wollman@FreeBSD.org>

Correct DEC -> Digital Equipment Corporation.


# 799e5f27 28-Sep-1994 Stefan Eßer <se@FreeBSD.org>

Submitted by: Wolfgang Stanglmeier <wolf@dentaro.GUN.de>
New version with improved support for WIDE SCSI using the NCR 53c825.
Test for buggy secondary cache implementations.
PCI Int to IRQ mapping now specified per slot.


# 4a078e7d 15-Sep-1994 Stefan Eßer <se@FreeBSD.org>

Submitted by: Wolfgang Stanglmeier <wolf@dentaro.GUN.de> + <se>
Improved bus probing, symbolic names for registers..
Chip set parameters get dumped for intel PCI chip sets
(82424+82434 only, for now).


# f86233fe 13-Sep-1994 Garrett Wollman <wollman@FreeBSD.org>

Added a bit of missing functionality to make this work correctly on a
wider variety of systems. Include the deivers from pci_intel.c in
pci_config.c (I hope this is what was intended; my system works ok).
Use pmap_mapdev(). Automatically map any large linear frame buffers
or whatnot in VGA-style devices which ordinarily would not have their
own drivers, and don't call not_supported() for them. (This shuts up
complaints about my Matrox card.) Include the beginnings of what could
eventually become dynamically-loadable PCI devices. Allow for the
possibility of PCI devices simply providing a PCI veneer over an existing
ISA device, and shut up about them, too.
Make autoconfiguration text conform more to the style of other supported
buses.


# 37bd2c9c 31-Aug-1994 Stefan Eßer <se@FreeBSD.org>

Submitted by: Wolfgang Stanglmeier <wolf@dentaro.GUN.de> + Stefan Esser <se>
Directory for PCI autoconfigure and device driver code.