aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-09-22 07:08:57 -0400
committerIngo Molnar <mingo@elte.hu>2008-09-22 07:08:57 -0400
commit0b88641f1bafdbd087d5e63987a30cc0eadd63b9 (patch)
tree81dcf756db373444140bb2623584710c628e3048 /drivers/base
parentfbdbf709938d155c719c76b9894d28342632c797 (diff)
parent72d31053f62c4bc464c2783974926969614a8649 (diff)
Merge commit 'v2.6.27-rc7' into x86/debug
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/class.c12
-rw-r--r--drivers/base/core.c37
-rw-r--r--drivers/base/driver.c3
-rw-r--r--drivers/base/firmware_class.c12
-rw-r--r--drivers/base/isa.c4
-rw-r--r--drivers/base/memory.c23
-rw-r--r--drivers/base/power/main.c19
-rw-r--r--drivers/base/power/power.h9
-rw-r--r--drivers/base/sys.c12
9 files changed, 78 insertions, 53 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 839d27cecb36..cc5e28c8885c 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -198,6 +198,7 @@ static void class_create_release(struct class *cls)
198 * class_create - create a struct class structure 198 * class_create - create a struct class structure
199 * @owner: pointer to the module that is to "own" this struct class 199 * @owner: pointer to the module that is to "own" this struct class
200 * @name: pointer to a string for the name of this class. 200 * @name: pointer to a string for the name of this class.
201 * @key: the lock_class_key for this class; used by mutex lock debugging
201 * 202 *
202 * This is used to create a struct class pointer that can then be used 203 * This is used to create a struct class pointer that can then be used
203 * in calls to device_create(). 204 * in calls to device_create().
@@ -294,6 +295,12 @@ int class_for_each_device(struct class *class, struct device *start,
294 295
295 if (!class) 296 if (!class)
296 return -EINVAL; 297 return -EINVAL;
298 if (!class->p) {
299 WARN(1, "%s called for class '%s' before it was initialized",
300 __func__, class->name);
301 return -EINVAL;
302 }
303
297 mutex_lock(&class->p->class_mutex); 304 mutex_lock(&class->p->class_mutex);
298 list_for_each_entry(dev, &class->p->class_devices, node) { 305 list_for_each_entry(dev, &class->p->class_devices, node) {
299 if (start) { 306 if (start) {
@@ -343,6 +350,11 @@ struct device *class_find_device(struct class *class, struct device *start,
343 350
344 if (!class) 351 if (!class)
345 return NULL; 352 return NULL;
353 if (!class->p) {
354 WARN(1, "%s called for class '%s' before it was initialized",
355 __func__, class->name);
356 return NULL;
357 }
346 358
347 mutex_lock(&class->p->class_mutex); 359 mutex_lock(&class->p->class_mutex);
348 list_for_each_entry(dev, &class->p->class_devices, node) { 360 list_for_each_entry(dev, &class->p->class_devices, node) {
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7d5c63c81a59..d021c98605b3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -53,7 +53,7 @@ static inline int device_is_not_partition(struct device *dev)
53 * it is attached to. If it is not attached to a bus either, an empty 53 * it is attached to. If it is not attached to a bus either, an empty
54 * string will be returned. 54 * string will be returned.
55 */ 55 */
56const char *dev_driver_string(struct device *dev) 56const char *dev_driver_string(const struct device *dev)
57{ 57{
58 return dev->driver ? dev->driver->name : 58 return dev->driver ? dev->driver->name :
59 (dev->bus ? dev->bus->name : 59 (dev->bus ? dev->bus->name :
@@ -116,12 +116,10 @@ static void device_release(struct kobject *kobj)
116 dev->type->release(dev); 116 dev->type->release(dev);
117 else if (dev->class && dev->class->dev_release) 117 else if (dev->class && dev->class->dev_release)
118 dev->class->dev_release(dev); 118 dev->class->dev_release(dev);
119 else { 119 else
120 printk(KERN_ERR "Device '%s' does not have a release() " 120 WARN(1, KERN_ERR "Device '%s' does not have a release() "
121 "function, it is broken and must be fixed.\n", 121 "function, it is broken and must be fixed.\n",
122 dev->bus_id); 122 dev->bus_id);
123 WARN_ON(1);
124 }
125} 123}
126 124
127static struct kobj_type device_ktype = { 125static struct kobj_type device_ktype = {
@@ -543,6 +541,7 @@ void device_initialize(struct device *dev)
543 spin_lock_init(&dev->devres_lock); 541 spin_lock_init(&dev->devres_lock);
544 INIT_LIST_HEAD(&dev->devres_head); 542 INIT_LIST_HEAD(&dev->devres_head);
545 device_init_wakeup(dev, 0); 543 device_init_wakeup(dev, 0);
544 device_pm_init(dev);
546 set_dev_node(dev, -1); 545 set_dev_node(dev, -1);
547} 546}
548 547
@@ -845,13 +844,19 @@ int device_add(struct device *dev)
845{ 844{
846 struct device *parent = NULL; 845 struct device *parent = NULL;
847 struct class_interface *class_intf; 846 struct class_interface *class_intf;
848 int error; 847 int error = -EINVAL;
849 848
850 dev = get_device(dev); 849 dev = get_device(dev);
851 if (!dev || !strlen(dev->bus_id)) { 850 if (!dev)
852 error = -EINVAL; 851 goto done;
853 goto Done; 852
854 } 853 /* Temporarily support init_name if it is set.
854 * It will override bus_id for now */
855 if (dev->init_name)
856 dev_set_name(dev, "%s", dev->init_name);
857
858 if (!strlen(dev->bus_id))
859 goto done;
855 860
856 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 861 pr_debug("device: '%s': %s\n", dev->bus_id, __func__);
857 862
@@ -899,9 +904,10 @@ int device_add(struct device *dev)
899 error = bus_add_device(dev); 904 error = bus_add_device(dev);
900 if (error) 905 if (error)
901 goto BusError; 906 goto BusError;
902 error = device_pm_add(dev); 907 error = dpm_sysfs_add(dev);
903 if (error) 908 if (error)
904 goto PMError; 909 goto DPMError;
910 device_pm_add(dev);
905 kobject_uevent(&dev->kobj, KOBJ_ADD); 911 kobject_uevent(&dev->kobj, KOBJ_ADD);
906 bus_attach_device(dev); 912 bus_attach_device(dev);
907 if (parent) 913 if (parent)
@@ -919,10 +925,10 @@ int device_add(struct device *dev)
919 class_intf->add_dev(dev, class_intf); 925 class_intf->add_dev(dev, class_intf);
920 mutex_unlock(&dev->class->p->class_mutex); 926 mutex_unlock(&dev->class->p->class_mutex);
921 } 927 }
922 Done: 928done:
923 put_device(dev); 929 put_device(dev);
924 return error; 930 return error;
925 PMError: 931 DPMError:
926 bus_remove_device(dev); 932 bus_remove_device(dev);
927 BusError: 933 BusError:
928 if (dev->bus) 934 if (dev->bus)
@@ -946,7 +952,7 @@ int device_add(struct device *dev)
946 cleanup_device_parent(dev); 952 cleanup_device_parent(dev);
947 if (parent) 953 if (parent)
948 put_device(parent); 954 put_device(parent);
949 goto Done; 955 goto done;
950} 956}
951 957
952/** 958/**
@@ -1009,6 +1015,7 @@ void device_del(struct device *dev)
1009 struct class_interface *class_intf; 1015 struct class_interface *class_intf;
1010 1016
1011 device_pm_remove(dev); 1017 device_pm_remove(dev);
1018 dpm_sysfs_remove(dev);
1012 if (parent) 1019 if (parent)
1013 klist_del(&dev->knode_parent); 1020 klist_del(&dev->knode_parent);
1014 if (MAJOR(dev->devt)) { 1021 if (MAJOR(dev->devt)) {
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 2ef5acf4368b..1e2bda780e48 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -16,9 +16,6 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include "base.h" 17#include "base.h"
18 18
19#define to_dev(node) container_of(node, struct device, driver_list)
20
21
22static struct device *next_device(struct klist_iter *i) 19static struct device *next_device(struct klist_iter *i)
23{ 20{
24 struct klist_node *n = klist_next(i); 21 struct klist_node *n = klist_next(i);
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b0be1d18fee2..c9c92b00fd55 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -184,7 +184,7 @@ firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
184 struct device *dev = to_dev(kobj); 184 struct device *dev = to_dev(kobj);
185 struct firmware_priv *fw_priv = dev_get_drvdata(dev); 185 struct firmware_priv *fw_priv = dev_get_drvdata(dev);
186 struct firmware *fw; 186 struct firmware *fw;
187 ssize_t ret_count = count; 187 ssize_t ret_count;
188 188
189 mutex_lock(&fw_lock); 189 mutex_lock(&fw_lock);
190 fw = fw_priv->fw; 190 fw = fw_priv->fw;
@@ -192,14 +192,8 @@ firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
192 ret_count = -ENODEV; 192 ret_count = -ENODEV;
193 goto out; 193 goto out;
194 } 194 }
195 if (offset > fw->size) { 195 ret_count = memory_read_from_buffer(buffer, count, &offset,
196 ret_count = 0; 196 fw->data, fw->size);
197 goto out;
198 }
199 if (offset + ret_count > fw->size)
200 ret_count = fw->size - offset;
201
202 memcpy(buffer, fw->data + offset, ret_count);
203out: 197out:
204 mutex_unlock(&fw_lock); 198 mutex_unlock(&fw_lock);
205 return ret_count; 199 return ret_count;
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index d2222397a401..efd577574948 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -7,6 +7,7 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/dma-mapping.h>
10#include <linux/isa.h> 11#include <linux/isa.h>
11 12
12static struct device isa_bus = { 13static struct device isa_bus = {
@@ -141,6 +142,9 @@ int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
141 isa_dev->dev.release = isa_dev_release; 142 isa_dev->dev.release = isa_dev_release;
142 isa_dev->id = id; 143 isa_dev->id = id;
143 144
145 isa_dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
146 isa_dev->dev.dma_mask = &isa_dev->dev.coherent_dma_mask;
147
144 error = device_register(&isa_dev->dev); 148 error = device_register(&isa_dev->dev);
145 if (error) { 149 if (error) {
146 put_device(&isa_dev->dev); 150 put_device(&isa_dev->dev);
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 4d4e0e7b6e92..af0d175c025d 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -101,6 +101,22 @@ static ssize_t show_mem_phys_index(struct sys_device *dev,
101} 101}
102 102
103/* 103/*
104 * Show whether the section of memory is likely to be hot-removable
105 */
106static ssize_t show_mem_removable(struct sys_device *dev,
107 struct sysdev_attribute *attr, char *buf)
108{
109 unsigned long start_pfn;
110 int ret;
111 struct memory_block *mem =
112 container_of(dev, struct memory_block, sysdev);
113
114 start_pfn = section_nr_to_pfn(mem->phys_index);
115 ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
116 return sprintf(buf, "%d\n", ret);
117}
118
119/*
104 * online, offline, going offline, etc. 120 * online, offline, going offline, etc.
105 */ 121 */
106static ssize_t show_mem_state(struct sys_device *dev, 122static ssize_t show_mem_state(struct sys_device *dev,
@@ -189,9 +205,8 @@ memory_block_action(struct memory_block *mem, unsigned long action)
189 } 205 }
190 break; 206 break;
191 default: 207 default:
192 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 208 WARN(1, KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
193 __func__, mem, action, action); 209 __func__, mem, action, action);
194 WARN_ON(1);
195 ret = -EINVAL; 210 ret = -EINVAL;
196 } 211 }
197 212
@@ -262,6 +277,7 @@ static ssize_t show_phys_device(struct sys_device *dev,
262static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); 277static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
263static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 278static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
264static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 279static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
280static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
265 281
266#define mem_create_simple_file(mem, attr_name) \ 282#define mem_create_simple_file(mem, attr_name) \
267 sysdev_create_file(&mem->sysdev, &attr_##attr_name) 283 sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -350,6 +366,8 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
350 ret = mem_create_simple_file(mem, state); 366 ret = mem_create_simple_file(mem, state);
351 if (!ret) 367 if (!ret)
352 ret = mem_create_simple_file(mem, phys_device); 368 ret = mem_create_simple_file(mem, phys_device);
369 if (!ret)
370 ret = mem_create_simple_file(mem, removable);
353 371
354 return ret; 372 return ret;
355} 373}
@@ -394,6 +412,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
394 mem_remove_simple_file(mem, phys_index); 412 mem_remove_simple_file(mem, phys_index);
395 mem_remove_simple_file(mem, state); 413 mem_remove_simple_file(mem, state);
396 mem_remove_simple_file(mem, phys_device); 414 mem_remove_simple_file(mem, phys_device);
415 mem_remove_simple_file(mem, removable);
397 unregister_memory(mem, section); 416 unregister_memory(mem, section);
398 417
399 return 0; 418 return 0;
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 3250c5257b74..273a944d4040 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -67,20 +67,16 @@ void device_pm_unlock(void)
67 * device_pm_add - add a device to the list of active devices 67 * device_pm_add - add a device to the list of active devices
68 * @dev: Device to be added to the list 68 * @dev: Device to be added to the list
69 */ 69 */
70int device_pm_add(struct device *dev) 70void device_pm_add(struct device *dev)
71{ 71{
72 int error;
73
74 pr_debug("PM: Adding info for %s:%s\n", 72 pr_debug("PM: Adding info for %s:%s\n",
75 dev->bus ? dev->bus->name : "No Bus", 73 dev->bus ? dev->bus->name : "No Bus",
76 kobject_name(&dev->kobj)); 74 kobject_name(&dev->kobj));
77 mutex_lock(&dpm_list_mtx); 75 mutex_lock(&dpm_list_mtx);
78 if (dev->parent) { 76 if (dev->parent) {
79 if (dev->parent->power.status >= DPM_SUSPENDING) { 77 if (dev->parent->power.status >= DPM_SUSPENDING)
80 dev_warn(dev, "parent %s is sleeping, will not add\n", 78 dev_warn(dev, "parent %s should not be sleeping\n",
81 dev->parent->bus_id); 79 dev->parent->bus_id);
82 WARN_ON(true);
83 }
84 } else if (transition_started) { 80 } else if (transition_started) {
85 /* 81 /*
86 * We refuse to register parentless devices while a PM 82 * We refuse to register parentless devices while a PM
@@ -89,13 +85,9 @@ int device_pm_add(struct device *dev)
89 */ 85 */
90 WARN_ON(true); 86 WARN_ON(true);
91 } 87 }
92 error = dpm_sysfs_add(dev); 88
93 if (!error) { 89 list_add_tail(&dev->power.entry, &dpm_list);
94 dev->power.status = DPM_ON;
95 list_add_tail(&dev->power.entry, &dpm_list);
96 }
97 mutex_unlock(&dpm_list_mtx); 90 mutex_unlock(&dpm_list_mtx);
98 return error;
99} 91}
100 92
101/** 93/**
@@ -110,7 +102,6 @@ void device_pm_remove(struct device *dev)
110 dev->bus ? dev->bus->name : "No Bus", 102 dev->bus ? dev->bus->name : "No Bus",
111 kobject_name(&dev->kobj)); 103 kobject_name(&dev->kobj));
112 mutex_lock(&dpm_list_mtx); 104 mutex_lock(&dpm_list_mtx);
113 dpm_sysfs_remove(dev);
114 list_del_init(&dev->power.entry); 105 list_del_init(&dev->power.entry);
115 mutex_unlock(&dpm_list_mtx); 106 mutex_unlock(&dpm_list_mtx);
116} 107}
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index a3252c0e2887..41f51fae042f 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -1,3 +1,8 @@
1static inline void device_pm_init(struct device *dev)
2{
3 dev->power.status = DPM_ON;
4}
5
1#ifdef CONFIG_PM_SLEEP 6#ifdef CONFIG_PM_SLEEP
2 7
3/* 8/*
@@ -11,12 +16,12 @@ static inline struct device *to_device(struct list_head *entry)
11 return container_of(entry, struct device, power.entry); 16 return container_of(entry, struct device, power.entry);
12} 17}
13 18
14extern int device_pm_add(struct device *); 19extern void device_pm_add(struct device *);
15extern void device_pm_remove(struct device *); 20extern void device_pm_remove(struct device *);
16 21
17#else /* CONFIG_PM_SLEEP */ 22#else /* CONFIG_PM_SLEEP */
18 23
19static inline int device_pm_add(struct device *dev) { return 0; } 24static inline void device_pm_add(struct device *dev) {}
20static inline void device_pm_remove(struct device *dev) {} 25static inline void device_pm_remove(struct device *dev) {}
21 26
22#endif 27#endif
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 40fc14f03540..75dd6e22faff 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -168,19 +168,16 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
168 int err = 0; 168 int err = 0;
169 169
170 if (!cls) { 170 if (!cls) {
171 printk(KERN_WARNING "sysdev: invalid class passed to " 171 WARN(1, KERN_WARNING "sysdev: invalid class passed to "
172 "sysdev_driver_register!\n"); 172 "sysdev_driver_register!\n");
173 WARN_ON(1);
174 return -EINVAL; 173 return -EINVAL;
175 } 174 }
176 175
177 /* Check whether this driver has already been added to a class. */ 176 /* Check whether this driver has already been added to a class. */
178 if (drv->entry.next && !list_empty(&drv->entry)) { 177 if (drv->entry.next && !list_empty(&drv->entry))
179 printk(KERN_WARNING "sysdev: class %s: driver (%p) has already" 178 WARN(1, KERN_WARNING "sysdev: class %s: driver (%p) has already"
180 " been registered to a class, something is wrong, but " 179 " been registered to a class, something is wrong, but "
181 "will forge on!\n", cls->name, drv); 180 "will forge on!\n", cls->name, drv);
182 WARN_ON(1);
183 }
184 181
185 mutex_lock(&sysdev_drivers_lock); 182 mutex_lock(&sysdev_drivers_lock);
186 if (cls && kset_get(&cls->kset)) { 183 if (cls && kset_get(&cls->kset)) {
@@ -194,8 +191,7 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
194 } 191 }
195 } else { 192 } else {
196 err = -EINVAL; 193 err = -EINVAL;
197 printk(KERN_ERR "%s: invalid device class\n", __func__); 194 WARN(1, KERN_ERR "%s: invalid device class\n", __func__);
198 WARN_ON(1);
199 } 195 }
200 mutex_unlock(&sysdev_drivers_lock); 196 mutex_unlock(&sysdev_drivers_lock);
201 return err; 197 return err;