1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2019 Ramon Fried <ramon.fried@gmail.com>
14 * struct sandbox_pci_ep_priv - private data for driver
15 * @hdr: Stores the EP device header
16 * @msix: required MSIx count;
17 * @msi: required MSI count;
19 struct sandbox_pci_ep_priv {
20 struct pci_ep_header hdr;
21 struct pci_bar bars[6];
27 /* Method exported for testing purposes */
28 int sandbox_get_pci_ep_irq_count(struct udevice *dev)
30 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
32 return priv->irq_count;
35 static const struct udevice_id sandbox_pci_ep_ids[] = {
36 { .compatible = "sandbox,pci_ep" },
40 static int sandbox_write_header(struct udevice *dev, uint fn,
41 struct pci_ep_header *hdr)
43 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
48 memcpy(&priv->hdr, hdr, sizeof(*hdr));
53 static int sandbox_read_header(struct udevice *dev, uint fn,
54 struct pci_ep_header *hdr)
56 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
61 memcpy(hdr, &priv->hdr, sizeof(*hdr));
66 static int sandbox_set_bar(struct udevice *dev, uint fn,
67 struct pci_bar *ep_bar)
69 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
75 bar_idx = ep_bar->barno;
77 memcpy(&priv->bars[bar_idx], ep_bar, sizeof(*ep_bar));
82 static int sandbox_read_bar(struct udevice *dev, uint fn,
83 struct pci_bar *ep_bar, enum pci_barno barno)
85 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
91 bar_idx = ep_bar->barno;
93 memcpy(ep_bar, &priv->bars[bar_idx], sizeof(*ep_bar));
98 static int sandbox_set_msi(struct udevice *dev, uint fn, uint interrupts)
100 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
105 priv->msi = interrupts;
110 static int sandbox_get_msi(struct udevice *dev, uint fn)
112 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
120 static int sandbox_set_msix(struct udevice *dev, uint fn, uint interrupts)
122 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
127 priv->msix = interrupts;
132 static int sandbox_get_msix(struct udevice *dev, uint fn)
134 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
142 static int sandbox_raise_irq(struct udevice *dev, uint fn,
143 enum pci_ep_irq_type type, uint interrupt_num)
145 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
155 static int sandbox_pci_ep_probe(struct udevice *dev)
157 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
159 memset(priv, 0, sizeof(*priv));
163 static struct pci_ep_ops sandbox_pci_ep_ops = {
164 .write_header = sandbox_write_header,
165 .read_header = sandbox_read_header,
166 .set_bar = sandbox_set_bar,
167 .read_bar = sandbox_read_bar,
168 .set_msi = sandbox_set_msi,
169 .get_msi = sandbox_get_msi,
170 .set_msix = sandbox_set_msix,
171 .get_msix = sandbox_get_msix,
172 .raise_irq = sandbox_raise_irq,
175 U_BOOT_DRIVER(pci_ep_sandbox) = {
176 .name = "pci_ep_sandbox",
178 .of_match = sandbox_pci_ep_ids,
179 .probe = sandbox_pci_ep_probe,
180 .ops = &sandbox_pci_ep_ops,
181 .priv_auto_alloc_size = sizeof(struct sandbox_pci_ep_priv),