Commit Graph

130 Commits

Author SHA1 Message Date
Daniel Leung 552e29790d kernel: mm: rename z_phys_un/map to k_mem_*_phys_bare
This renames z_phys_map() and z_phys_unmap() to
k_mem_map_phys_bare() and k_mem_unmap_phys_bare()
respectively. This is part of the series to move memory
management functions away from the z_ namespace.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-06-12 21:13:26 -04:00
Flavio Ceolin 8cd1ab8896 drivers: pcie: Remove deprecated pcie_bdf_lookup
pcie_bdf_lookup() was deprecated before 3.3 release. Time to remove
it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-05-17 09:30:04 +02:00
Flavio Ceolin f4aefc281b drivers: pcie: Remove deprecated pcie_probe
pcie_probe() was deprecated before 3.3 release. Time to remove it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-05-17 09:30:04 +02:00
Hess Nathan 958a4505bd coding guidelines: comply with MISRA Rule 12.1.
-added parentheses verifying lack of ambiguities

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-05-13 16:05:53 -04:00
Najumon B.A 34a2fbfba1 drivers: pci: update prt retrieve based on pnp id
update prt retrieve based on acpi pnp id instead of acpi device
path/name

Signed-off-by: Najumon B.A <najumon.ba@intel.com>
2024-01-31 15:03:06 +01:00
Andrei Emeltchenko fc8b53bf10 drivers: pcie: Read register before actual usage
Move reading PCIE_CONF_CMDSTAT before actual usage. There are four
return branches before value is used.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-12-28 12:07:30 +00:00
Andrei Emeltchenko 4a17446636 drivers: pcie: Remove magic number
Use definitions instead of magic numbers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-12-28 12:07:30 +00:00
Najumon B.A c146833fc8 drivers: pcie: fix for mmio size region calculation
I/O or memory decoding should be disabled via the command register
before sizing BAR for calculation MMIO size

Signed-off-by: Najumon B.A <najumon.ba@intel.com>
2023-12-22 09:52:40 +01:00
Henrik Brix Andersen c0c8952739 shell: do not enable subsystem/driver shell modules by default
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.

The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.

This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-11-20 09:21:40 +01:00
Daniel Leung c972ef1a0f kernel: mm: move kernel mm functions under kernel includes
This moves the k_* memory management functions from sys/ into
kernel/ includes, as there are kernel public APIs. The z_*
functions are further separated into the kernel internal
header directory.

Also made a quick change to doxygen to group sys_mem_* into
the OS Memory Management group so they will appear in doc.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-20 09:19:14 +01:00
Najumon B.A e89b005368 drivers: pcie: add config for enable PRT
add config support for enable IRQ information retrieve via
ACPI PRT (PCI Routing Table)

Signed-off-by: Najumon B.A <najumon.ba@intel.com>
2023-10-06 10:40:14 +02:00
Gerard Marull-Paretas 1b361f9832 drivers: pcie: host: add missing init.h
File was using SYS_INIT from init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-29 12:20:31 +01:00
Daniel Leung 80f079a2cd pcie: host: guard include of ACPICA header file
This puts a ifdef guard around the inclusion of ACPICA header
file. The ACPICA module is not active unless CONFIG_ACPI is
also enabled so we should not be using that header without
CONFIG_ACPI also being enabled.

This was discovered by Coverity.

Fixes #60484

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-07-24 09:07:45 +00:00
Fabio Baltieri 5ea3f9a24e drivers: pcie: initialize after interrupt controllers
PCIe devices refer to interrupt nodes, but are initialized with the same
priority, making the sequence depending on the linking order. Add a new
symbol and set it to one unit after intc to ensure that the
initialization sequence is stable.

Found with:

west build -p -b qemu_cortex_a53 \
	samples/drivers/virtualization/ivshmem/doorbell \
	-DCONFIG_CHECK_INIT_PRIORITIES=y
...
ERROR: /soc/pcie@4010000000 PRE_KERNEL_1 40 <
	/soc/interrupt-controller@8000000/its@8080000 POST_KERNEL 40

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-07-12 09:25:35 +02:00
Najumon Ba a72271f27f drivers: pcie: add prt support for pci legacy interrupt
add support for obtain irq number from pci irq routing table

Signed-off-by: Najumon Ba <najumon.ba@intel.com>
2023-06-30 17:53:01 +03:00
Tomasz Bursztyka 257deba9c2 drivers/pcie: Fix copyright year
Trivial update that was missed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2023-06-21 13:57:01 -04:00
Tomasz Bursztyka 0c9e762cee drivers/pcie: Add VC/TC mapping and VC enablement
Note that only the the hardware round robin port arbitration capability
is being used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2023-06-20 14:01:43 -04:00
Tomasz Bursztyka 6a1e19cf86 drivers/pcie: Add virtual channel details output to shell module
Helps to see how many VCs are supported and the related ressources.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2023-06-20 14:01:43 -04:00
Tomasz Bursztyka 5e4e6bc486 drivers/pcie: Add Virtual Channel configuration support
Basic support of VC capability, where a driver can enable VC and map its
traffic classes.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2023-06-20 14:01:43 -04:00
Tomasz Bursztyka d39645a206 drivers/pcie: Add capabilities output to shell module
This help to decipher PCIe capabilities supported by each listed device.
Shown only on a selected device and not on the general list.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2023-06-17 07:58:41 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Grant Ramsay 244f4f2034 drivers: pcie: Enable filtering PCIe devices by class-rev
This allows finding the correct PCIe device when multiple devices
have the same vendor-id/device-id but differ in the class-rev register

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-05-14 18:17:33 -04:00
Christopher Friedt 9ad78eb60c drivers: pcie_ep: iproc: compile-out unused function based on DT
Compile-out `iproc_pcie_pl330_dma_xfer()` if there are no active
DMA users in devicetree.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-02 09:10:33 -04:00
Chris Friedt 7212792295 drivers: pcie_ep: iproc: ensure config and api are const
The `config` and `api` members of `struct device` are expected
to be `const`. This also improves reliability, as `config`
and `api` are stored in rom rather than ram, which has the
potential to be corrupted at runtime in the absense of an MMU.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-04-26 17:54:59 -04:00
Tarun Karuturi 9d95f69a87 drivers: pcie_ep: iproc: enable based on device tree specs
There are use cases for the pcie_ep driver where we don't
necessarily need the dma functionality. Added ifdef's around
the dma functionality so that it's only available if we
specify the dma engines in the device tree similar to

```
dmas = <&pl330 0>, <&pl330 1>;
dma-names = "txdma", "rxdma";
```

Signed-off-by: Tarun Karuturi <tkaruturi@meta.com>
Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-04-26 17:54:59 -04:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Rodrigo Cataldo bcb3961567 drivers: pcie: late initialization of pcie when PCIe controller is used
For architectures that rely on a PCIe controller (for example, ARM64),
scanning the PCI space will only succeed after the controller has
initialized. Therefore, in the presence of PCIe controller, the PCIe
initialization is bumped to the next system init level.

In the past, drivers like ivshmem would do a late scan of the PCI space
in case the early scan failed; however, the cited commit removed this
feature and ivshmem fails for ARM64. This commit fix this by making the
early scan succeed.

Fixes: a96016d747 ("drivers: ivshmem: Remove unnecessary BDF lookup ...")
Signed-off-by: Rodrigo Cataldo <rodrigo.cataldo@huawei.com>
Co-authored-by: Henri Xavier <datacomos@huawei.com>
2022-12-10 09:47:26 +01:00
Johan Hedberg 7feb7ef914 pcie: shell: Use pcie_scan() for scanning for devices
Use the new pcie_scan() API instead of doing a brute-force scan.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-24 15:23:28 +01:00
Johan Hedberg e4b8e97c1a pcie: Convert pcie_bdf_lookup() to use pcie_scan()
Use the commmon scanning framework instead of doing a custom brute-force
scan.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-24 15:23:28 +01:00
Johan Hedberg b7343b28ac pcie: Convert PCIe device scanning to use pcie_scan() API
Take advantage of the new PCIe scanning API for doing the initial lookup
of PCIe devices specified for a given board.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-24 15:23:28 +01:00
Johan Hedberg 57c150af0c pcie: Add API for scanning for available endpoints
This adds a generic API to be used for scanning for available PCI
endpoints. It takes a more detailed approach than the "brute force"
based scanning that's so far been used in Zephyr, buy inspecting the
host controller node and bridge nodes, and only scanning for busses and
devices that are actually expected to exist.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-24 15:23:28 +01:00
Johan Hedberg a2c8fdca33 pcie: Add helper macro to identify valid identifiers
PCI(e) host controllers behave in different ways (some more buggy than
others) in what value they use to indicate that an endpoint is not
present. In most cases the VID/DID is all ones (PCIE_ID_NONE) but in
others it's all zeroes, and some may even have the VID all zeroes and
the DID all ones, or vice-versa.

Add a macro to easily test for all these possibilities. The "all ones"
and "all zeroes" cases have been verified to exist on actual HW
supported by Zephyr, however the test for the mixed cases is simply
based on what Linux considers valid values (drivers/pci/probe.c in the
Linux kernel tree).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-24 15:23:28 +01:00
Johan Hedberg cb1e4509fe drivers: pci: ptm: Convert to use dynamic BDF lookup
Use the new PCIe core infrastructure for looking up the BDF at runtime
based on the VID/DID values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Johan Hedberg ed726fcce9 drivers: pci: ptm: Fix missing DT_DRV_COMPAT
The ptm.c driver never defined DT_DRV_COMPAT, so the various DT macros
never expanded to anything useful.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Johan Hedberg 0eed096f99 pcie: Add support for centralized lookup of BDF values
The BDF values can differ on the same platform, based on e.g. BIOS
configuration, and in the case of qemu the command line parameters. It's
therefore more reliable to always look up the BDF value based on the
known Vendor and Device IDs.

This patch introduces such a framework, and allows the incremental
update of PCIe drivers to start taking advantage of it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Henri Xavier 0f2d763099 pcie: Write MSI-X vectors using `sys_write32`
It was previously written as regular members of a struct, which
allows the C compiler to do things the way it wants. On ARM64, gcc
would typically write field by pairs (`STP`), which
would generate aborts.

By using `sys_write32`, we force it the right way.

Signed-off-by: Henri Xavier <datacomos@huawei.com>
2022-11-15 12:20:21 +00:00
Henrik Brix Andersen 3c99a1e015 drivers: pcie: reintroduce support for I/O BARs
Reintroduce support for accessing I/O BARs which was removed in
43d84147d9.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
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