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);
90 memcpy(ep_bar, &priv->bars[barno], sizeof(*ep_bar));
95 static int sandbox_set_msi(struct udevice *dev, uint fn, uint interrupts)
97 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
102 priv->msi = interrupts;
107 static int sandbox_get_msi(struct udevice *dev, uint fn)
109 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
117 static int sandbox_set_msix(struct udevice *dev, uint fn, uint interrupts)
119 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
124 priv->msix = interrupts;
129 static int sandbox_get_msix(struct udevice *dev, uint fn)
131 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
139 static int sandbox_raise_irq(struct udevice *dev, uint fn,
140 enum pci_ep_irq_type type, uint interrupt_num)
142 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
152 static int sandbox_pci_ep_probe(struct udevice *dev)
154 struct sandbox_pci_ep_priv *priv = dev_get_priv(dev);
156 memset(priv, 0, sizeof(*priv));
160 static struct pci_ep_ops sandbox_pci_ep_ops = {
161 .write_header = sandbox_write_header,
162 .read_header = sandbox_read_header,
163 .set_bar = sandbox_set_bar,
164 .read_bar = sandbox_read_bar,
165 .set_msi = sandbox_set_msi,
166 .get_msi = sandbox_get_msi,
167 .set_msix = sandbox_set_msix,
168 .get_msix = sandbox_get_msix,
169 .raise_irq = sandbox_raise_irq,
172 U_BOOT_DRIVER(pci_ep_sandbox) = {
173 .name = "pci_ep_sandbox",
175 .of_match = sandbox_pci_ep_ids,
176 .probe = sandbox_pci_ep_probe,
177 .ops = &sandbox_pci_ep_ops,
178 .priv_auto_alloc_size = sizeof(struct sandbox_pci_ep_priv),