Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153741527
D32855.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D32855.diff
View Options
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -690,14 +690,17 @@
struct resource_list_entry *rle;
rman_res_t newstart;
device_t dev;
+ int error;
if ((rle = linux_pci_get_bar(pdev, bar, true)) == NULL)
return (0);
dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
- if (BUS_TRANSLATE_RESOURCE(dev, rle->type, rle->start, &newstart)) {
- device_printf(pdev->dev.bsddev, "translate of %#jx failed\n",
- (uintmax_t)rle->start);
+ error = bus_translate_resource(dev, rle->type, rle->start, &newstart);
+ if (error != 0) {
+ device_printf(pdev->dev.bsddev,
+ "translate of %#jx failed: %d\n",
+ (uintmax_t)rle->start, error);
return (0);
}
return (newstart);
diff --git a/sys/dev/ofw/ofw_pcib.c b/sys/dev/ofw/ofw_pcib.c
--- a/sys/dev/ofw/ofw_pcib.c
+++ b/sys/dev/ofw/ofw_pcib.c
@@ -511,11 +511,11 @@
if (type == space) {
start += (rp->host - rp->pci);
- break;
+ *newstart = start;
+ return (0);
}
}
- *newstart = start;
- return (0);
+ return (ENOENT);
}
static int
diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c
--- a/sys/dev/pci/pci_host_generic.c
+++ b/sys/dev/pci/pci_host_generic.c
@@ -331,7 +331,7 @@
return (bus_generic_release_resource(dev, child, type, rid, res));
}
-static bool
+static int
generic_pcie_translate_resource_common(device_t dev, int type, rman_res_t start,
rman_res_t end, rman_res_t *new_start, rman_res_t *new_end)
{
@@ -385,7 +385,7 @@
break;
}
- return (found);
+ return (found ? 0 : ENOENT);
}
static int
@@ -394,7 +394,7 @@
{
rman_res_t newend; /* unused */
- return (!generic_pcie_translate_resource_common(
+ return (generic_pcie_translate_resource_common(
bus, type, start, 0, newstart, &newend));
}
@@ -422,8 +422,8 @@
type, rid, start, end, count, flags));
/* Translate the address from a PCI address to a physical address */
- if (!generic_pcie_translate_resource_common(dev, type, start, end, &phys_start,
- &phys_end)) {
+ if (generic_pcie_translate_resource_common(dev, type, start, end,
+ &phys_start, &phys_end) != 0) {
device_printf(dev,
"Failed to translate resource %jx-%jx type %x for %s\n",
(uintmax_t)start, (uintmax_t)end, type,
@@ -474,9 +474,12 @@
start = rman_get_start(r);
end = rman_get_end(r);
- if (!generic_pcie_translate_resource_common(dev, type, start, end, &start,
- &end))
- return (EINVAL);
+ res = generic_pcie_translate_resource_common(dev, type, start, end,
+ &start, &end);
+ if (res != 0) {
+ rman_deactivate_resource(r);
+ return (res);
+ }
rman_set_start(r, start);
rman_set_end(r, end);
diff --git a/sys/dev/pci/pci_user.c b/sys/dev/pci/pci_user.c
--- a/sys/dev/pci/pci_user.c
+++ b/sys/dev/pci/pci_user.c
@@ -877,7 +877,7 @@
return (EBUSY); /* XXXKIB enable if _ACTIVATE */
if (!PCI_BAR_MEM(pm->pm_value))
return (EIO);
- error = BUS_TRANSLATE_RESOURCE(pcidev, SYS_RES_MEMORY,
+ error = bus_translate_resource(pcidev, SYS_RES_MEMORY,
pm->pm_value & PCIM_BAR_MEM_BASE, &membase);
if (error != 0)
return (error);
diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m
--- a/sys/kern/bus_if.m
+++ b/sys/kern/bus_if.m
@@ -77,18 +77,6 @@
return (0);
}
- static int
- null_translate_resource(device_t bus, int type, rman_res_t start,
- rman_res_t *newstart)
- {
- if (device_get_parent(bus) != NULL)
- return (BUS_TRANSLATE_RESOURCE(device_get_parent(bus),
- type, start, newstart));
-
- *newstart = start;
- return (0);
- }
-
static ssize_t
null_get_property(device_t dev, device_t child, const char *propname,
void *propvalue, size_t size)
@@ -425,10 +413,12 @@
rman_res_t _end;
};
-
/**
* @brief translate a resource value
*
+ * Give a bus driver the opportunity to translate resource ranges. If
+ * successful, the host's view of the resource starting at @p _start is
+ * returned in @p _newstart, otherwise an error is returned.
*
* @param _dev the device associated with the resource
* @param _type the type of resource
@@ -440,7 +430,7 @@
int _type;
rman_res_t _start;
rman_res_t *_newstart;
-} DEFAULT null_translate_resource;
+} DEFAULT bus_generic_translate_resource;
/**
* @brief Release a resource
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -4242,6 +4242,24 @@
return (EINVAL);
}
+/*
+ * @brief Helper function for implementing BUS_TRANSLATE_RESOURCE().
+ *
+ * This simple implementation of BUS_TRANSLATE_RESOURCE() simply calls the
+ * BUS_TRANSLATE_RESOURCE() method of the parent of @p dev. If there is no
+ * parent, no translation happens.
+ */
+int
+bus_generic_translate_resource(device_t dev, int type, rman_res_t start,
+ rman_res_t *newstart)
+{
+ if (dev->parent)
+ return (BUS_TRANSLATE_RESOURCE(dev->parent, type, start,
+ newstart));
+ *newstart = start;
+ return (0);
+}
+
/**
* @brief Helper function for implementing BUS_ALLOC_RESOURCE().
*
@@ -4672,6 +4690,21 @@
return (BUS_ADJUST_RESOURCE(dev->parent, dev, type, r, start, end));
}
+/**
+ * @brief Wrapper function for BUS_TRANSLATE_RESOURCE().
+ *
+ * This function simply calls the BUS_TRANSLATE_RESOURCE() method of the
+ * parent of @p dev.
+ */
+int
+bus_translate_resource(device_t dev, int type, rman_res_t start,
+ rman_res_t *newstart)
+{
+ if (dev->parent == NULL)
+ return (EINVAL);
+ return (BUS_TRANSLATE_RESOURCE(dev->parent, type, start, newstart));
+}
+
/**
* @brief Wrapper function for BUS_ACTIVATE_RESOURCE().
*
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -515,6 +515,8 @@
int bus_adjust_resource(device_t child, int type, struct resource *r,
rman_res_t start, rman_res_t end);
+int bus_translate_resource(device_t child, int type, rman_res_t start,
+ rman_res_t *newstart);
struct resource *bus_alloc_resource(device_t dev, int type, int *rid,
rman_res_t start, rman_res_t end,
rman_res_t count, u_int flags);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 24, 8:52 AM (14 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32069701
Default Alt Text
D32855.diff (6 KB)
Attached To
Mode
D32855: bus: Make BUS_TRANSLATE_RESOURCE behave more like other bus methods
Attached
Detach File
Event Timeline
Log In to Comment