Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109080075
D32783.id99441.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D32783.id99441.diff
View Options
Index: sys/kern/subr_bus.c
===================================================================
--- sys/kern/subr_bus.c
+++ sys/kern/subr_bus.c
@@ -6066,6 +6066,106 @@
UID_ROOT, GID_WHEEL, 0644, "devctl2");
}
+/*
+ * For maintaining device 'at' location info to avoid recomputing it
+ */
+struct device_location_node {
+ const char *dln_locator;
+ const char *dln_path;
+ TAILQ_ENTRY(device_location_node) dln_link;
+};
+typedef TAILQ_HEAD(device_location_list, device_location_node) device_location_list_t;
+
+struct device_location_cache {
+ device_location_list_t dlc_list;
+};
+
+
+/*
+ * Location cache for wired devices.
+ */
+device_location_cache_t *
+dev_wired_cache_init(void)
+{
+ device_location_cache_t *dcp;
+
+ dcp = malloc(sizeof(*dcp), M_BUS, M_WAITOK | M_ZERO);
+ TAILQ_INIT(&dcp->dlc_list);
+
+ return (dcp);
+}
+
+void
+dev_wired_cache_fini(device_location_cache_t *dcp)
+{
+ struct device_location_node *dln, *tdln;
+
+ TAILQ_FOREACH_SAFE(dln, &dcp->dlc_list, dln_link, tdln) {
+ /* Note: one allocation for both node and locator, but not path */
+ free(__DECONST(void *, dln->dln_path), M_BUS);
+ free(dln, M_BUS);
+ }
+ free(dcp, M_BUS);
+}
+
+static struct device_location_node *
+dev_wired_cache_lookup(device_location_cache_t *dcp, const char *locator)
+{
+ struct device_location_node *dln;
+
+ TAILQ_FOREACH(dln, &dcp->dlc_list, dln_link) {
+ if (strcmp(locator, dln->dln_locator) == 0)
+ return (dln);
+ }
+
+ return (NULL);
+}
+
+static struct device_location_node *
+dev_wired_cache_add(device_location_cache_t *dcp, const char *locator, const char *path)
+{
+ struct device_location_node *dln;
+ char *l;
+
+ dln = malloc(sizeof(*dln) + strlen(locator) + 1, M_BUS, M_WAITOK | M_ZERO);
+ dln->dln_locator = l = (char *)(dln + 1);
+ memcpy(l, locator, strlen(locator) + 1);
+ dln->dln_path = path;
+ TAILQ_INSERT_HEAD(&dcp->dlc_list, dln, dln_link);
+
+ return (dln);
+}
+
+bool
+dev_wired_cache_match(device_location_cache_t *dcp, device_t dev, const char *at)
+{
+ const char *cp, *path;
+ char locator[32];
+ int len;
+ struct device_location_node *res;
+
+ cp = strchr(at, ':');
+ if (cp == NULL)
+ return (false);
+ len = cp - at;
+ if (len > sizeof(locator) - 1) /* Skip too long locator */
+ return (false);
+ memcpy(locator, at, len);
+ locator[len] = '\0';
+ cp++;
+
+ /* maybe cache this inside device_t and look that up, but not yet */
+ res = dev_wired_cache_lookup(dcp, locator);
+ if (res == NULL) {
+ path = device_get_path(dev, locator);
+ res = dev_wired_cache_add(dcp, locator, path);
+ }
+ if (res == NULL || res->dln_path == NULL)
+ return (false);
+
+ return (strcmp(res->dln_path, cp) == 0);
+}
+
/*
* APIs to manage deprecation and obsolescence.
*/
Index: sys/sys/bus.h
===================================================================
--- sys/sys/bus.h
+++ sys/sys/bus.h
@@ -833,6 +833,13 @@
device_get_nameunit(device_get_parent(dev)), e)); \
}
+struct device_location_cache;
+typedef struct device_location_cache device_location_cache_t;
+device_location_cache_t *dev_wired_cache_init(void);
+void dev_wired_cache_fini(device_location_cache_t *dcp);
+bool dev_wired_cache_match(device_location_cache_t *dcp, device_t dev, const char *at);
+
+
/**
* Shorthand macros, taking resource argument
* Generated with sys/tools/bus_macro.sh
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 1, 1:07 PM (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16383562
Default Alt Text
D32783.id99441.diff (3 KB)
Attached To
Mode
D32783: bus: Create dev_wired_cache
Attached
Detach File
Event Timeline
Log In to Comment