diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/Kconfig | 11 | ||||
-rw-r--r-- | drivers/base/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/bus.c | 6 | ||||
-rw-r--r-- | drivers/base/class.c | 4 | ||||
-rw-r--r-- | drivers/base/core.c | 8 | ||||
-rw-r--r-- | drivers/base/dd.c | 9 | ||||
-rw-r--r-- | drivers/base/devtmpfs.c | 3 | ||||
-rw-r--r-- | drivers/base/dma-buf.c | 75 | ||||
-rw-r--r-- | drivers/base/firmware_class.c | 552 | ||||
-rw-r--r-- | drivers/base/memory.c | 10 | ||||
-rw-r--r-- | drivers/base/pinctrl.c | 69 | ||||
-rw-r--r-- | drivers/base/power/domain.c | 3 | ||||
-rw-r--r-- | drivers/base/power/opp.c | 19 | ||||
-rw-r--r-- | drivers/base/power/qos.c | 1 | ||||
-rw-r--r-- | drivers/base/power/runtime.c | 89 | ||||
-rw-r--r-- | drivers/base/power/wakeup.c | 6 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 2 |
17 files changed, 574 insertions, 294 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index c8b453939da2..07abd9d76f7f 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig | |||
@@ -145,6 +145,17 @@ config EXTRA_FIRMWARE_DIR | |||
145 | this option you can point it elsewhere, such as /lib/firmware/ or | 145 | this option you can point it elsewhere, such as /lib/firmware/ or |
146 | some other directory containing the firmware files. | 146 | some other directory containing the firmware files. |
147 | 147 | ||
148 | config FW_LOADER_USER_HELPER | ||
149 | bool "Fallback user-helper invocation for firmware loading" | ||
150 | depends on FW_LOADER | ||
151 | default y | ||
152 | help | ||
153 | This option enables / disables the invocation of user-helper | ||
154 | (e.g. udev) for loading firmware files as a fallback after the | ||
155 | direct file loading in kernel fails. The user-mode helper is | ||
156 | no longer required unless you have a special firmware file that | ||
157 | resides in a non-standard path. | ||
158 | |||
148 | config DEBUG_DRIVER | 159 | config DEBUG_DRIVER |
149 | bool "Driver Core verbose debug messages" | 160 | bool "Driver Core verbose debug messages" |
150 | depends on DEBUG_KERNEL | 161 | depends on DEBUG_KERNEL |
diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 5aa2d703d19f..4e22ce3ed73d 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile | |||
@@ -21,6 +21,7 @@ endif | |||
21 | obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o | 21 | obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o |
22 | obj-$(CONFIG_REGMAP) += regmap/ | 22 | obj-$(CONFIG_REGMAP) += regmap/ |
23 | obj-$(CONFIG_SOC_BUS) += soc.o | 23 | obj-$(CONFIG_SOC_BUS) += soc.o |
24 | obj-$(CONFIG_PINCTRL) += pinctrl.o | ||
24 | 25 | ||
25 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG | 26 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG |
26 | 27 | ||
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 24eb07868344..519865b53f76 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -290,7 +290,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, | |||
290 | struct device *dev; | 290 | struct device *dev; |
291 | int error = 0; | 291 | int error = 0; |
292 | 292 | ||
293 | if (!bus) | 293 | if (!bus || !bus->p) |
294 | return -EINVAL; | 294 | return -EINVAL; |
295 | 295 | ||
296 | klist_iter_init_node(&bus->p->klist_devices, &i, | 296 | klist_iter_init_node(&bus->p->klist_devices, &i, |
@@ -324,7 +324,7 @@ struct device *bus_find_device(struct bus_type *bus, | |||
324 | struct klist_iter i; | 324 | struct klist_iter i; |
325 | struct device *dev; | 325 | struct device *dev; |
326 | 326 | ||
327 | if (!bus) | 327 | if (!bus || !bus->p) |
328 | return NULL; | 328 | return NULL; |
329 | 329 | ||
330 | klist_iter_init_node(&bus->p->klist_devices, &i, | 330 | klist_iter_init_node(&bus->p->klist_devices, &i, |
@@ -700,12 +700,12 @@ int bus_add_driver(struct device_driver *drv) | |||
700 | if (error) | 700 | if (error) |
701 | goto out_unregister; | 701 | goto out_unregister; |
702 | 702 | ||
703 | klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); | ||
703 | if (drv->bus->p->drivers_autoprobe) { | 704 | if (drv->bus->p->drivers_autoprobe) { |
704 | error = driver_attach(drv); | 705 | error = driver_attach(drv); |
705 | if (error) | 706 | if (error) |
706 | goto out_unregister; | 707 | goto out_unregister; |
707 | } | 708 | } |
708 | klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); | ||
709 | module_add_driver(drv->owner, drv); | 709 | module_add_driver(drv->owner, drv); |
710 | 710 | ||
711 | error = driver_create_file(drv, &driver_attr_uevent); | 711 | error = driver_create_file(drv, &driver_attr_uevent); |
diff --git a/drivers/base/class.c b/drivers/base/class.c index 03243d4002fd..3ce845471327 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -420,8 +420,8 @@ EXPORT_SYMBOL_GPL(class_for_each_device); | |||
420 | * code. There's no locking restriction. | 420 | * code. There's no locking restriction. |
421 | */ | 421 | */ |
422 | struct device *class_find_device(struct class *class, struct device *start, | 422 | struct device *class_find_device(struct class *class, struct device *start, |
423 | void *data, | 423 | const void *data, |
424 | int (*match)(struct device *, void *)) | 424 | int (*match)(struct device *, const void *)) |
425 | { | 425 | { |
426 | struct class_dev_iter iter; | 426 | struct class_dev_iter iter; |
427 | struct device *dev; | 427 | struct device *dev; |
diff --git a/drivers/base/core.c b/drivers/base/core.c index a235085e343c..56536f4b0f6b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1617,9 +1617,9 @@ struct device *device_create(struct class *class, struct device *parent, | |||
1617 | } | 1617 | } |
1618 | EXPORT_SYMBOL_GPL(device_create); | 1618 | EXPORT_SYMBOL_GPL(device_create); |
1619 | 1619 | ||
1620 | static int __match_devt(struct device *dev, void *data) | 1620 | static int __match_devt(struct device *dev, const void *data) |
1621 | { | 1621 | { |
1622 | dev_t *devt = data; | 1622 | const dev_t *devt = data; |
1623 | 1623 | ||
1624 | return dev->devt == *devt; | 1624 | return dev->devt == *devt; |
1625 | } | 1625 | } |
@@ -1685,8 +1685,6 @@ EXPORT_SYMBOL_GPL(device_destroy); | |||
1685 | */ | 1685 | */ |
1686 | int device_rename(struct device *dev, const char *new_name) | 1686 | int device_rename(struct device *dev, const char *new_name) |
1687 | { | 1687 | { |
1688 | char *old_class_name = NULL; | ||
1689 | char *new_class_name = NULL; | ||
1690 | char *old_device_name = NULL; | 1688 | char *old_device_name = NULL; |
1691 | int error; | 1689 | int error; |
1692 | 1690 | ||
@@ -1717,8 +1715,6 @@ int device_rename(struct device *dev, const char *new_name) | |||
1717 | out: | 1715 | out: |
1718 | put_device(dev); | 1716 | put_device(dev); |
1719 | 1717 | ||
1720 | kfree(new_class_name); | ||
1721 | kfree(old_class_name); | ||
1722 | kfree(old_device_name); | 1718 | kfree(old_device_name); |
1723 | 1719 | ||
1724 | return error; | 1720 | return error; |
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index e3bbed8a617c..bb5645ea0282 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/wait.h> | 24 | #include <linux/wait.h> |
25 | #include <linux/async.h> | 25 | #include <linux/async.h> |
26 | #include <linux/pm_runtime.h> | 26 | #include <linux/pm_runtime.h> |
27 | #include <linux/pinctrl/devinfo.h> | ||
27 | 28 | ||
28 | #include "base.h" | 29 | #include "base.h" |
29 | #include "power/power.h" | 30 | #include "power/power.h" |
@@ -172,6 +173,8 @@ static int deferred_probe_initcall(void) | |||
172 | 173 | ||
173 | driver_deferred_probe_enable = true; | 174 | driver_deferred_probe_enable = true; |
174 | driver_deferred_probe_trigger(); | 175 | driver_deferred_probe_trigger(); |
176 | /* Sort as many dependencies as possible before exiting initcalls */ | ||
177 | flush_workqueue(deferred_wq); | ||
175 | return 0; | 178 | return 0; |
176 | } | 179 | } |
177 | late_initcall(deferred_probe_initcall); | 180 | late_initcall(deferred_probe_initcall); |
@@ -269,6 +272,12 @@ static int really_probe(struct device *dev, struct device_driver *drv) | |||
269 | WARN_ON(!list_empty(&dev->devres_head)); | 272 | WARN_ON(!list_empty(&dev->devres_head)); |
270 | 273 | ||
271 | dev->driver = drv; | 274 | dev->driver = drv; |
275 | |||
276 | /* If using pinctrl, bind pins now before probing */ | ||
277 | ret = pinctrl_bind_pins(dev); | ||
278 | if (ret) | ||
279 | goto probe_failed; | ||
280 | |||
272 | if (driver_sysfs_add(dev)) { | 281 | if (driver_sysfs_add(dev)) { |
273 | printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", | 282 | printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", |
274 | __func__, dev_name(dev)); | 283 | __func__, dev_name(dev)); |
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index 17cf7cad601e..01fc5b07f951 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c | |||
@@ -302,7 +302,8 @@ static int handle_remove(const char *nodename, struct device *dev) | |||
302 | 302 | ||
303 | if (dentry->d_inode) { | 303 | if (dentry->d_inode) { |
304 | struct kstat stat; | 304 | struct kstat stat; |
305 | err = vfs_getattr(parent.mnt, dentry, &stat); | 305 | struct path p = {.mnt = parent.mnt, .dentry = dentry}; |
306 | err = vfs_getattr(&p, &stat); | ||
306 | if (!err && dev_mynode(dev, dentry->d_inode, &stat)) { | 307 | if (!err && dev_mynode(dev, dentry->d_inode, &stat)) { |
307 | struct iattr newattrs; | 308 | struct iattr newattrs; |
308 | /* | 309 | /* |
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index a3f79c495a41..2a7cb0df176b 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c | |||
@@ -39,6 +39,8 @@ static int dma_buf_release(struct inode *inode, struct file *file) | |||
39 | 39 | ||
40 | dmabuf = file->private_data; | 40 | dmabuf = file->private_data; |
41 | 41 | ||
42 | BUG_ON(dmabuf->vmapping_counter); | ||
43 | |||
42 | dmabuf->ops->release(dmabuf); | 44 | dmabuf->ops->release(dmabuf); |
43 | kfree(dmabuf); | 45 | kfree(dmabuf); |
44 | return 0; | 46 | return 0; |
@@ -134,15 +136,14 @@ EXPORT_SYMBOL_GPL(dma_buf_export); | |||
134 | */ | 136 | */ |
135 | int dma_buf_fd(struct dma_buf *dmabuf, int flags) | 137 | int dma_buf_fd(struct dma_buf *dmabuf, int flags) |
136 | { | 138 | { |
137 | int error, fd; | 139 | int fd; |
138 | 140 | ||
139 | if (!dmabuf || !dmabuf->file) | 141 | if (!dmabuf || !dmabuf->file) |
140 | return -EINVAL; | 142 | return -EINVAL; |
141 | 143 | ||
142 | error = get_unused_fd_flags(flags); | 144 | fd = get_unused_fd_flags(flags); |
143 | if (error < 0) | 145 | if (fd < 0) |
144 | return error; | 146 | return fd; |
145 | fd = error; | ||
146 | 147 | ||
147 | fd_install(fd, dmabuf->file); | 148 | fd_install(fd, dmabuf->file); |
148 | 149 | ||
@@ -446,6 +447,9 @@ EXPORT_SYMBOL_GPL(dma_buf_kunmap); | |||
446 | int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, | 447 | int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, |
447 | unsigned long pgoff) | 448 | unsigned long pgoff) |
448 | { | 449 | { |
450 | struct file *oldfile; | ||
451 | int ret; | ||
452 | |||
449 | if (WARN_ON(!dmabuf || !vma)) | 453 | if (WARN_ON(!dmabuf || !vma)) |
450 | return -EINVAL; | 454 | return -EINVAL; |
451 | 455 | ||
@@ -459,14 +463,22 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, | |||
459 | return -EINVAL; | 463 | return -EINVAL; |
460 | 464 | ||
461 | /* readjust the vma */ | 465 | /* readjust the vma */ |
462 | if (vma->vm_file) | 466 | get_file(dmabuf->file); |
463 | fput(vma->vm_file); | 467 | oldfile = vma->vm_file; |
464 | 468 | vma->vm_file = dmabuf->file; | |
465 | vma->vm_file = get_file(dmabuf->file); | ||
466 | |||
467 | vma->vm_pgoff = pgoff; | 469 | vma->vm_pgoff = pgoff; |
468 | 470 | ||
469 | return dmabuf->ops->mmap(dmabuf, vma); | 471 | ret = dmabuf->ops->mmap(dmabuf, vma); |
472 | if (ret) { | ||
473 | /* restore old parameters on failure */ | ||
474 | vma->vm_file = oldfile; | ||
475 | fput(dmabuf->file); | ||
476 | } else { | ||
477 | if (oldfile) | ||
478 | fput(oldfile); | ||
479 | } | ||
480 | return ret; | ||
481 | |||
470 | } | 482 | } |
471 | EXPORT_SYMBOL_GPL(dma_buf_mmap); | 483 | EXPORT_SYMBOL_GPL(dma_buf_mmap); |
472 | 484 | ||
@@ -482,12 +494,34 @@ EXPORT_SYMBOL_GPL(dma_buf_mmap); | |||
482 | */ | 494 | */ |
483 | void *dma_buf_vmap(struct dma_buf *dmabuf) | 495 | void *dma_buf_vmap(struct dma_buf *dmabuf) |
484 | { | 496 | { |
497 | void *ptr; | ||
498 | |||
485 | if (WARN_ON(!dmabuf)) | 499 | if (WARN_ON(!dmabuf)) |
486 | return NULL; | 500 | return NULL; |
487 | 501 | ||
488 | if (dmabuf->ops->vmap) | 502 | if (!dmabuf->ops->vmap) |
489 | return dmabuf->ops->vmap(dmabuf); | 503 | return NULL; |
490 | return NULL; | 504 | |
505 | mutex_lock(&dmabuf->lock); | ||
506 | if (dmabuf->vmapping_counter) { | ||
507 | dmabuf->vmapping_counter++; | ||
508 | BUG_ON(!dmabuf->vmap_ptr); | ||
509 | ptr = dmabuf->vmap_ptr; | ||
510 | goto out_unlock; | ||
511 | } | ||
512 | |||
513 | BUG_ON(dmabuf->vmap_ptr); | ||
514 | |||
515 | ptr = dmabuf->ops->vmap(dmabuf); | ||
516 | if (IS_ERR_OR_NULL(ptr)) | ||
517 | goto out_unlock; | ||
518 | |||
519 | dmabuf->vmap_ptr = ptr; | ||
520 | dmabuf->vmapping_counter = 1; | ||
521 | |||
522 | out_unlock: | ||
523 | mutex_unlock(&dmabuf->lock); | ||
524 | return ptr; | ||
491 | } | 525 | } |
492 | EXPORT_SYMBOL_GPL(dma_buf_vmap); | 526 | EXPORT_SYMBOL_GPL(dma_buf_vmap); |
493 | 527 | ||
@@ -501,7 +535,16 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) | |||
501 | if (WARN_ON(!dmabuf)) | 535 | if (WARN_ON(!dmabuf)) |
502 | return; | 536 | return; |
503 | 537 | ||
504 | if (dmabuf->ops->vunmap) | 538 | BUG_ON(!dmabuf->vmap_ptr); |
505 | dmabuf->ops->vunmap(dmabuf, vaddr); | 539 | BUG_ON(dmabuf->vmapping_counter == 0); |
540 | BUG_ON(dmabuf->vmap_ptr != vaddr); | ||
541 | |||
542 | mutex_lock(&dmabuf->lock); | ||
543 | if (--dmabuf->vmapping_counter == 0) { | ||
544 | if (dmabuf->ops->vunmap) | ||
545 | dmabuf->ops->vunmap(dmabuf, vaddr); | ||
546 | dmabuf->vmap_ptr = NULL; | ||
547 | } | ||
548 | mutex_unlock(&dmabuf->lock); | ||
506 | } | 549 | } |
507 | EXPORT_SYMBOL_GPL(dma_buf_vunmap); | 550 | EXPORT_SYMBOL_GPL(dma_buf_vunmap); |
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index b392b353be39..4b1f9265887f 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -88,11 +88,6 @@ enum { | |||
88 | FW_STATUS_ABORT, | 88 | FW_STATUS_ABORT, |
89 | }; | 89 | }; |
90 | 90 | ||
91 | enum fw_buf_fmt { | ||
92 | VMALLOC_BUF, /* used in direct loading */ | ||
93 | PAGE_BUF, /* used in loading via userspace */ | ||
94 | }; | ||
95 | |||
96 | static int loading_timeout = 60; /* In seconds */ | 91 | static int loading_timeout = 60; /* In seconds */ |
97 | 92 | ||
98 | static inline long firmware_loading_timeout(void) | 93 | static inline long firmware_loading_timeout(void) |
@@ -128,12 +123,14 @@ struct firmware_buf { | |||
128 | struct completion completion; | 123 | struct completion completion; |
129 | struct firmware_cache *fwc; | 124 | struct firmware_cache *fwc; |
130 | unsigned long status; | 125 | unsigned long status; |
131 | enum fw_buf_fmt fmt; | ||
132 | void *data; | 126 | void *data; |
133 | size_t size; | 127 | size_t size; |
128 | #ifdef CONFIG_FW_LOADER_USER_HELPER | ||
129 | bool is_paged_buf; | ||
134 | struct page **pages; | 130 | struct page **pages; |
135 | int nr_pages; | 131 | int nr_pages; |
136 | int page_array_size; | 132 | int page_array_size; |
133 | #endif | ||
137 | char fw_id[]; | 134 | char fw_id[]; |
138 | }; | 135 | }; |
139 | 136 | ||
@@ -142,14 +139,6 @@ struct fw_cache_entry { | |||
142 | char name[]; | 139 | char name[]; |
143 | }; | 140 | }; |
144 | 141 | ||
145 | struct firmware_priv { | ||
146 | struct delayed_work timeout_work; | ||
147 | bool nowait; | ||
148 | struct device dev; | ||
149 | struct firmware_buf *buf; | ||
150 | struct firmware *fw; | ||
151 | }; | ||
152 | |||
153 | struct fw_name_devm { | 142 | struct fw_name_devm { |
154 | unsigned long magic; | 143 | unsigned long magic; |
155 | char name[]; | 144 | char name[]; |
@@ -182,7 +171,6 @@ static struct firmware_buf *__allocate_fw_buf(const char *fw_name, | |||
182 | strcpy(buf->fw_id, fw_name); | 171 | strcpy(buf->fw_id, fw_name); |
183 | buf->fwc = fwc; | 172 | buf->fwc = fwc; |
184 | init_completion(&buf->completion); | 173 | init_completion(&buf->completion); |
185 | buf->fmt = VMALLOC_BUF; | ||
186 | 174 | ||
187 | pr_debug("%s: fw-%s buf=%p\n", __func__, fw_name, buf); | 175 | pr_debug("%s: fw-%s buf=%p\n", __func__, fw_name, buf); |
188 | 176 | ||
@@ -240,7 +228,6 @@ static void __fw_free_buf(struct kref *ref) | |||
240 | { | 228 | { |
241 | struct firmware_buf *buf = to_fwbuf(ref); | 229 | struct firmware_buf *buf = to_fwbuf(ref); |
242 | struct firmware_cache *fwc = buf->fwc; | 230 | struct firmware_cache *fwc = buf->fwc; |
243 | int i; | ||
244 | 231 | ||
245 | pr_debug("%s: fw-%s buf=%p data=%p size=%u\n", | 232 | pr_debug("%s: fw-%s buf=%p data=%p size=%u\n", |
246 | __func__, buf->fw_id, buf, buf->data, | 233 | __func__, buf->fw_id, buf, buf->data, |
@@ -249,13 +236,15 @@ static void __fw_free_buf(struct kref *ref) | |||
249 | list_del(&buf->list); | 236 | list_del(&buf->list); |
250 | spin_unlock(&fwc->lock); | 237 | spin_unlock(&fwc->lock); |
251 | 238 | ||
252 | 239 | #ifdef CONFIG_FW_LOADER_USER_HELPER | |
253 | if (buf->fmt == PAGE_BUF) { | 240 | if (buf->is_paged_buf) { |
241 | int i; | ||
254 | vunmap(buf->data); | 242 | vunmap(buf->data); |
255 | for (i = 0; i < buf->nr_pages; i++) | 243 | for (i = 0; i < buf->nr_pages; i++) |
256 | __free_page(buf->pages[i]); | 244 | __free_page(buf->pages[i]); |
257 | kfree(buf->pages); | 245 | kfree(buf->pages); |
258 | } else | 246 | } else |
247 | #endif | ||
259 | vfree(buf->data); | 248 | vfree(buf->data); |
260 | kfree(buf); | 249 | kfree(buf); |
261 | } | 250 | } |
@@ -290,7 +279,7 @@ MODULE_PARM_DESC(path, "customized firmware image search path with a higher prio | |||
290 | static noinline_for_stack long fw_file_size(struct file *file) | 279 | static noinline_for_stack long fw_file_size(struct file *file) |
291 | { | 280 | { |
292 | struct kstat st; | 281 | struct kstat st; |
293 | if (vfs_getattr(file->f_path.mnt, file->f_path.dentry, &st)) | 282 | if (vfs_getattr(&file->f_path, &st)) |
294 | return -1; | 283 | return -1; |
295 | if (!S_ISREG(st.mode)) | 284 | if (!S_ISREG(st.mode)) |
296 | return -1; | 285 | return -1; |
@@ -319,7 +308,8 @@ static bool fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf | |||
319 | return true; | 308 | return true; |
320 | } | 309 | } |
321 | 310 | ||
322 | static bool fw_get_filesystem_firmware(struct firmware_buf *buf) | 311 | static bool fw_get_filesystem_firmware(struct device *device, |
312 | struct firmware_buf *buf) | ||
323 | { | 313 | { |
324 | int i; | 314 | int i; |
325 | bool success = false; | 315 | bool success = false; |
@@ -343,9 +333,114 @@ static bool fw_get_filesystem_firmware(struct firmware_buf *buf) | |||
343 | break; | 333 | break; |
344 | } | 334 | } |
345 | __putname(path); | 335 | __putname(path); |
336 | |||
337 | if (success) { | ||
338 | dev_dbg(device, "firmware: direct-loading firmware %s\n", | ||
339 | buf->fw_id); | ||
340 | mutex_lock(&fw_lock); | ||
341 | set_bit(FW_STATUS_DONE, &buf->status); | ||
342 | complete_all(&buf->completion); | ||
343 | mutex_unlock(&fw_lock); | ||
344 | } | ||
345 | |||
346 | return success; | 346 | return success; |
347 | } | 347 | } |
348 | 348 | ||
349 | /* firmware holds the ownership of pages */ | ||
350 | static void firmware_free_data(const struct firmware *fw) | ||
351 | { | ||
352 | /* Loaded directly? */ | ||
353 | if (!fw->priv) { | ||
354 | vfree(fw->data); | ||
355 | return; | ||
356 | } | ||
357 | fw_free_buf(fw->priv); | ||
358 | } | ||
359 | |||
360 | /* store the pages buffer info firmware from buf */ | ||
361 | static void fw_set_page_data(struct firmware_buf *buf, struct firmware *fw) | ||
362 | { | ||
363 | fw->priv = buf; | ||
364 | #ifdef CONFIG_FW_LOADER_USER_HELPER | ||
365 | fw->pages = buf->pages; | ||
366 | #endif | ||
367 | fw->size = buf->size; | ||
368 | fw->data = buf->data; | ||
369 | |||
370 | pr_debug("%s: fw-%s buf=%p data=%p size=%u\n", | ||
371 | __func__, buf->fw_id, buf, buf->data, | ||
372 | (unsigned int)buf->size); | ||
373 | } | ||
374 | |||
375 | #ifdef CONFIG_PM_SLEEP | ||
376 | static void fw_name_devm_release(struct device *dev, void *res) | ||
377 | { | ||
378 | struct fw_name_devm *fwn = res; | ||
379 | |||
380 | if (fwn->magic == (unsigned long)&fw_cache) | ||
381 | pr_debug("%s: fw_name-%s devm-%p released\n", | ||
382 | __func__, fwn->name, res); | ||
383 | } | ||
384 | |||
385 | static int fw_devm_match(struct device *dev, void *res, | ||
386 | void *match_data) | ||
387 | { | ||
388 | struct fw_name_devm *fwn = res; | ||
389 | |||
390 | return (fwn->magic == (unsigned long)&fw_cache) && | ||
391 | !strcmp(fwn->name, match_data); | ||
392 | } | ||
393 | |||
394 | static struct fw_name_devm *fw_find_devm_name(struct device *dev, | ||
395 | const char *name) | ||
396 | { | ||
397 | struct fw_name_devm *fwn; | ||
398 | |||
399 | fwn = devres_find(dev, fw_name_devm_release, | ||
400 | fw_devm_match, (void *)name); | ||
401 | return fwn; | ||
402 | } | ||
403 | |||
404 | /* add firmware name into devres list */ | ||
405 | static int fw_add_devm_name(struct device *dev, const char *name) | ||
406 | { | ||
407 | struct fw_name_devm *fwn; | ||
408 | |||
409 | fwn = fw_find_devm_name(dev, name); | ||
410 | if (fwn) | ||
411 | return 1; | ||
412 | |||
413 | fwn = devres_alloc(fw_name_devm_release, sizeof(struct fw_name_devm) + | ||
414 | strlen(name) + 1, GFP_KERNEL); | ||
415 | if (!fwn) | ||
416 | return -ENOMEM; | ||
417 | |||
418 | fwn->magic = (unsigned long)&fw_cache; | ||
419 | strcpy(fwn->name, name); | ||
420 | devres_add(dev, fwn); | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | #else | ||
425 | static int fw_add_devm_name(struct device *dev, const char *name) | ||
426 | { | ||
427 | return 0; | ||
428 | } | ||
429 | #endif | ||
430 | |||
431 | |||
432 | /* | ||
433 | * user-mode helper code | ||
434 | */ | ||
435 | #ifdef CONFIG_FW_LOADER_USER_HELPER | ||
436 | struct firmware_priv { | ||
437 | struct delayed_work timeout_work; | ||
438 | bool nowait; | ||
439 | struct device dev; | ||
440 | struct firmware_buf *buf; | ||
441 | struct firmware *fw; | ||
442 | }; | ||
443 | |||
349 | static struct firmware_priv *to_firmware_priv(struct device *dev) | 444 | static struct firmware_priv *to_firmware_priv(struct device *dev) |
350 | { | 445 | { |
351 | return container_of(dev, struct firmware_priv, dev); | 446 | return container_of(dev, struct firmware_priv, dev); |
@@ -359,6 +454,9 @@ static void fw_load_abort(struct firmware_priv *fw_priv) | |||
359 | complete_all(&buf->completion); | 454 | complete_all(&buf->completion); |
360 | } | 455 | } |
361 | 456 | ||
457 | #define is_fw_load_aborted(buf) \ | ||
458 | test_bit(FW_STATUS_ABORT, &(buf)->status) | ||
459 | |||
362 | static ssize_t firmware_timeout_show(struct class *class, | 460 | static ssize_t firmware_timeout_show(struct class *class, |
363 | struct class_attribute *attr, | 461 | struct class_attribute *attr, |
364 | char *buf) | 462 | char *buf) |
@@ -435,17 +533,6 @@ static ssize_t firmware_loading_show(struct device *dev, | |||
435 | return sprintf(buf, "%d\n", loading); | 533 | return sprintf(buf, "%d\n", loading); |
436 | } | 534 | } |
437 | 535 | ||
438 | /* firmware holds the ownership of pages */ | ||
439 | static void firmware_free_data(const struct firmware *fw) | ||
440 | { | ||
441 | /* Loaded directly? */ | ||
442 | if (!fw->priv) { | ||
443 | vfree(fw->data); | ||
444 | return; | ||
445 | } | ||
446 | fw_free_buf(fw->priv); | ||
447 | } | ||
448 | |||
449 | /* Some architectures don't have PAGE_KERNEL_RO */ | 536 | /* Some architectures don't have PAGE_KERNEL_RO */ |
450 | #ifndef PAGE_KERNEL_RO | 537 | #ifndef PAGE_KERNEL_RO |
451 | #define PAGE_KERNEL_RO PAGE_KERNEL | 538 | #define PAGE_KERNEL_RO PAGE_KERNEL |
@@ -454,7 +541,7 @@ static void firmware_free_data(const struct firmware *fw) | |||
454 | /* one pages buffer should be mapped/unmapped only once */ | 541 | /* one pages buffer should be mapped/unmapped only once */ |
455 | static int fw_map_pages_buf(struct firmware_buf *buf) | 542 | static int fw_map_pages_buf(struct firmware_buf *buf) |
456 | { | 543 | { |
457 | if (buf->fmt != PAGE_BUF) | 544 | if (!buf->is_paged_buf) |
458 | return 0; | 545 | return 0; |
459 | 546 | ||
460 | if (buf->data) | 547 | if (buf->data) |
@@ -727,171 +814,16 @@ exit: | |||
727 | return fw_priv; | 814 | return fw_priv; |
728 | } | 815 | } |
729 | 816 | ||
730 | /* store the pages buffer info firmware from buf */ | 817 | /* load a firmware via user helper */ |
731 | static void fw_set_page_data(struct firmware_buf *buf, struct firmware *fw) | ||
732 | { | ||
733 | fw->priv = buf; | ||
734 | fw->pages = buf->pages; | ||
735 | fw->size = buf->size; | ||
736 | fw->data = buf->data; | ||
737 | |||
738 | pr_debug("%s: fw-%s buf=%p data=%p size=%u\n", | ||
739 | __func__, buf->fw_id, buf, buf->data, | ||
740 | (unsigned int)buf->size); | ||
741 | } | ||
742 | |||
743 | #ifdef CONFIG_PM_SLEEP | ||
744 | static void fw_name_devm_release(struct device *dev, void *res) | ||
745 | { | ||
746 | struct fw_name_devm *fwn = res; | ||
747 | |||
748 | if (fwn->magic == (unsigned long)&fw_cache) | ||
749 | pr_debug("%s: fw_name-%s devm-%p released\n", | ||
750 | __func__, fwn->name, res); | ||
751 | } | ||
752 | |||
753 | static int fw_devm_match(struct device *dev, void *res, | ||
754 | void *match_data) | ||
755 | { | ||
756 | struct fw_name_devm *fwn = res; | ||
757 | |||
758 | return (fwn->magic == (unsigned long)&fw_cache) && | ||
759 | !strcmp(fwn->name, match_data); | ||
760 | } | ||
761 | |||
762 | static struct fw_name_devm *fw_find_devm_name(struct device *dev, | ||
763 | const char *name) | ||
764 | { | ||
765 | struct fw_name_devm *fwn; | ||
766 | |||
767 | fwn = devres_find(dev, fw_name_devm_release, | ||
768 | fw_devm_match, (void *)name); | ||
769 | return fwn; | ||
770 | } | ||
771 | |||
772 | /* add firmware name into devres list */ | ||
773 | static int fw_add_devm_name(struct device *dev, const char *name) | ||
774 | { | ||
775 | struct fw_name_devm *fwn; | ||
776 | |||
777 | fwn = fw_find_devm_name(dev, name); | ||
778 | if (fwn) | ||
779 | return 1; | ||
780 | |||
781 | fwn = devres_alloc(fw_name_devm_release, sizeof(struct fw_name_devm) + | ||
782 | strlen(name) + 1, GFP_KERNEL); | ||
783 | if (!fwn) | ||
784 | return -ENOMEM; | ||
785 | |||
786 | fwn->magic = (unsigned long)&fw_cache; | ||
787 | strcpy(fwn->name, name); | ||
788 | devres_add(dev, fwn); | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | #else | ||
793 | static int fw_add_devm_name(struct device *dev, const char *name) | ||
794 | { | ||
795 | return 0; | ||
796 | } | ||
797 | #endif | ||
798 | |||
799 | static void _request_firmware_cleanup(const struct firmware **firmware_p) | ||
800 | { | ||
801 | release_firmware(*firmware_p); | ||
802 | *firmware_p = NULL; | ||
803 | } | ||
804 | |||
805 | static struct firmware_priv * | ||
806 | _request_firmware_prepare(const struct firmware **firmware_p, const char *name, | ||
807 | struct device *device, bool uevent, bool nowait) | ||
808 | { | ||
809 | struct firmware *firmware; | ||
810 | struct firmware_priv *fw_priv = NULL; | ||
811 | struct firmware_buf *buf; | ||
812 | int ret; | ||
813 | |||
814 | if (!firmware_p) | ||
815 | return ERR_PTR(-EINVAL); | ||
816 | |||
817 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); | ||
818 | if (!firmware) { | ||
819 | dev_err(device, "%s: kmalloc(struct firmware) failed\n", | ||
820 | __func__); | ||
821 | return ERR_PTR(-ENOMEM); | ||
822 | } | ||
823 | |||
824 | if (fw_get_builtin_firmware(firmware, name)) { | ||
825 | dev_dbg(device, "firmware: using built-in firmware %s\n", name); | ||
826 | return NULL; | ||
827 | } | ||
828 | |||
829 | ret = fw_lookup_and_allocate_buf(name, &fw_cache, &buf); | ||
830 | if (!ret) | ||
831 | fw_priv = fw_create_instance(firmware, name, device, | ||
832 | uevent, nowait); | ||
833 | |||
834 | if (IS_ERR(fw_priv) || ret < 0) { | ||
835 | kfree(firmware); | ||
836 | *firmware_p = NULL; | ||
837 | return ERR_PTR(-ENOMEM); | ||
838 | } else if (fw_priv) { | ||
839 | fw_priv->buf = buf; | ||
840 | |||
841 | /* | ||
842 | * bind with 'buf' now to avoid warning in failure path | ||
843 | * of requesting firmware. | ||
844 | */ | ||
845 | firmware->priv = buf; | ||
846 | return fw_priv; | ||
847 | } | ||
848 | |||
849 | /* share the cached buf, which is inprogessing or completed */ | ||
850 | check_status: | ||
851 | mutex_lock(&fw_lock); | ||
852 | if (test_bit(FW_STATUS_ABORT, &buf->status)) { | ||
853 | fw_priv = ERR_PTR(-ENOENT); | ||
854 | firmware->priv = buf; | ||
855 | _request_firmware_cleanup(firmware_p); | ||
856 | goto exit; | ||
857 | } else if (test_bit(FW_STATUS_DONE, &buf->status)) { | ||
858 | fw_priv = NULL; | ||
859 | fw_set_page_data(buf, firmware); | ||
860 | goto exit; | ||
861 | } | ||
862 | mutex_unlock(&fw_lock); | ||
863 | wait_for_completion(&buf->completion); | ||
864 | goto check_status; | ||
865 | |||
866 | exit: | ||
867 | mutex_unlock(&fw_lock); | ||
868 | return fw_priv; | ||
869 | } | ||
870 | |||
871 | static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, | 818 | static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, |
872 | long timeout) | 819 | long timeout) |
873 | { | 820 | { |
874 | int retval = 0; | 821 | int retval = 0; |
875 | struct device *f_dev = &fw_priv->dev; | 822 | struct device *f_dev = &fw_priv->dev; |
876 | struct firmware_buf *buf = fw_priv->buf; | 823 | struct firmware_buf *buf = fw_priv->buf; |
877 | struct firmware_cache *fwc = &fw_cache; | ||
878 | int direct_load = 0; | ||
879 | |||
880 | /* try direct loading from fs first */ | ||
881 | if (fw_get_filesystem_firmware(buf)) { | ||
882 | dev_dbg(f_dev->parent, "firmware: direct-loading" | ||
883 | " firmware %s\n", buf->fw_id); | ||
884 | |||
885 | mutex_lock(&fw_lock); | ||
886 | set_bit(FW_STATUS_DONE, &buf->status); | ||
887 | mutex_unlock(&fw_lock); | ||
888 | complete_all(&buf->completion); | ||
889 | direct_load = 1; | ||
890 | goto handle_fw; | ||
891 | } | ||
892 | 824 | ||
893 | /* fall back on userspace loading */ | 825 | /* fall back on userspace loading */ |
894 | buf->fmt = PAGE_BUF; | 826 | buf->is_paged_buf = true; |
895 | 827 | ||
896 | dev_set_uevent_suppress(f_dev, true); | 828 | dev_set_uevent_suppress(f_dev, true); |
897 | 829 | ||
@@ -929,47 +861,196 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, | |||
929 | 861 | ||
930 | cancel_delayed_work_sync(&fw_priv->timeout_work); | 862 | cancel_delayed_work_sync(&fw_priv->timeout_work); |
931 | 863 | ||
932 | handle_fw: | 864 | fw_priv->buf = NULL; |
865 | |||
866 | device_remove_file(f_dev, &dev_attr_loading); | ||
867 | err_del_bin_attr: | ||
868 | device_remove_bin_file(f_dev, &firmware_attr_data); | ||
869 | err_del_dev: | ||
870 | device_del(f_dev); | ||
871 | err_put_dev: | ||
872 | put_device(f_dev); | ||
873 | return retval; | ||
874 | } | ||
875 | |||
876 | static int fw_load_from_user_helper(struct firmware *firmware, | ||
877 | const char *name, struct device *device, | ||
878 | bool uevent, bool nowait, long timeout) | ||
879 | { | ||
880 | struct firmware_priv *fw_priv; | ||
881 | |||
882 | fw_priv = fw_create_instance(firmware, name, device, uevent, nowait); | ||
883 | if (IS_ERR(fw_priv)) | ||
884 | return PTR_ERR(fw_priv); | ||
885 | |||
886 | fw_priv->buf = firmware->priv; | ||
887 | return _request_firmware_load(fw_priv, uevent, timeout); | ||
888 | } | ||
889 | #else /* CONFIG_FW_LOADER_USER_HELPER */ | ||
890 | static inline int | ||
891 | fw_load_from_user_helper(struct firmware *firmware, const char *name, | ||
892 | struct device *device, bool uevent, bool nowait, | ||
893 | long timeout) | ||
894 | { | ||
895 | return -ENOENT; | ||
896 | } | ||
897 | |||
898 | /* No abort during direct loading */ | ||
899 | #define is_fw_load_aborted(buf) false | ||
900 | |||
901 | #endif /* CONFIG_FW_LOADER_USER_HELPER */ | ||
902 | |||
903 | |||
904 | /* wait until the shared firmware_buf becomes ready (or error) */ | ||
905 | static int sync_cached_firmware_buf(struct firmware_buf *buf) | ||
906 | { | ||
907 | int ret = 0; | ||
908 | |||
909 | mutex_lock(&fw_lock); | ||
910 | while (!test_bit(FW_STATUS_DONE, &buf->status)) { | ||
911 | if (is_fw_load_aborted(buf)) { | ||
912 | ret = -ENOENT; | ||
913 | break; | ||
914 | } | ||
915 | mutex_unlock(&fw_lock); | ||
916 | wait_for_completion(&buf->completion); | ||
917 | mutex_lock(&fw_lock); | ||
918 | } | ||
919 | mutex_unlock(&fw_lock); | ||
920 | return ret; | ||
921 | } | ||
922 | |||
923 | /* prepare firmware and firmware_buf structs; | ||
924 | * return 0 if a firmware is already assigned, 1 if need to load one, | ||
925 | * or a negative error code | ||
926 | */ | ||
927 | static int | ||
928 | _request_firmware_prepare(struct firmware **firmware_p, const char *name, | ||
929 | struct device *device) | ||
930 | { | ||
931 | struct firmware *firmware; | ||
932 | struct firmware_buf *buf; | ||
933 | int ret; | ||
934 | |||
935 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); | ||
936 | if (!firmware) { | ||
937 | dev_err(device, "%s: kmalloc(struct firmware) failed\n", | ||
938 | __func__); | ||
939 | return -ENOMEM; | ||
940 | } | ||
941 | |||
942 | if (fw_get_builtin_firmware(firmware, name)) { | ||
943 | dev_dbg(device, "firmware: using built-in firmware %s\n", name); | ||
944 | return 0; /* assigned */ | ||
945 | } | ||
946 | |||
947 | ret = fw_lookup_and_allocate_buf(name, &fw_cache, &buf); | ||
948 | |||
949 | /* | ||
950 | * bind with 'buf' now to avoid warning in failure path | ||
951 | * of requesting firmware. | ||
952 | */ | ||
953 | firmware->priv = buf; | ||
954 | |||
955 | if (ret > 0) { | ||
956 | ret = sync_cached_firmware_buf(buf); | ||
957 | if (!ret) { | ||
958 | fw_set_page_data(buf, firmware); | ||
959 | return 0; /* assigned */ | ||
960 | } | ||
961 | } | ||
962 | |||
963 | if (ret < 0) | ||
964 | return ret; | ||
965 | return 1; /* need to load */ | ||
966 | } | ||
967 | |||
968 | static int assign_firmware_buf(struct firmware *fw, struct device *device) | ||
969 | { | ||
970 | struct firmware_buf *buf = fw->priv; | ||
971 | |||
933 | mutex_lock(&fw_lock); | 972 | mutex_lock(&fw_lock); |
934 | if (!buf->size || test_bit(FW_STATUS_ABORT, &buf->status)) | 973 | if (!buf->size || is_fw_load_aborted(buf)) { |
935 | retval = -ENOENT; | 974 | mutex_unlock(&fw_lock); |
975 | return -ENOENT; | ||
976 | } | ||
936 | 977 | ||
937 | /* | 978 | /* |
938 | * add firmware name into devres list so that we can auto cache | 979 | * add firmware name into devres list so that we can auto cache |
939 | * and uncache firmware for device. | 980 | * and uncache firmware for device. |
940 | * | 981 | * |
941 | * f_dev->parent may has been deleted already, but the problem | 982 | * device may has been deleted already, but the problem |
942 | * should be fixed in devres or driver core. | 983 | * should be fixed in devres or driver core. |
943 | */ | 984 | */ |
944 | if (!retval && f_dev->parent) | 985 | if (device) |
945 | fw_add_devm_name(f_dev->parent, buf->fw_id); | 986 | fw_add_devm_name(device, buf->fw_id); |
946 | 987 | ||
947 | /* | 988 | /* |
948 | * After caching firmware image is started, let it piggyback | 989 | * After caching firmware image is started, let it piggyback |
949 | * on request firmware. | 990 | * on request firmware. |
950 | */ | 991 | */ |
951 | if (!retval && fwc->state == FW_LOADER_START_CACHE) { | 992 | if (buf->fwc->state == FW_LOADER_START_CACHE) { |
952 | if (fw_cache_piggyback_on_request(buf->fw_id)) | 993 | if (fw_cache_piggyback_on_request(buf->fw_id)) |
953 | kref_get(&buf->ref); | 994 | kref_get(&buf->ref); |
954 | } | 995 | } |
955 | 996 | ||
956 | /* pass the pages buffer to driver at the last minute */ | 997 | /* pass the pages buffer to driver at the last minute */ |
957 | fw_set_page_data(buf, fw_priv->fw); | 998 | fw_set_page_data(buf, fw); |
958 | |||
959 | fw_priv->buf = NULL; | ||
960 | mutex_unlock(&fw_lock); | 999 | mutex_unlock(&fw_lock); |
1000 | return 0; | ||
1001 | } | ||
961 | 1002 | ||
962 | if (direct_load) | 1003 | /* called from request_firmware() and request_firmware_work_func() */ |
963 | goto err_put_dev; | 1004 | static int |
1005 | _request_firmware(const struct firmware **firmware_p, const char *name, | ||
1006 | struct device *device, bool uevent, bool nowait) | ||
1007 | { | ||
1008 | struct firmware *fw; | ||
1009 | long timeout; | ||
1010 | int ret; | ||
964 | 1011 | ||
965 | device_remove_file(f_dev, &dev_attr_loading); | 1012 | if (!firmware_p) |
966 | err_del_bin_attr: | 1013 | return -EINVAL; |
967 | device_remove_bin_file(f_dev, &firmware_attr_data); | 1014 | |
968 | err_del_dev: | 1015 | ret = _request_firmware_prepare(&fw, name, device); |
969 | device_del(f_dev); | 1016 | if (ret <= 0) /* error or already assigned */ |
970 | err_put_dev: | 1017 | goto out; |
971 | put_device(f_dev); | 1018 | |
972 | return retval; | 1019 | ret = 0; |
1020 | timeout = firmware_loading_timeout(); | ||
1021 | if (nowait) { | ||
1022 | timeout = usermodehelper_read_lock_wait(timeout); | ||
1023 | if (!timeout) { | ||
1024 | dev_dbg(device, "firmware: %s loading timed out\n", | ||
1025 | name); | ||
1026 | ret = -EBUSY; | ||
1027 | goto out; | ||
1028 | } | ||
1029 | } else { | ||
1030 | ret = usermodehelper_read_trylock(); | ||
1031 | if (WARN_ON(ret)) { | ||
1032 | dev_err(device, "firmware: %s will not be loaded\n", | ||
1033 | name); | ||
1034 | goto out; | ||
1035 | } | ||
1036 | } | ||
1037 | |||
1038 | if (!fw_get_filesystem_firmware(device, fw->priv)) | ||
1039 | ret = fw_load_from_user_helper(fw, name, device, | ||
1040 | uevent, nowait, timeout); | ||
1041 | if (!ret) | ||
1042 | ret = assign_firmware_buf(fw, device); | ||
1043 | |||
1044 | usermodehelper_read_unlock(); | ||
1045 | |||
1046 | out: | ||
1047 | if (ret < 0) { | ||
1048 | release_firmware(fw); | ||
1049 | fw = NULL; | ||
1050 | } | ||
1051 | |||
1052 | *firmware_p = fw; | ||
1053 | return ret; | ||
973 | } | 1054 | } |
974 | 1055 | ||
975 | /** | 1056 | /** |
@@ -996,26 +1077,7 @@ int | |||
996 | request_firmware(const struct firmware **firmware_p, const char *name, | 1077 | request_firmware(const struct firmware **firmware_p, const char *name, |
997 | struct device *device) | 1078 | struct device *device) |
998 | { | 1079 | { |
999 | struct firmware_priv *fw_priv; | 1080 | return _request_firmware(firmware_p, name, device, true, false); |
1000 | int ret; | ||
1001 | |||
1002 | fw_priv = _request_firmware_prepare(firmware_p, name, device, true, | ||
1003 | false); | ||
1004 | if (IS_ERR_OR_NULL(fw_priv)) | ||
1005 | return PTR_RET(fw_priv); | ||
1006 | |||
1007 | ret = usermodehelper_read_trylock(); | ||
1008 | if (WARN_ON(ret)) { | ||
1009 | dev_err(device, "firmware: %s will not be loaded\n", name); | ||
1010 | } else { | ||
1011 | ret = _request_firmware_load(fw_priv, true, | ||
1012 | firmware_loading_timeout()); | ||
1013 | usermodehelper_read_unlock(); | ||
1014 | } | ||
1015 | if (ret) | ||
1016 | _request_firmware_cleanup(firmware_p); | ||
1017 | |||
1018 | return ret; | ||
1019 | } | 1081 | } |
1020 | 1082 | ||
1021 | /** | 1083 | /** |
@@ -1046,33 +1108,13 @@ static void request_firmware_work_func(struct work_struct *work) | |||
1046 | { | 1108 | { |
1047 | struct firmware_work *fw_work; | 1109 | struct firmware_work *fw_work; |
1048 | const struct firmware *fw; | 1110 | const struct firmware *fw; |
1049 | struct firmware_priv *fw_priv; | ||
1050 | long timeout; | ||
1051 | int ret; | ||
1052 | 1111 | ||
1053 | fw_work = container_of(work, struct firmware_work, work); | 1112 | fw_work = container_of(work, struct firmware_work, work); |
1054 | fw_priv = _request_firmware_prepare(&fw, fw_work->name, fw_work->device, | ||
1055 | fw_work->uevent, true); | ||
1056 | if (IS_ERR_OR_NULL(fw_priv)) { | ||
1057 | ret = PTR_RET(fw_priv); | ||
1058 | goto out; | ||
1059 | } | ||
1060 | |||
1061 | timeout = usermodehelper_read_lock_wait(firmware_loading_timeout()); | ||
1062 | if (timeout) { | ||
1063 | ret = _request_firmware_load(fw_priv, fw_work->uevent, timeout); | ||
1064 | usermodehelper_read_unlock(); | ||
1065 | } else { | ||
1066 | dev_dbg(fw_work->device, "firmware: %s loading timed out\n", | ||
1067 | fw_work->name); | ||
1068 | ret = -EAGAIN; | ||
1069 | } | ||
1070 | if (ret) | ||
1071 | _request_firmware_cleanup(&fw); | ||
1072 | 1113 | ||
1073 | out: | 1114 | _request_firmware(&fw, fw_work->name, fw_work->device, |
1115 | fw_work->uevent, true); | ||
1074 | fw_work->cont(fw, fw_work->context); | 1116 | fw_work->cont(fw, fw_work->context); |
1075 | put_device(fw_work->device); | 1117 | put_device(fw_work->device); /* taken in request_firmware_nowait() */ |
1076 | 1118 | ||
1077 | module_put(fw_work->module); | 1119 | module_put(fw_work->module); |
1078 | kfree(fw_work); | 1120 | kfree(fw_work); |
@@ -1474,7 +1516,11 @@ static void __init fw_cache_init(void) | |||
1474 | static int __init firmware_class_init(void) | 1516 | static int __init firmware_class_init(void) |
1475 | { | 1517 | { |
1476 | fw_cache_init(); | 1518 | fw_cache_init(); |
1519 | #ifdef CONFIG_FW_LOADER_USER_HELPER | ||
1477 | return class_register(&firmware_class); | 1520 | return class_register(&firmware_class); |
1521 | #else | ||
1522 | return 0; | ||
1523 | #endif | ||
1478 | } | 1524 | } |
1479 | 1525 | ||
1480 | static void __exit firmware_class_exit(void) | 1526 | static void __exit firmware_class_exit(void) |
@@ -1483,7 +1529,9 @@ static void __exit firmware_class_exit(void) | |||
1483 | unregister_syscore_ops(&fw_syscore_ops); | 1529 | unregister_syscore_ops(&fw_syscore_ops); |
1484 | unregister_pm_notifier(&fw_cache.pm_notify); | 1530 | unregister_pm_notifier(&fw_cache.pm_notify); |
1485 | #endif | 1531 | #endif |
1532 | #ifdef CONFIG_FW_LOADER_USER_HELPER | ||
1486 | class_unregister(&firmware_class); | 1533 | class_unregister(&firmware_class); |
1534 | #endif | ||
1487 | } | 1535 | } |
1488 | 1536 | ||
1489 | fs_initcall(firmware_class_init); | 1537 | fs_initcall(firmware_class_init); |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 987604d56c83..a51007b79032 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -494,8 +494,8 @@ store_hard_offline_page(struct device *dev, | |||
494 | return ret ? ret : count; | 494 | return ret ? ret : count; |
495 | } | 495 | } |
496 | 496 | ||
497 | static DEVICE_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page); | 497 | static DEVICE_ATTR(soft_offline_page, S_IWUSR, NULL, store_soft_offline_page); |
498 | static DEVICE_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page); | 498 | static DEVICE_ATTR(hard_offline_page, S_IWUSR, NULL, store_hard_offline_page); |
499 | 499 | ||
500 | static __init int memory_fail_init(void) | 500 | static __init int memory_fail_init(void) |
501 | { | 501 | { |
@@ -693,6 +693,12 @@ int offline_memory_block(struct memory_block *mem) | |||
693 | return ret; | 693 | return ret; |
694 | } | 694 | } |
695 | 695 | ||
696 | /* return true if the memory block is offlined, otherwise, return false */ | ||
697 | bool is_memblock_offlined(struct memory_block *mem) | ||
698 | { | ||
699 | return mem->state == MEM_OFFLINE; | ||
700 | } | ||
701 | |||
696 | /* | 702 | /* |
697 | * Initialize the sysfs support for memory devices... | 703 | * Initialize the sysfs support for memory devices... |
698 | */ | 704 | */ |
diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c new file mode 100644 index 000000000000..67a274e86727 --- /dev/null +++ b/drivers/base/pinctrl.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Driver core interface to the pinctrl subsystem. | ||
3 | * | ||
4 | * Copyright (C) 2012 ST-Ericsson SA | ||
5 | * Written on behalf of Linaro for ST-Ericsson | ||
6 | * Based on bits of regulator core, gpio core and clk core | ||
7 | * | ||
8 | * Author: Linus Walleij <linus.walleij@linaro.org> | ||
9 | * | ||
10 | * License terms: GNU General Public License (GPL) version 2 | ||
11 | */ | ||
12 | |||
13 | #include <linux/device.h> | ||
14 | #include <linux/pinctrl/devinfo.h> | ||
15 | #include <linux/pinctrl/consumer.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | /** | ||
19 | * pinctrl_bind_pins() - called by the device core before probe | ||
20 | * @dev: the device that is just about to probe | ||
21 | */ | ||
22 | int pinctrl_bind_pins(struct device *dev) | ||
23 | { | ||
24 | int ret; | ||
25 | |||
26 | dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL); | ||
27 | if (!dev->pins) | ||
28 | return -ENOMEM; | ||
29 | |||
30 | dev->pins->p = devm_pinctrl_get(dev); | ||
31 | if (IS_ERR(dev->pins->p)) { | ||
32 | dev_dbg(dev, "no pinctrl handle\n"); | ||
33 | ret = PTR_ERR(dev->pins->p); | ||
34 | goto cleanup_alloc; | ||
35 | } | ||
36 | |||
37 | dev->pins->default_state = pinctrl_lookup_state(dev->pins->p, | ||
38 | PINCTRL_STATE_DEFAULT); | ||
39 | if (IS_ERR(dev->pins->default_state)) { | ||
40 | dev_dbg(dev, "no default pinctrl state\n"); | ||
41 | ret = 0; | ||
42 | goto cleanup_get; | ||
43 | } | ||
44 | |||
45 | ret = pinctrl_select_state(dev->pins->p, dev->pins->default_state); | ||
46 | if (ret) { | ||
47 | dev_dbg(dev, "failed to activate default pinctrl state\n"); | ||
48 | goto cleanup_get; | ||
49 | } | ||
50 | |||
51 | return 0; | ||
52 | |||
53 | /* | ||
54 | * If no pinctrl handle or default state was found for this device, | ||
55 | * let's explicitly free the pin container in the device, there is | ||
56 | * no point in keeping it around. | ||
57 | */ | ||
58 | cleanup_get: | ||
59 | devm_pinctrl_put(dev->pins->p); | ||
60 | cleanup_alloc: | ||
61 | devm_kfree(dev, dev->pins); | ||
62 | dev->pins = NULL; | ||
63 | |||
64 | /* Only return deferrals */ | ||
65 | if (ret != -EPROBE_DEFER) | ||
66 | ret = 0; | ||
67 | |||
68 | return ret; | ||
69 | } | ||
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index acc3a8ded29d..9a6b05a35603 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c | |||
@@ -433,8 +433,7 @@ static bool genpd_abort_poweroff(struct generic_pm_domain *genpd) | |||
433 | */ | 433 | */ |
434 | void genpd_queue_power_off_work(struct generic_pm_domain *genpd) | 434 | void genpd_queue_power_off_work(struct generic_pm_domain *genpd) |
435 | { | 435 | { |
436 | if (!work_pending(&genpd->power_off_work)) | 436 | queue_work(pm_wq, &genpd->power_off_work); |
437 | queue_work(pm_wq, &genpd->power_off_work); | ||
438 | } | 437 | } |
439 | 438 | ||
440 | /** | 439 | /** |
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 50b2831e027d..32ee0fc7ea54 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c | |||
@@ -162,7 +162,7 @@ unsigned long opp_get_voltage(struct opp *opp) | |||
162 | 162 | ||
163 | return v; | 163 | return v; |
164 | } | 164 | } |
165 | EXPORT_SYMBOL(opp_get_voltage); | 165 | EXPORT_SYMBOL_GPL(opp_get_voltage); |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * opp_get_freq() - Gets the frequency corresponding to an available opp | 168 | * opp_get_freq() - Gets the frequency corresponding to an available opp |
@@ -192,7 +192,7 @@ unsigned long opp_get_freq(struct opp *opp) | |||
192 | 192 | ||
193 | return f; | 193 | return f; |
194 | } | 194 | } |
195 | EXPORT_SYMBOL(opp_get_freq); | 195 | EXPORT_SYMBOL_GPL(opp_get_freq); |
196 | 196 | ||
197 | /** | 197 | /** |
198 | * opp_get_opp_count() - Get number of opps available in the opp list | 198 | * opp_get_opp_count() - Get number of opps available in the opp list |
@@ -225,7 +225,7 @@ int opp_get_opp_count(struct device *dev) | |||
225 | 225 | ||
226 | return count; | 226 | return count; |
227 | } | 227 | } |
228 | EXPORT_SYMBOL(opp_get_opp_count); | 228 | EXPORT_SYMBOL_GPL(opp_get_opp_count); |
229 | 229 | ||
230 | /** | 230 | /** |
231 | * opp_find_freq_exact() - search for an exact frequency | 231 | * opp_find_freq_exact() - search for an exact frequency |
@@ -276,7 +276,7 @@ struct opp *opp_find_freq_exact(struct device *dev, unsigned long freq, | |||
276 | 276 | ||
277 | return opp; | 277 | return opp; |
278 | } | 278 | } |
279 | EXPORT_SYMBOL(opp_find_freq_exact); | 279 | EXPORT_SYMBOL_GPL(opp_find_freq_exact); |
280 | 280 | ||
281 | /** | 281 | /** |
282 | * opp_find_freq_ceil() - Search for an rounded ceil freq | 282 | * opp_find_freq_ceil() - Search for an rounded ceil freq |
@@ -323,7 +323,7 @@ struct opp *opp_find_freq_ceil(struct device *dev, unsigned long *freq) | |||
323 | 323 | ||
324 | return opp; | 324 | return opp; |
325 | } | 325 | } |
326 | EXPORT_SYMBOL(opp_find_freq_ceil); | 326 | EXPORT_SYMBOL_GPL(opp_find_freq_ceil); |
327 | 327 | ||
328 | /** | 328 | /** |
329 | * opp_find_freq_floor() - Search for a rounded floor freq | 329 | * opp_find_freq_floor() - Search for a rounded floor freq |
@@ -374,7 +374,7 @@ struct opp *opp_find_freq_floor(struct device *dev, unsigned long *freq) | |||
374 | 374 | ||
375 | return opp; | 375 | return opp; |
376 | } | 376 | } |
377 | EXPORT_SYMBOL(opp_find_freq_floor); | 377 | EXPORT_SYMBOL_GPL(opp_find_freq_floor); |
378 | 378 | ||
379 | /** | 379 | /** |
380 | * opp_add() - Add an OPP table from a table definitions | 380 | * opp_add() - Add an OPP table from a table definitions |
@@ -568,7 +568,7 @@ int opp_enable(struct device *dev, unsigned long freq) | |||
568 | { | 568 | { |
569 | return opp_set_availability(dev, freq, true); | 569 | return opp_set_availability(dev, freq, true); |
570 | } | 570 | } |
571 | EXPORT_SYMBOL(opp_enable); | 571 | EXPORT_SYMBOL_GPL(opp_enable); |
572 | 572 | ||
573 | /** | 573 | /** |
574 | * opp_disable() - Disable a specific OPP | 574 | * opp_disable() - Disable a specific OPP |
@@ -590,7 +590,7 @@ int opp_disable(struct device *dev, unsigned long freq) | |||
590 | { | 590 | { |
591 | return opp_set_availability(dev, freq, false); | 591 | return opp_set_availability(dev, freq, false); |
592 | } | 592 | } |
593 | EXPORT_SYMBOL(opp_disable); | 593 | EXPORT_SYMBOL_GPL(opp_disable); |
594 | 594 | ||
595 | #ifdef CONFIG_CPU_FREQ | 595 | #ifdef CONFIG_CPU_FREQ |
596 | /** | 596 | /** |
@@ -661,6 +661,7 @@ int opp_init_cpufreq_table(struct device *dev, | |||
661 | 661 | ||
662 | return 0; | 662 | return 0; |
663 | } | 663 | } |
664 | EXPORT_SYMBOL_GPL(opp_init_cpufreq_table); | ||
664 | 665 | ||
665 | /** | 666 | /** |
666 | * opp_free_cpufreq_table() - free the cpufreq table | 667 | * opp_free_cpufreq_table() - free the cpufreq table |
@@ -678,6 +679,7 @@ void opp_free_cpufreq_table(struct device *dev, | |||
678 | kfree(*table); | 679 | kfree(*table); |
679 | *table = NULL; | 680 | *table = NULL; |
680 | } | 681 | } |
682 | EXPORT_SYMBOL_GPL(opp_free_cpufreq_table); | ||
681 | #endif /* CONFIG_CPU_FREQ */ | 683 | #endif /* CONFIG_CPU_FREQ */ |
682 | 684 | ||
683 | /** | 685 | /** |
@@ -738,4 +740,5 @@ int of_init_opp_table(struct device *dev) | |||
738 | 740 | ||
739 | return 0; | 741 | return 0; |
740 | } | 742 | } |
743 | EXPORT_SYMBOL_GPL(of_init_opp_table); | ||
741 | #endif | 744 | #endif |
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index d21349544ce5..3d4d1f8aac5c 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c | |||
@@ -91,6 +91,7 @@ enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask) | |||
91 | 91 | ||
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | EXPORT_SYMBOL_GPL(dev_pm_qos_flags); | ||
94 | 95 | ||
95 | /** | 96 | /** |
96 | * __dev_pm_qos_read_value - Get PM QoS constraint for a given device. | 97 | * __dev_pm_qos_read_value - Get PM QoS constraint for a given device. |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 3148b10dc2e5..1244930e3d7a 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
@@ -124,6 +124,76 @@ unsigned long pm_runtime_autosuspend_expiration(struct device *dev) | |||
124 | } | 124 | } |
125 | EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration); | 125 | EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration); |
126 | 126 | ||
127 | static int dev_memalloc_noio(struct device *dev, void *data) | ||
128 | { | ||
129 | return dev->power.memalloc_noio; | ||
130 | } | ||
131 | |||
132 | /* | ||
133 | * pm_runtime_set_memalloc_noio - Set a device's memalloc_noio flag. | ||
134 | * @dev: Device to handle. | ||
135 | * @enable: True for setting the flag and False for clearing the flag. | ||
136 | * | ||
137 | * Set the flag for all devices in the path from the device to the | ||
138 | * root device in the device tree if @enable is true, otherwise clear | ||
139 | * the flag for devices in the path whose siblings don't set the flag. | ||
140 | * | ||
141 | * The function should only be called by block device, or network | ||
142 | * device driver for solving the deadlock problem during runtime | ||
143 | * resume/suspend: | ||
144 | * | ||
145 | * If memory allocation with GFP_KERNEL is called inside runtime | ||
146 | * resume/suspend callback of any one of its ancestors(or the | ||
147 | * block device itself), the deadlock may be triggered inside the | ||
148 | * memory allocation since it might not complete until the block | ||
149 | * device becomes active and the involed page I/O finishes. The | ||
150 | * situation is pointed out first by Alan Stern. Network device | ||
151 | * are involved in iSCSI kind of situation. | ||
152 | * | ||
153 | * The lock of dev_hotplug_mutex is held in the function for handling | ||
154 | * hotplug race because pm_runtime_set_memalloc_noio() may be called | ||
155 | * in async probe(). | ||
156 | * | ||
157 | * The function should be called between device_add() and device_del() | ||
158 | * on the affected device(block/network device). | ||
159 | */ | ||
160 | void pm_runtime_set_memalloc_noio(struct device *dev, bool enable) | ||
161 | { | ||
162 | static DEFINE_MUTEX(dev_hotplug_mutex); | ||
163 | |||
164 | mutex_lock(&dev_hotplug_mutex); | ||
165 | for (;;) { | ||
166 | bool enabled; | ||
167 | |||
168 | /* hold power lock since bitfield is not SMP-safe. */ | ||
169 | spin_lock_irq(&dev->power.lock); | ||
170 | enabled = dev->power.memalloc_noio; | ||
171 | dev->power.memalloc_noio = enable; | ||
172 | spin_unlock_irq(&dev->power.lock); | ||
173 | |||
174 | /* | ||
175 | * not need to enable ancestors any more if the device | ||
176 | * has been enabled. | ||
177 | */ | ||
178 | if (enabled && enable) | ||
179 | break; | ||
180 | |||
181 | dev = dev->parent; | ||
182 | |||
183 | /* | ||
184 | * clear flag of the parent device only if all the | ||
185 | * children don't set the flag because ancestor's | ||
186 | * flag was set by any one of the descendants. | ||
187 | */ | ||
188 | if (!dev || (!enable && | ||
189 | device_for_each_child(dev, NULL, | ||
190 | dev_memalloc_noio))) | ||
191 | break; | ||
192 | } | ||
193 | mutex_unlock(&dev_hotplug_mutex); | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(pm_runtime_set_memalloc_noio); | ||
196 | |||
127 | /** | 197 | /** |
128 | * rpm_check_suspend_allowed - Test whether a device may be suspended. | 198 | * rpm_check_suspend_allowed - Test whether a device may be suspended. |
129 | * @dev: Device to test. | 199 | * @dev: Device to test. |
@@ -278,7 +348,24 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev) | |||
278 | if (!cb) | 348 | if (!cb) |
279 | return -ENOSYS; | 349 | return -ENOSYS; |
280 | 350 | ||
281 | retval = __rpm_callback(cb, dev); | 351 | if (dev->power.memalloc_noio) { |
352 | unsigned int noio_flag; | ||
353 | |||
354 | /* | ||
355 | * Deadlock might be caused if memory allocation with | ||
356 | * GFP_KERNEL happens inside runtime_suspend and | ||
357 | * runtime_resume callbacks of one block device's | ||
358 | * ancestor or the block device itself. Network | ||
359 | * device might be thought as part of iSCSI block | ||
360 | * device, so network device and its ancestor should | ||
361 | * be marked as memalloc_noio too. | ||
362 | */ | ||
363 | noio_flag = memalloc_noio_save(); | ||
364 | retval = __rpm_callback(cb, dev); | ||
365 | memalloc_noio_restore(noio_flag); | ||
366 | } else { | ||
367 | retval = __rpm_callback(cb, dev); | ||
368 | } | ||
282 | 369 | ||
283 | dev->power.runtime_error = retval; | 370 | dev->power.runtime_error = retval; |
284 | return retval != -EACCES ? retval : -EIO; | 371 | return retval != -EACCES ? retval : -EIO; |
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index e6ee5e80e546..79715e7fa43e 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c | |||
@@ -382,6 +382,12 @@ static void wakeup_source_activate(struct wakeup_source *ws) | |||
382 | { | 382 | { |
383 | unsigned int cec; | 383 | unsigned int cec; |
384 | 384 | ||
385 | /* | ||
386 | * active wakeup source should bring the system | ||
387 | * out of PM_SUSPEND_FREEZE state | ||
388 | */ | ||
389 | freeze_wake(); | ||
390 | |||
385 | ws->active = true; | 391 | ws->active = true; |
386 | ws->active_count++; | 392 | ws->active_count++; |
387 | ws->last_time = ktime_get(); | 393 | ws->last_time = ktime_get(); |
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 78d5f20c5f5b..81d6f605c92e 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c | |||
@@ -279,7 +279,7 @@ static ssize_t regmap_map_write_file(struct file *file, | |||
279 | return -EINVAL; | 279 | return -EINVAL; |
280 | 280 | ||
281 | /* Userspace has been fiddling around behind the kernel's back */ | 281 | /* Userspace has been fiddling around behind the kernel's back */ |
282 | add_taint(TAINT_USER); | 282 | add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); |
283 | 283 | ||
284 | regmap_write(map, reg, value); | 284 | regmap_write(map, reg, value); |
285 | return buf_size; | 285 | return buf_size; |