summaryrefslogtreecommitdiff
path: root/documentation/6.components/device-driver/pci/endpoint.md
blob: 0c6d81363b13b94dcda980b1b1b397eb9d70254f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@page page_device_pci_endpoint PCI endpoint (EP) mode

# PCI endpoint framework (`endpoint/`)

Header: **`drivers/pci_endpoint.h`**. Core: **`endpoint/endpoint.c`**, **`endpoint/mem.c`**.

SoC as **PCIe device** under a remote host — not root complex. Kconfig: **`RT_PCI_ENDPOINT`**.

---

## Core objects

| Type | Role |
| --- | --- |
| **`struct rt_pci_ep`** | Controller: **`max_functions`**, **`ops`**, **`epf`** list |
| **`struct rt_pci_epf`** | Function image (driver) |
| **`struct rt_pci_ep_header`** | Emulated config header |
| **`struct rt_pci_ep_bar`** | BAR size/flags for programming |

**`rt_pci_ep_register` / `unregister`** — global controller list under lock.

---

## Controller ops

| API | `ops` | Purpose |
| --- | --- | --- |
| **`rt_pci_ep_write_header`** | **`write_header`** | Config header for **`func_no`** |
| **`rt_pci_ep_set_bar` / `clear_bar`** | **`set_bar`** | BAR programming |
| **`rt_pci_ep_map_addr` / `unmap_addr`** | **`map_addr`** | CPU ↔ PCI map |
| **`rt_pci_ep_set_msi` / `get_msi`** | MSI doorbell |
| **`rt_pci_ep_set_msix` / `get_msix`** | MSI-X table |
| **`rt_pci_ep_raise_irq`** | **`raise_irq`** | INTx/MSI/MSI-X to host |
| **`rt_pci_ep_start` / `stop`** | Link visibility |

**`func_no < max_functions`** required; missing **`ops`** → **`-RT_ENOSYS`**.

---

## BAR validation

**`rt_pci_ep_set_bar`** rejects invalid 64-bit pairs, >4 GiB on 32-bit BAR, bad I/O flags before calling hardware.

---

## Memory helpers (`mem.c`)

**`rt_pci_ep_mem_init`**, **`rt_pci_ep_mem_array_init`** — outbound/inbound windows for host mapping.

**`host/dw/pcie-dw_ep.c`** — typical **`rt_pci_ep_ops`** implementation.

---

## Host vs endpoint

| Mode | APIs | Doc |
| --- | --- | --- |
| Root complex | **`rt_pci_host_bridge_*`**, **`rt_pci_scan_*`** | @ref page_device_pci_host |
| Endpoint | **`rt_pci_ep_*`** | this page |

Do not call host enumeration on EP controllers.

---

## Pitfalls

| Issue | Mitigation |
| --- | --- |
| **`func_no` out of range** | **`-RT_EINVAL`** |
| IRQ before link **`start`** | Host may ignore |
| 64-bit BAR layout | Follow PCI pair rules |

## See also

- @ref page_device_pci
- @ref page_device_pci_host
- `components/drivers/pci/host/dw/pcie-dw_ep.c`