35 Commits

Author SHA1 Message Date
Travis Geiselbrecht
664bb17afa [ubsan] fix some bugs and warnings discovered by ubsan
- X86 cpuid feature list dump was using the wrong array and walking off
  the end of one.
- GICv2 code had a left shift by up to 31 of an integer. Needs to be
  unsigned.
- PLIC same as GIC code.
- fdtwalker code should be using a bytewise accessor based helper
  function for reading large integers out of an unaliged FDT.
- PCI BIOS32 search code could do a 32bit unaligned read of a string,
  switch to using memcmp.
2025-10-05 15:35:31 -07:00
Travis Geiselbrecht
355b62b13a [pci] fix a warning that only shows up on gcc 7.5.0 2025-10-05 14:22:41 -07:00
Travis Geiselbrecht
72112c0676 [pci] little bit of code cleanup in the pci bus driver
Mostly just suggestions by clang-tidy. No functional change.
2025-09-23 23:16:55 -07:00
Alex Richardson
d22534704d pci: remove write-only variable
This is not used anywhere so just drop it.
2025-01-07 22:28:07 -08:00
Travis Geiselbrecht
bd423cad4d [lib][fdtwalk] skip scanning pci busses marked 'disabled' 2024-06-19 16:18:28 -07:00
Travis Geiselbrecht
2f98fbf772 [pci][fdt] do not attempt to configure PCI with 64bit bars on a 32bit system
Especially in the case where the 32bit system doesn't have an MMU, avoid
using any high addresses for BARs.
2024-05-09 22:18:19 -07:00
Travis Geiselbrecht
9a4fae0714 [warnings] remove some extraneous __PACKED attributes
Also remove a few extra data structures that were marked packed but not
otherwise used anywhere.
2024-04-19 00:07:49 -07:00
Alex Richardson
6b29ec9223 [clang] Silence unused private member warning
We could also remove this variable, but it seems best to keep it to
retain the same struct layout.
2023-04-23 17:23:31 -07:00
Pedro Falcato
93a8b45ada [bus][pci] Clarify device::assign_resource
The previous XXX comments were unnecessary as the spec defines the
bottom 3 bits as being hardwired and read-only.
2023-01-15 18:35:49 -08:00
Pedro Falcato
3b4dade91f [bus][pci] Disable IO and mem decoding around BAR enumeration
Disable IO and mem decoding around BAR enumation as described in the PCI
Local Bus specification. This behavior should be safer when messing
around BARs for BAR lengths.
2023-01-15 18:35:49 -08:00
Travis Geiselbrecht
611bd1cba0 [bus][pci] ask for 4MB alignment when mapping the ecam
This helps any architecture that might have a better chance with using
large pages.
2022-10-21 23:47:47 -07:00
Travis Geiselbrecht
96231b132f [bus][pci] make the pci bus dump on bootup use a little less horizontal space
Should fit better on an 80 column display
2022-10-19 00:24:10 -07:00
Travis Geiselbrecht
3a6c4aed8f [bus][pci] do not automatically initialize the bus manager in pci_init_legacy
This lets the caller do any last minute resource set up before starting
the bus manager. Is consistent with the way pci_init_ecam() works.
2022-10-18 23:58:18 -07:00
Wencheng Yang
853bce759d [dev][bus][pci] fixed type1_read_byte API bug
It should invoke type1_read_byte() rather than type1_read_half.
2022-08-11 23:33:15 -07:00
Travis Geiselbrecht
e555db5bda [bus][pci] at least register that MSIX is available
Doesn't yet have support for it, but set the bool and remember it was
present when scanning devices.
2022-02-27 19:36:59 -08:00
Travis Geiselbrecht
979cebecf2 [bus][pci] Make sure there's a fallback range in release mode 2022-02-06 20:50:24 -08:00
Travis Geiselbrecht
f1431b81d0 [bus][pci] Support for dynamically assigning BARs and bridges if needed
In the case of platforms where a bios or firmware has not already
assigned all the resources, do so. Requires the platform supply one or
more ranges of physical address space and IO that can be mapped into
BARs.

Handles iterating through bridges, computing the sizes of all the
peripherals downstream and rolling that up as well.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
36e73e0fac [bus][pci] add routines to pass in PCI bus resources prior to starting the pci bus manager
Wire them up on arm and riscv which need them. x86-pc does not, so dont
call it.

Also fix a few miscellaneous bugs, notably PCI not detecting 64bit bars
properly due to an off by one bit error.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
d5f394859d [bus][pci] first stab at assigning bus numbers to unconfigured bridges
Had to rearrange the proble logic somewhat, but now the bus manager will
assign consequtive bus numbers as it finds bridges and recursively
drills down to discover the entire bus structure.

Does not assign resources yet, but need to do this in the first pass
to find all of the devices before can figure out how much space they
occupy.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
ba21aa9236 [bus][pci] quick hack to not dive into bridges that appear unconfigured
This fixes an infinite recursion where it was stepped into bridge a
bridge that has the secondary bus set to 0, which caused it to start
over and probe bus 0 until it blew the stack.

Better fix is to actually assign busses.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
07f847e38a [bus][pci] add accessors for bridge ranges and print on dump 2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
95443413e8 [bus][pci] break the bus manager file into separate cpp files per object
No functional change aside from rearranging things.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
5e92f0adf7 [bus][pci] move the bus manager code into a subdir 2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
ef8d252a8a [bus][pci] load BARs for bridges as well
Dump them in the pci dump
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
ef67d619a5 [bus][pci] load bars for devices even if their address is 0
Probe the size first, and if that turns up anything, mark the bar as
valid, even if the address is set to 0. The address can be configured in
a later pass of the bus manager.

Also print the bars on boot.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
2ab1af0bf3 [bus][pci] add a virtual module that references all the pci drivers
Not sure if this is the right way to go forward, but it at least keeps
from having to copy/paste the same module list in a few different
places.
2022-02-06 19:46:39 -08:00
Travis Geiselbrecht
278c551821 [dev][pci] read and cache BAR sizes at probe time
Since probing the size of a BAR requires writing and reading back from
the address field, do it at probe time and cache the data instead of at
api time. This should avoid fouling up any mmio transactions in flight.
2022-01-11 01:24:17 -08:00
Travis Geiselbrecht
fb1e414a09 [dev][bus][pci] major refactor of the PCI bus driver
-Add a bus manager level, which is an object oriented walk of the pci
busses to build a per device object for later manipulation.
-Add features to enable MSI interrupts.
-Extend generic interrupt api to allow the platform to allocate vectors
for MSI interrupts.
-Rearrange a bit of the pc platform for the platform api changes.
-Add PC platform support for using the local apic to EOI MSI vectors.
-Fix up a few existing PCI drivers for small API changes.
-Add a few stubbed out routines for non PC platforms that use PCI.
2021-12-27 22:24:31 -08:00
Travis Geiselbrecht
0c27d8fe45 [bus][pci] first stab at PCI-e ECAM support 2021-11-12 20:44:47 -08:00
Travis Geiselbrecht
7285a2d1fd [bus][pci] convert the pci driver's back end to simple C++ objects
It was already rolling a vtable so go ahead and just implement it as
actual c++ objects.
2021-11-12 20:44:47 -08:00
Travis Geiselbrecht
0aba1b73cc [bus][pci] trivially switch the PCI bus driver to c++
Just minimum to get it to build and work.
2021-11-12 20:44:47 -08:00
Travis Geiselbrecht
a2b41c11d2 [dev][pci] move the pci console commands into the pci bus driver
Remove app/pcitests since it was just the console commands.
2021-11-09 00:19:53 -08:00
Travis Geiselbrecht
b54f5f2b0f [dev][bus][pci] add simple type 1 (IO port based) access mode 2020-03-07 19:40:41 -08:00
Travis Geiselbrecht
389965328f [dev][bus][pci] split the bios32 routines out into a separate file
Disable bios32 mechanism based on architecture (x86-32 only) for now.
2020-03-07 18:39:35 -08:00
Travis Geiselbrecht
a44bc7863d [dev][bus][pci] move the pci driver out of platform/pc into generic space
No functional change.
2020-03-07 18:17:36 -08:00