Commit Graph

93 Commits

Author SHA1 Message Date
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Andrei Emeltchenko 7c81ee9d18 pcie: shell: Add help and argument check
Use SHELL_CMD_ARG() for argument check and add help, looking like:

...

$ pcie -h
  pcie - PCI(e) device information
  Subcommands:
    ls  :List PCIE devices
         Usage: ls [bus:device:function] [dump]

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-08-25 21:14:51 +00:00
Andrei Emeltchenko d46c7595d9 pcie: shell: Verify command parameters
Exit on wrong parameter for pcie ls command.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-08-25 21:14:51 +00:00
Andrei Emeltchenko 054b6d7287 pcie: shell: Replace shell argument with sh
Fix Zephyr coding guidelines warnings.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-08-18 10:19:49 +02:00
Andrei Emeltchenko 3029d2fba8 pcie: shell: Add dump and BDF string arguments
Add argument dump for dumping first 16 PCI configuration space
registers same way lspci -x is doing. Also parse bdf string as
argument. pcie can be called following way:

  uart:~$ pcie 0:1f.4
   ...
  uart:~$ pcie 0:1f.4 dump
   ...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-08-18 10:19:49 +02:00
Simon Hein d0921018fc drivers: Fix coding guidelines MISRAC:2012 Rule 14.4 do-whiles/Zero checks
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

The commit is a subset of the original auditable-branch commit:
5d02614e34

Signed-off-by: Simon Hein <SHein@baumer.com>
2022-07-26 15:30:24 -04:00
Anas Nashif 49b36ead95 drivers: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Rodrigo Cataldo 089ed23a32 drivers: pcie: fix inverted translation for PCIe controller
Invert the physical address given to pcie_ctrl_region_translate() to
match the PCI BAR layout. Previously, physical addresses for memory
space BAR were exposed to bit 3 (prefetchable bit) and 2 (1 type bit) of
the header.

Signed-off-by: Rodrigo Cataldo <rodrigo.cataldo@huawei.com>
2022-07-06 10:45:54 +02:00
Abramo Bagnara ada9ca4c93 coding guidelines: comply with MISRA C:2012 Rule 7.2
MISRA C:2012 Rule 7.2 (A `u' or `U' suffix shall be applied to all
integer constants that are represented in an unsigned type)

Added missing `U' suffixes in constants that are involved in the
analyzed build, plus a few more not to introduce inconsistencies
with respect to nearby constants that are either unused in the
build (but implicitly unsigned) or are used and are immediately
converted to unsigned.

Signed-off-by: Abramo Bagnara <abramo.bagnara@bugseng.com>
2022-06-14 13:36:14 -04:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Bartosz Bilas f5f110bb36 drivers: pcie: iproc: remove superfluous default n for boolean
bool symbols implicitly default to n so
there is no need to redundant those values.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-04-15 10:32:24 -07:00
Neil Armstrong d89efe0434 pcie: ecam: implement MSI/MSI-X interrupts setup
This implements the msi_device_setup() callback for ECAM controllers
used with an ARM GIC ITS MSI message translater.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-03-25 12:56:25 +01:00
Neil Armstrong acd38cb30e pcie: controller: add generic controller MSI/MSI-X API core functions
Define the MSI/MSI-X APIs to be used with the Generic PCIe Controller API.

It notably adds the msi_device_setup() callback to the PCI Express
Controller API used to allocate and setup the MSI/MSI-C vectors on the
MSI message translater HW.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-03-25 12:56:25 +01:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Neil Armstrong 8e0f3d1e5d pcie: controller: add non-recursive pcie busses enumeration
In order to preserve stack, this replaces the single-bus enumeration
loop by a stack based non-recursive pcie hierarchy iteration.

Each stack entry contains a bridge bus enumeration state.

When a bridge endpoint is detected on the current bus, it is
configured and this new bus is pushed on top of the stack in
order to be enumerated at next loop.

When enumeration ends on the bus, the current bus state is
removed from the stack to continue enumeration on the previous
bus.

This enumeration affects a sequential bus number to each new
bus detected in the same order as Linux & U-Boot does.

In this hierarchy:
       [0         1          2   ...   31]
        |         |          |
        EP        |          |
                  |          |
        [0   1  ... 31]   [0  ... 31]
         |   |             |
         |  EP             |
         |              [0 ... 31]
     [0 ... 31]          |
      |                 EP
     EP

We will get the following BDFs enumeration order:
 00:00.0	Endpoint
 00:01.0	Bridge => Bus primary 0 secondary 1
 01:00.0	Bridge => Bus primary 1 secondary 2
 02:00.0	Endpoint
 ... Bus secondary 2 => subordinate 2
 01:01.0	Endpoint
 ... Bus secondary 1 => subordinate 2
 00:02.0	Bridge => Bus primary 0 secondary 3
 03:00.0	Bridge => Bus primary 3 secondary 4
 04:00.0	Endpoint
 ... Bus secondary 4 => subordinate 4
 ... Bus secondary 3 => subordinate 4

The gives the following primary/secondary/subordinate map:
 Bus 0 [0         1              2   ...   31]
        |         |              |
        |      [0:1->2]      [0:3->4]
   EP 00:00.0     |              |
                  |              |
  Bus 1 [0   1  ... 31]  Bus 3 [0  ... 31]
         |   |                  |
         |  EP 01:01.0          |
     [1:2->2]                [3:4->4]
         |                      |
         |            Bus 4  [0 ... 31]
Bus 2 [0 ... 31]              |
       |                     EP 04:00.0
      EP 02:00.0

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 13:37:36 -05:00
Neil Armstrong e937eb97c4 pcie: controller: add Type 1 bridge configuration
This adds setup of Type 1 bridge endpoints in two steps, first when
endpoint is detected and secondly when enumerating the next endpoint.

First, the code configures the bus primary & secondary number and 0xff
as subordinate to redirect all PCIe messages to this bus.

Then memory & I/O base are programmed by getting the current allocation
bases.

Finally, now right away, we program the subordinate to the max bus
number under the bridge, here the same, and the memory & I/O limit,
here lower than the base.

This doesn't make the bridge totally usable, enumeration would work
bus not for nested bridges and BARs wouldn't be accessible.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 13:37:36 -05:00
Neil Armstrong b79d66a712 pcie: controller: split out endpoint enumeration code
In order to prepare support for bridges enumeration, split out the
actual endpoint enumeration code out of the enumeration loop.

Pass a skip_next_func boolean to indicate if the current endpoint
is multifunction of not, to continue to next dev or next function.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 13:37:36 -05:00
Neil Armstrong a1b20d3dd9 pcie: controller: prepare to enumerate bars for Type 1 endpoints
The Type 1 endpoints has 2 BARs are the same position as the Type 0
BARS 0 & 1, so reuse the generic_pcie_ctrl_type0_enumerate_bars()
for both types by passing the number of possible BARs on the endpoint.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 13:37:36 -05:00
Neil Armstrong b2d6096eb5 pcie: ecam: implement callback to get allocation base
Implement callback to get allocation base similar to the
pcie_ecam_region_allocate callback.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 13:37:36 -05:00
Gerard Marull-Paretas 435213a753 drivers: remove redundant data/config casts
Some drivers explicitely casted data/config from void * to the
corresponding type. However, this is unnecessary and, in many drivers it
has been misused to drop const qualifier (refer to previous commits).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Neil Armstrong 9463525347 pcie: controller: rename generic_pcie_ to pcie_generic_
As suggested by Tomasz Bursztyka, it's clearer to move generic after the
domain prefix, here pcie.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 09:47:59 -05:00
Neil Armstrong 6595ca1a35 pcie: controller: rename xlate to translate
As suggested by Tomasz Bursztyka, translate is clearer than xlate in
the PCIe controller functions and callbacks names.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-01-19 09:47:22 -05:00
Tomasz Bursztyka 6ed593f861 drivers/pcie: Extending parameters to pcie_msi_map
n_vector will be necessary for VT-D actually.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka 25b8df0bdb drivers/pcie: Even single MSI based interrupt needs to be remapped
Refactor to handle this case. This is valid only when MSI multi-vector
feature is enabled.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka b5fecc5ff8 drivers/pcie: Add a function for dynamic PCIe IRQ connection
The is meant to fix a chicken & egg issue with MSI interrupt remapping.
Currently, drivers first connect the irq (by-passing any possible MSI
remapping), so the IRQ ends-up being remapped at the IOAPIC level which
is not what we want.

So adding a dedicated function to properly handle this case. This is
valid only for runtime dynamic IRQ connection obviously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka fbb2f1511c drivers/pcie: Add a function to know MSI/MSI-x support of an endpoint
And since it does yet another round of pcie_get_cap() on PCIE_MSI_CAP_ID
and PCIE_MSIX_CAP_ID, let's factorize that into a utility function and
change the relevant places to use that function instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka c1bc5db795 drivers/pcie: Use the generic arch-interface for allocating IRQs
PCIE now uses the new interface. And pcie_alloc_irq() is only made
available when CONFIG_PCIE_CONTROLLER is unset. So only for x86 atm.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-12-22 12:16:52 +01:00
Neil Armstrong f8f2936dba pcie: add initial controller support
This adds :
- Generic PCIe Controller layer implementing the current PCIe API
- Generic PCIe Controller in ECAM mode driver

The Generic PCIe Controller layer provides:
- Configuration space read/write
- single bus endpoint enumerations
- Endpoint I/O, MEM & MEM64 BARs allocation
- Endpoint I/O, MEM & MEM64 BARs get & translation for drivers

The Generic PCIe Controller in ECAM mode driver provides:
- Raw DT RANGES properties into usable PCIe regions
- Configuration space read/write into ECAM config space
- PCIe regions allocation & translation

The limitations are:
- No support for PCIe prefetchable regions
- No support for PCIe bus configuration (only bus0 is supported)
- No support for multiple controllers (no domain-id in BDF)

Support has been designed to initially support Root Complexes with
Root Complex Integrated Endpoint, which was designed for Embedded
Systems with internal-only PCIe Endpoints on bus 0.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-11-25 18:37:15 +01:00
Tomasz Bursztyka 23a0ce4ff3 drivers/pcie: Add PTM root device driver as well as implement PTM API
Any exposed PTM root device will by default see their root capability
enabled so they will become PTM responder.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 11:06:02 -04:00
Tomasz Bursztyka 766f567bfc drivers/pcie: Add PCIE logging module
Such module is missing and will prove to be useful for future features
and/or printing out debug messages on existing ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 11:06:02 -04:00
Krzysztof Chruscinski eb3375f47c shell: Add __printf_like to shell_fprintf
Add __printf_like modifier to validate strings used by shell.
Fixing warnings triggered by this change.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-10-14 16:32:19 -04:00
Andrei Emeltchenko 12f67c11cd pcie: shell: Print more MSI-X information
For pcie ls command print more detailed MSI / MSI-X information.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2021-09-03 10:09:05 -04:00
Andrei Emeltchenko bf4d79a3db pcie: shell: Print 64 bit BARs
Print full 64 bit BARs.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2021-09-03 10:09:05 -04:00
Neil Armstrong 95315239d8 pcie: use newly introduced IDs define for MSI/MSI-X
Remove the locally MSI/MSI-X capabilities ID define and use the
newly introduced one from the PCI Code and ID Assignment
Specification Revision 1.11 document header.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-09-02 19:37:56 -04:00
Neil Armstrong 99c2279abf pci: add Extended PCI(e) capability offset get
Extend the PCIe API to find Extended Capabilities in the PCI Express
Extended Capabilities located in Configuration Space at offsets 256
or greater.

Note: the Root Complex Register Block is not supported

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-09-02 19:37:56 -04:00
Daniel Leung ec2b9d42af pcie: msi: pci_msi_enable() to take IRQ as parameter
This changes pci_msi_enable() to take IRQ number as a function
parameter. The old behavior relies on putting the IRQ number
into the interrupt line register in the PCI config space
during IRQ allocation, and reading it back when enabling IRQ.
However, the interrupt line register is only required to be
read-/writable when legacy interrupt is supported on the device.
Otherwise it has undefined behavior. On ACRN, they don't even
care about this register and always wires it to 0x00.
So this commit changes the behavior in pci_msi_enable() to not
require reading back the interrupt line register and instead
takes the IRQ number via function parameter.

Fixes #36765

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-30 13:04:36 +03:00
Tomasz Bursztyka f70ecc1099 drivers/pcie: Improve and fix MBAR retrieval depending on use cases
So far pcie_get_mbar() has been the only way to retrieve a MBAR. But
it's logic does not fit all uses cases as we will see further.
The meaning of its parameter "index" is not about BAR index but about
a valid Base Address count instead. It's an arbitrary way to index
MBARs unrelated to the actual BAR index.

While this has proven to be just the function we needed so far, this has
not been the case for MSI-X, which one (through BIR info) needs to
access the BAR by their actual index. Same as ivshmem in fact, though
that one did not generate any bug since it never has IO BARs nor 64bits
BARs (so far?).

So:

- renaming existing pcie_get_mbar() to pcie_probe_mbar(), which is a
  more relevant name as it indeed probes the BARs to find the nth valid
  one.
- Introducing a new pcie_get_mbar() which this time really asks for the
  BAR index.
- Applying the change where relevant. So all use pcie_probe_mbar() now
  but MSI-X and ivshmem.

Fixes #37444

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-08-20 06:30:20 -04:00
Daniel Leung 941eb9696a drivers: pcie: build as static library
Instead of putting the object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Neil Armstrong 72bb75a360 pcie: msi: fix MSI-X fallback to MSI
When enabling MSI & MSI-X, the code seemed to handle fallback to MSI
when MSI-X is not available, but the logic uses MSI-X even if not
available and the MSI path never gets used.

Fixes: a2491b321e ("drivers/pcie: Add support for MSI-X")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-08-10 14:46:22 -04:00
Neil Armstrong f9c3ade883 pcie: msi: add missing mem_manage.h include for MSI-X
When building on non-X86 platforms K_MEM_PERM_RW gets undefined.

Fixes: a2491b321e ("drivers/pcie: Add support for MSI-X")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-08-10 14:46:22 -04:00
Andrei Emeltchenko f818d8770b pcie: msi: Map only actual table
Map only actual table of size n_vector * PCIE_MSIR_TABLE_ENTRY_SIZE.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2021-07-08 14:36:32 -04:00
Gerard Marull-Paretas 6e7539502b drivers: pcie: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:25:24 -04:00
Kumar Gala 48d01cfcb3 drivers: pcie: endpoint: Convert dma to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the dma controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-17 11:28:31 +01:00
Raveendra Padasalagi b71bdad7bb drivers: pcie: endpoint: Use DEVICE_DT_INST_GET() API
Replace current use of DEVICE_GET() with DEVICE_DT_INST_GET().

Signed-off-by: Raveendra Padasalagi <raveendra.padasalagi@broadcom.com>
2021-03-02 10:03:34 -06:00
Johan Hedberg d01fa56f6a drivers: pcie: Introduce API to look up devices by ID
In some cases we cannot know the BDF up-front, so provide a way to
look it up based on the vendor and device ID.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-02-15 08:23:05 -05:00
Johan Hedberg 14da6014a3 drivers: pcie: Move MAX_BUS/DEV/FUNC defines to pcie.h header file
These have been redefined in various places - better to have them in a
single place that different users can use.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-02-15 08:23:05 -05:00
Kumar Gala 02703e60d9 device: Remove DEVICE_DT_DECLARE / DEVICE_DT_INST_DECLARE
Now that we generate a header that extern's all possible devicetree
based device struct we can remove DEVICE_DT_DECLARE and
DEVICE_DT_INST_DECLARE as they aren't needed anymore.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-01-15 07:16:21 -06:00
Kumar Gala d1cc8357d8 drivers: pcie: Convert drivers to new DT device macros
Convert pcie drivers from:

    DEVICE_AND_API_INIT -> DEVICE_DT_INST_DEFINE

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-16 13:51:53 -05:00
Andrew Boie d2ad783a97 mmu: rename z_mem_map to z_phys_map
Renamed to make its semantics clearer; this function maps
*physical* memory addresses and is not equivalent to
posix mmap(), which might confuse people.

mem_map test case remains the same name as other memory
mapping scenarios will be added in the fullness of time.

Parameter names to z_phys_map adjusted slightly to be more
consistent with names used in other memory mapping functions.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-12-16 08:55:55 -05:00