hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pci/endpoint/pci-epf-core.c
....@@ -1,5 +1,5 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/**
2
+/*
33 * PCI Endpoint *Function* (EPF) library
44 *
55 * Copyright (C) 2017 Texas Instruments
....@@ -21,26 +21,6 @@
2121 static const struct device_type pci_epf_type;
2222
2323 /**
24
- * pci_epf_linkup() - Notify the function driver that EPC device has
25
- * established a connection with the Root Complex.
26
- * @epf: the EPF device bound to the EPC device which has established
27
- * the connection with the host
28
- *
29
- * Invoke to notify the function driver that EPC device has established
30
- * a connection with the Root Complex.
31
- */
32
-void pci_epf_linkup(struct pci_epf *epf)
33
-{
34
- if (!epf->driver) {
35
- dev_WARN(&epf->dev, "epf device not bound to driver\n");
36
- return;
37
- }
38
-
39
- epf->driver->ops->linkup(epf);
40
-}
41
-EXPORT_SYMBOL_GPL(pci_epf_linkup);
42
-
43
-/**
4424 * pci_epf_unbind() - Notify the function driver that the binding between the
4525 * EPF device and EPC device has been lost
4626 * @epf: the EPF device which has lost the binding with the EPC device
....@@ -55,7 +35,9 @@
5535 return;
5636 }
5737
38
+ mutex_lock(&epf->lock);
5839 epf->driver->ops->unbind(epf);
40
+ mutex_unlock(&epf->lock);
5941 module_put(epf->driver->owner);
6042 }
6143 EXPORT_SYMBOL_GPL(pci_epf_unbind);
....@@ -69,6 +51,8 @@
6951 */
7052 int pci_epf_bind(struct pci_epf *epf)
7153 {
54
+ int ret;
55
+
7256 if (!epf->driver) {
7357 dev_WARN(&epf->dev, "epf device not bound to driver\n");
7458 return -EINVAL;
....@@ -77,12 +61,17 @@
7761 if (!try_module_get(epf->driver->owner))
7862 return -EAGAIN;
7963
80
- return epf->driver->ops->bind(epf);
64
+ mutex_lock(&epf->lock);
65
+ ret = epf->driver->ops->bind(epf);
66
+ mutex_unlock(&epf->lock);
67
+
68
+ return ret;
8169 }
8270 EXPORT_SYMBOL_GPL(pci_epf_bind);
8371
8472 /**
8573 * pci_epf_free_space() - free the allocated PCI EPF register space
74
+ * @epf: the EPF device from whom to free the memory
8675 * @addr: the virtual address of the PCI EPF register space
8776 * @bar: the BAR number corresponding to the register space
8877 *
....@@ -99,6 +88,7 @@
9988 epf->bar[bar].phys_addr);
10089
10190 epf->bar[bar].phys_addr = 0;
91
+ epf->bar[bar].addr = NULL;
10292 epf->bar[bar].size = 0;
10393 epf->bar[bar].barno = 0;
10494 epf->bar[bar].flags = 0;
....@@ -107,12 +97,15 @@
10797
10898 /**
10999 * pci_epf_alloc_space() - allocate memory for the PCI EPF register space
100
+ * @epf: the EPF device to whom allocate the memory
110101 * @size: the size of the memory that has to be allocated
111102 * @bar: the BAR number corresponding to the allocated register space
103
+ * @align: alignment size for the allocation region
112104 *
113105 * Invoke to allocate memory for the PCI EPF register space.
114106 */
115
-void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar)
107
+void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
108
+ size_t align)
116109 {
117110 void *space;
118111 struct device *dev = epf->epc->dev.parent;
....@@ -120,7 +113,11 @@
120113
121114 if (size < 128)
122115 size = 128;
123
- size = roundup_pow_of_two(size);
116
+
117
+ if (align)
118
+ size = ALIGN(size, align);
119
+ else
120
+ size = roundup_pow_of_two(size);
124121
125122 space = dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL);
126123 if (!space) {
....@@ -129,9 +126,12 @@
129126 }
130127
131128 epf->bar[bar].phys_addr = phys_addr;
129
+ epf->bar[bar].addr = space;
132130 epf->bar[bar].size = size;
133131 epf->bar[bar].barno = bar;
134
- epf->bar[bar].flags = PCI_BASE_ADDRESS_SPACE_MEMORY;
132
+ epf->bar[bar].flags |= upper_32_bits(size) ?
133
+ PCI_BASE_ADDRESS_MEM_TYPE_64 :
134
+ PCI_BASE_ADDRESS_MEM_TYPE_32;
135135
136136 return space;
137137 }
....@@ -206,7 +206,7 @@
206206 if (!driver->ops)
207207 return -EINVAL;
208208
209
- if (!driver->ops->bind || !driver->ops->unbind || !driver->ops->linkup)
209
+ if (!driver->ops->bind || !driver->ops->unbind)
210210 return -EINVAL;
211211
212212 driver->driver.bus = &pci_epf_bus_type;
....@@ -264,6 +264,7 @@
264264 device_initialize(dev);
265265 dev->bus = &pci_epf_bus_type;
266266 dev->type = &pci_epf_type;
267
+ mutex_init(&epf->lock);
267268
268269 ret = dev_set_name(dev, "%s", name);
269270 if (ret) {