diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/core.c | 34 | ||||
-rw-r--r-- | drivers/base/firmware_class.c | 7 | ||||
-rw-r--r-- | drivers/base/memory.c | 197 | ||||
-rw-r--r-- | drivers/base/node.c | 12 | ||||
-rw-r--r-- | drivers/base/sys.c | 65 | ||||
-rw-r--r-- | drivers/firmware/Kconfig | 11 | ||||
-rw-r--r-- | drivers/firmware/Makefile | 1 | ||||
-rw-r--r-- | drivers/firmware/dmi-sysfs.c | 696 | ||||
-rw-r--r-- | drivers/firmware/efivars.c | 343 | ||||
-rw-r--r-- | drivers/misc/Kconfig | 7 | ||||
-rw-r--r-- | drivers/misc/pch_phub.c | 69 | ||||
-rw-r--r-- | drivers/misc/ti-st/st_core.c | 419 | ||||
-rw-r--r-- | drivers/misc/ti-st/st_kim.c | 491 | ||||
-rw-r--r-- | drivers/misc/ti-st/st_ll.c | 10 | ||||
-rw-r--r-- | drivers/uio/Kconfig | 17 | ||||
-rw-r--r-- | drivers/uio/Makefile | 1 | ||||
-rw-r--r-- | drivers/uio/uio_pruss.c | 247 |
17 files changed, 1858 insertions, 769 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 080e9ca11017..81b78ede37c4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1320,7 +1320,10 @@ struct root_device | |||
1320 | struct module *owner; | 1320 | struct module *owner; |
1321 | }; | 1321 | }; |
1322 | 1322 | ||
1323 | #define to_root_device(dev) container_of(dev, struct root_device, dev) | 1323 | inline struct root_device *to_root_device(struct device *d) |
1324 | { | ||
1325 | return container_of(d, struct root_device, dev); | ||
1326 | } | ||
1324 | 1327 | ||
1325 | static void root_device_release(struct device *dev) | 1328 | static void root_device_release(struct device *dev) |
1326 | { | 1329 | { |
@@ -1551,7 +1554,34 @@ EXPORT_SYMBOL_GPL(device_destroy); | |||
1551 | * on the same device to ensure that new_name is valid and | 1554 | * on the same device to ensure that new_name is valid and |
1552 | * won't conflict with other devices. | 1555 | * won't conflict with other devices. |
1553 | * | 1556 | * |
1554 | * "Never use this function, bad things will happen" - gregkh | 1557 | * Note: Don't call this function. Currently, the networking layer calls this |
1558 | * function, but that will change. The following text from Kay Sievers offers | ||
1559 | * some insight: | ||
1560 | * | ||
1561 | * Renaming devices is racy at many levels, symlinks and other stuff are not | ||
1562 | * replaced atomically, and you get a "move" uevent, but it's not easy to | ||
1563 | * connect the event to the old and new device. Device nodes are not renamed at | ||
1564 | * all, there isn't even support for that in the kernel now. | ||
1565 | * | ||
1566 | * In the meantime, during renaming, your target name might be taken by another | ||
1567 | * driver, creating conflicts. Or the old name is taken directly after you | ||
1568 | * renamed it -- then you get events for the same DEVPATH, before you even see | ||
1569 | * the "move" event. It's just a mess, and nothing new should ever rely on | ||
1570 | * kernel device renaming. Besides that, it's not even implemented now for | ||
1571 | * other things than (driver-core wise very simple) network devices. | ||
1572 | * | ||
1573 | * We are currently about to change network renaming in udev to completely | ||
1574 | * disallow renaming of devices in the same namespace as the kernel uses, | ||
1575 | * because we can't solve the problems properly, that arise with swapping names | ||
1576 | * of multiple interfaces without races. Means, renaming of eth[0-9]* will only | ||
1577 | * be allowed to some other name than eth[0-9]*, for the aforementioned | ||
1578 | * reasons. | ||
1579 | * | ||
1580 | * Make up a "real" name in the driver before you register anything, or add | ||
1581 | * some other attributes for userspace to find the device, or use udev to add | ||
1582 | * symlinks -- but never rename kernel devices later, it's a complete mess. We | ||
1583 | * don't even want to get into that and try to implement the missing pieces in | ||
1584 | * the core. We really have other pieces to fix in the driver core mess. :) | ||
1555 | */ | 1585 | */ |
1556 | int device_rename(struct device *dev, const char *new_name) | 1586 | int device_rename(struct device *dev, const char *new_name) |
1557 | { | 1587 | { |
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 40af43ebd92d..8c798ef7f13f 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -593,8 +593,7 @@ int | |||
593 | request_firmware(const struct firmware **firmware_p, const char *name, | 593 | request_firmware(const struct firmware **firmware_p, const char *name, |
594 | struct device *device) | 594 | struct device *device) |
595 | { | 595 | { |
596 | int uevent = 1; | 596 | return _request_firmware(firmware_p, name, device, true, false); |
597 | return _request_firmware(firmware_p, name, device, uevent, false); | ||
598 | } | 597 | } |
599 | 598 | ||
600 | /** | 599 | /** |
@@ -618,7 +617,7 @@ struct firmware_work { | |||
618 | struct device *device; | 617 | struct device *device; |
619 | void *context; | 618 | void *context; |
620 | void (*cont)(const struct firmware *fw, void *context); | 619 | void (*cont)(const struct firmware *fw, void *context); |
621 | int uevent; | 620 | bool uevent; |
622 | }; | 621 | }; |
623 | 622 | ||
624 | static int request_firmware_work_func(void *arg) | 623 | static int request_firmware_work_func(void *arg) |
@@ -661,7 +660,7 @@ static int request_firmware_work_func(void *arg) | |||
661 | **/ | 660 | **/ |
662 | int | 661 | int |
663 | request_firmware_nowait( | 662 | request_firmware_nowait( |
664 | struct module *module, int uevent, | 663 | struct module *module, bool uevent, |
665 | const char *name, struct device *device, gfp_t gfp, void *context, | 664 | const char *name, struct device *device, gfp_t gfp, void *context, |
666 | void (*cont)(const struct firmware *fw, void *context)) | 665 | void (*cont)(const struct firmware *fw, void *context)) |
667 | { | 666 | { |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index cafeaaf0428f..3da6a43b7756 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -30,6 +30,14 @@ | |||
30 | static DEFINE_MUTEX(mem_sysfs_mutex); | 30 | static DEFINE_MUTEX(mem_sysfs_mutex); |
31 | 31 | ||
32 | #define MEMORY_CLASS_NAME "memory" | 32 | #define MEMORY_CLASS_NAME "memory" |
33 | #define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS) | ||
34 | |||
35 | static int sections_per_block; | ||
36 | |||
37 | static inline int base_memory_block_id(int section_nr) | ||
38 | { | ||
39 | return section_nr / sections_per_block; | ||
40 | } | ||
33 | 41 | ||
34 | static struct sysdev_class memory_sysdev_class = { | 42 | static struct sysdev_class memory_sysdev_class = { |
35 | .name = MEMORY_CLASS_NAME, | 43 | .name = MEMORY_CLASS_NAME, |
@@ -84,39 +92,72 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier); | |||
84 | * register_memory - Setup a sysfs device for a memory block | 92 | * register_memory - Setup a sysfs device for a memory block |
85 | */ | 93 | */ |
86 | static | 94 | static |
87 | int register_memory(struct memory_block *memory, struct mem_section *section) | 95 | int register_memory(struct memory_block *memory) |
88 | { | 96 | { |
89 | int error; | 97 | int error; |
90 | 98 | ||
91 | memory->sysdev.cls = &memory_sysdev_class; | 99 | memory->sysdev.cls = &memory_sysdev_class; |
92 | memory->sysdev.id = __section_nr(section); | 100 | memory->sysdev.id = memory->start_section_nr / sections_per_block; |
93 | 101 | ||
94 | error = sysdev_register(&memory->sysdev); | 102 | error = sysdev_register(&memory->sysdev); |
95 | return error; | 103 | return error; |
96 | } | 104 | } |
97 | 105 | ||
98 | static void | 106 | static void |
99 | unregister_memory(struct memory_block *memory, struct mem_section *section) | 107 | unregister_memory(struct memory_block *memory) |
100 | { | 108 | { |
101 | BUG_ON(memory->sysdev.cls != &memory_sysdev_class); | 109 | BUG_ON(memory->sysdev.cls != &memory_sysdev_class); |
102 | BUG_ON(memory->sysdev.id != __section_nr(section)); | ||
103 | 110 | ||
104 | /* drop the ref. we got in remove_memory_block() */ | 111 | /* drop the ref. we got in remove_memory_block() */ |
105 | kobject_put(&memory->sysdev.kobj); | 112 | kobject_put(&memory->sysdev.kobj); |
106 | sysdev_unregister(&memory->sysdev); | 113 | sysdev_unregister(&memory->sysdev); |
107 | } | 114 | } |
108 | 115 | ||
116 | unsigned long __weak memory_block_size_bytes(void) | ||
117 | { | ||
118 | return MIN_MEMORY_BLOCK_SIZE; | ||
119 | } | ||
120 | |||
121 | static unsigned long get_memory_block_size(void) | ||
122 | { | ||
123 | unsigned long block_sz; | ||
124 | |||
125 | block_sz = memory_block_size_bytes(); | ||
126 | |||
127 | /* Validate blk_sz is a power of 2 and not less than section size */ | ||
128 | if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) { | ||
129 | WARN_ON(1); | ||
130 | block_sz = MIN_MEMORY_BLOCK_SIZE; | ||
131 | } | ||
132 | |||
133 | return block_sz; | ||
134 | } | ||
135 | |||
109 | /* | 136 | /* |
110 | * use this as the physical section index that this memsection | 137 | * use this as the physical section index that this memsection |
111 | * uses. | 138 | * uses. |
112 | */ | 139 | */ |
113 | 140 | ||
114 | static ssize_t show_mem_phys_index(struct sys_device *dev, | 141 | static ssize_t show_mem_start_phys_index(struct sys_device *dev, |
115 | struct sysdev_attribute *attr, char *buf) | 142 | struct sysdev_attribute *attr, char *buf) |
116 | { | 143 | { |
117 | struct memory_block *mem = | 144 | struct memory_block *mem = |
118 | container_of(dev, struct memory_block, sysdev); | 145 | container_of(dev, struct memory_block, sysdev); |
119 | return sprintf(buf, "%08lx\n", mem->phys_index); | 146 | unsigned long phys_index; |
147 | |||
148 | phys_index = mem->start_section_nr / sections_per_block; | ||
149 | return sprintf(buf, "%08lx\n", phys_index); | ||
150 | } | ||
151 | |||
152 | static ssize_t show_mem_end_phys_index(struct sys_device *dev, | ||
153 | struct sysdev_attribute *attr, char *buf) | ||
154 | { | ||
155 | struct memory_block *mem = | ||
156 | container_of(dev, struct memory_block, sysdev); | ||
157 | unsigned long phys_index; | ||
158 | |||
159 | phys_index = mem->end_section_nr / sections_per_block; | ||
160 | return sprintf(buf, "%08lx\n", phys_index); | ||
120 | } | 161 | } |
121 | 162 | ||
122 | /* | 163 | /* |
@@ -125,13 +166,16 @@ static ssize_t show_mem_phys_index(struct sys_device *dev, | |||
125 | static ssize_t show_mem_removable(struct sys_device *dev, | 166 | static ssize_t show_mem_removable(struct sys_device *dev, |
126 | struct sysdev_attribute *attr, char *buf) | 167 | struct sysdev_attribute *attr, char *buf) |
127 | { | 168 | { |
128 | unsigned long start_pfn; | 169 | unsigned long i, pfn; |
129 | int ret; | 170 | int ret = 1; |
130 | struct memory_block *mem = | 171 | struct memory_block *mem = |
131 | container_of(dev, struct memory_block, sysdev); | 172 | container_of(dev, struct memory_block, sysdev); |
132 | 173 | ||
133 | start_pfn = section_nr_to_pfn(mem->phys_index); | 174 | for (i = 0; i < sections_per_block; i++) { |
134 | ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION); | 175 | pfn = section_nr_to_pfn(mem->start_section_nr + i); |
176 | ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION); | ||
177 | } | ||
178 | |||
135 | return sprintf(buf, "%d\n", ret); | 179 | return sprintf(buf, "%d\n", ret); |
136 | } | 180 | } |
137 | 181 | ||
@@ -184,17 +228,14 @@ int memory_isolate_notify(unsigned long val, void *v) | |||
184 | * OK to have direct references to sparsemem variables in here. | 228 | * OK to have direct references to sparsemem variables in here. |
185 | */ | 229 | */ |
186 | static int | 230 | static int |
187 | memory_block_action(struct memory_block *mem, unsigned long action) | 231 | memory_section_action(unsigned long phys_index, unsigned long action) |
188 | { | 232 | { |
189 | int i; | 233 | int i; |
190 | unsigned long psection; | ||
191 | unsigned long start_pfn, start_paddr; | 234 | unsigned long start_pfn, start_paddr; |
192 | struct page *first_page; | 235 | struct page *first_page; |
193 | int ret; | 236 | int ret; |
194 | int old_state = mem->state; | ||
195 | 237 | ||
196 | psection = mem->phys_index; | 238 | first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT); |
197 | first_page = pfn_to_page(psection << PFN_SECTION_SHIFT); | ||
198 | 239 | ||
199 | /* | 240 | /* |
200 | * The probe routines leave the pages reserved, just | 241 | * The probe routines leave the pages reserved, just |
@@ -207,8 +248,8 @@ memory_block_action(struct memory_block *mem, unsigned long action) | |||
207 | continue; | 248 | continue; |
208 | 249 | ||
209 | printk(KERN_WARNING "section number %ld page number %d " | 250 | printk(KERN_WARNING "section number %ld page number %d " |
210 | "not reserved, was it already online? \n", | 251 | "not reserved, was it already online?\n", |
211 | psection, i); | 252 | phys_index, i); |
212 | return -EBUSY; | 253 | return -EBUSY; |
213 | } | 254 | } |
214 | } | 255 | } |
@@ -219,18 +260,13 @@ memory_block_action(struct memory_block *mem, unsigned long action) | |||
219 | ret = online_pages(start_pfn, PAGES_PER_SECTION); | 260 | ret = online_pages(start_pfn, PAGES_PER_SECTION); |
220 | break; | 261 | break; |
221 | case MEM_OFFLINE: | 262 | case MEM_OFFLINE: |
222 | mem->state = MEM_GOING_OFFLINE; | ||
223 | start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; | 263 | start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; |
224 | ret = remove_memory(start_paddr, | 264 | ret = remove_memory(start_paddr, |
225 | PAGES_PER_SECTION << PAGE_SHIFT); | 265 | PAGES_PER_SECTION << PAGE_SHIFT); |
226 | if (ret) { | ||
227 | mem->state = old_state; | ||
228 | break; | ||
229 | } | ||
230 | break; | 266 | break; |
231 | default: | 267 | default: |
232 | WARN(1, KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", | 268 | WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " |
233 | __func__, mem, action, action); | 269 | "%ld\n", __func__, phys_index, action, action); |
234 | ret = -EINVAL; | 270 | ret = -EINVAL; |
235 | } | 271 | } |
236 | 272 | ||
@@ -240,7 +276,8 @@ memory_block_action(struct memory_block *mem, unsigned long action) | |||
240 | static int memory_block_change_state(struct memory_block *mem, | 276 | static int memory_block_change_state(struct memory_block *mem, |
241 | unsigned long to_state, unsigned long from_state_req) | 277 | unsigned long to_state, unsigned long from_state_req) |
242 | { | 278 | { |
243 | int ret = 0; | 279 | int i, ret = 0; |
280 | |||
244 | mutex_lock(&mem->state_mutex); | 281 | mutex_lock(&mem->state_mutex); |
245 | 282 | ||
246 | if (mem->state != from_state_req) { | 283 | if (mem->state != from_state_req) { |
@@ -248,8 +285,23 @@ static int memory_block_change_state(struct memory_block *mem, | |||
248 | goto out; | 285 | goto out; |
249 | } | 286 | } |
250 | 287 | ||
251 | ret = memory_block_action(mem, to_state); | 288 | if (to_state == MEM_OFFLINE) |
252 | if (!ret) | 289 | mem->state = MEM_GOING_OFFLINE; |
290 | |||
291 | for (i = 0; i < sections_per_block; i++) { | ||
292 | ret = memory_section_action(mem->start_section_nr + i, | ||
293 | to_state); | ||
294 | if (ret) | ||
295 | break; | ||
296 | } | ||
297 | |||
298 | if (ret) { | ||
299 | for (i = 0; i < sections_per_block; i++) | ||
300 | memory_section_action(mem->start_section_nr + i, | ||
301 | from_state_req); | ||
302 | |||
303 | mem->state = from_state_req; | ||
304 | } else | ||
253 | mem->state = to_state; | 305 | mem->state = to_state; |
254 | 306 | ||
255 | out: | 307 | out: |
@@ -262,20 +314,15 @@ store_mem_state(struct sys_device *dev, | |||
262 | struct sysdev_attribute *attr, const char *buf, size_t count) | 314 | struct sysdev_attribute *attr, const char *buf, size_t count) |
263 | { | 315 | { |
264 | struct memory_block *mem; | 316 | struct memory_block *mem; |
265 | unsigned int phys_section_nr; | ||
266 | int ret = -EINVAL; | 317 | int ret = -EINVAL; |
267 | 318 | ||
268 | mem = container_of(dev, struct memory_block, sysdev); | 319 | mem = container_of(dev, struct memory_block, sysdev); |
269 | phys_section_nr = mem->phys_index; | ||
270 | |||
271 | if (!present_section_nr(phys_section_nr)) | ||
272 | goto out; | ||
273 | 320 | ||
274 | if (!strncmp(buf, "online", min((int)count, 6))) | 321 | if (!strncmp(buf, "online", min((int)count, 6))) |
275 | ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); | 322 | ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); |
276 | else if(!strncmp(buf, "offline", min((int)count, 7))) | 323 | else if(!strncmp(buf, "offline", min((int)count, 7))) |
277 | ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); | 324 | ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); |
278 | out: | 325 | |
279 | if (ret) | 326 | if (ret) |
280 | return ret; | 327 | return ret; |
281 | return count; | 328 | return count; |
@@ -298,7 +345,8 @@ static ssize_t show_phys_device(struct sys_device *dev, | |||
298 | return sprintf(buf, "%d\n", mem->phys_device); | 345 | return sprintf(buf, "%d\n", mem->phys_device); |
299 | } | 346 | } |
300 | 347 | ||
301 | static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); | 348 | static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); |
349 | static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL); | ||
302 | static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); | 350 | static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); |
303 | static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); | 351 | static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); |
304 | static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); | 352 | static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); |
@@ -315,7 +363,7 @@ static ssize_t | |||
315 | print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, | 363 | print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, |
316 | char *buf) | 364 | char *buf) |
317 | { | 365 | { |
318 | return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); | 366 | return sprintf(buf, "%lx\n", get_memory_block_size()); |
319 | } | 367 | } |
320 | 368 | ||
321 | static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); | 369 | static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); |
@@ -339,12 +387,19 @@ memory_probe_store(struct class *class, struct class_attribute *attr, | |||
339 | { | 387 | { |
340 | u64 phys_addr; | 388 | u64 phys_addr; |
341 | int nid; | 389 | int nid; |
342 | int ret; | 390 | int i, ret; |
343 | 391 | ||
344 | phys_addr = simple_strtoull(buf, NULL, 0); | 392 | phys_addr = simple_strtoull(buf, NULL, 0); |
345 | 393 | ||
346 | nid = memory_add_physaddr_to_nid(phys_addr); | 394 | for (i = 0; i < sections_per_block; i++) { |
347 | ret = add_memory(nid, phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); | 395 | nid = memory_add_physaddr_to_nid(phys_addr); |
396 | ret = add_memory(nid, phys_addr, | ||
397 | PAGES_PER_SECTION << PAGE_SHIFT); | ||
398 | if (ret) | ||
399 | break; | ||
400 | |||
401 | phys_addr += MIN_MEMORY_BLOCK_SIZE; | ||
402 | } | ||
348 | 403 | ||
349 | if (ret) | 404 | if (ret) |
350 | count = ret; | 405 | count = ret; |
@@ -444,6 +499,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section, | |||
444 | struct sys_device *sysdev; | 499 | struct sys_device *sysdev; |
445 | struct memory_block *mem; | 500 | struct memory_block *mem; |
446 | char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; | 501 | char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; |
502 | int block_id = base_memory_block_id(__section_nr(section)); | ||
447 | 503 | ||
448 | kobj = hint ? &hint->sysdev.kobj : NULL; | 504 | kobj = hint ? &hint->sysdev.kobj : NULL; |
449 | 505 | ||
@@ -451,7 +507,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section, | |||
451 | * This only works because we know that section == sysdev->id | 507 | * This only works because we know that section == sysdev->id |
452 | * slightly redundant with sysdev_register() | 508 | * slightly redundant with sysdev_register() |
453 | */ | 509 | */ |
454 | sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section)); | 510 | sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, block_id); |
455 | 511 | ||
456 | kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj); | 512 | kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj); |
457 | if (!kobj) | 513 | if (!kobj) |
@@ -476,36 +532,62 @@ struct memory_block *find_memory_block(struct mem_section *section) | |||
476 | return find_memory_block_hinted(section, NULL); | 532 | return find_memory_block_hinted(section, NULL); |
477 | } | 533 | } |
478 | 534 | ||
479 | static int add_memory_block(int nid, struct mem_section *section, | 535 | static int init_memory_block(struct memory_block **memory, |
480 | unsigned long state, enum mem_add_context context) | 536 | struct mem_section *section, unsigned long state) |
481 | { | 537 | { |
482 | struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); | 538 | struct memory_block *mem; |
483 | unsigned long start_pfn; | 539 | unsigned long start_pfn; |
540 | int scn_nr; | ||
484 | int ret = 0; | 541 | int ret = 0; |
485 | 542 | ||
543 | mem = kzalloc(sizeof(*mem), GFP_KERNEL); | ||
486 | if (!mem) | 544 | if (!mem) |
487 | return -ENOMEM; | 545 | return -ENOMEM; |
488 | 546 | ||
489 | mutex_lock(&mem_sysfs_mutex); | 547 | scn_nr = __section_nr(section); |
490 | 548 | mem->start_section_nr = | |
491 | mem->phys_index = __section_nr(section); | 549 | base_memory_block_id(scn_nr) * sections_per_block; |
550 | mem->end_section_nr = mem->start_section_nr + sections_per_block - 1; | ||
492 | mem->state = state; | 551 | mem->state = state; |
493 | mem->section_count++; | 552 | mem->section_count++; |
494 | mutex_init(&mem->state_mutex); | 553 | mutex_init(&mem->state_mutex); |
495 | start_pfn = section_nr_to_pfn(mem->phys_index); | 554 | start_pfn = section_nr_to_pfn(mem->start_section_nr); |
496 | mem->phys_device = arch_get_memory_phys_device(start_pfn); | 555 | mem->phys_device = arch_get_memory_phys_device(start_pfn); |
497 | 556 | ||
498 | ret = register_memory(mem, section); | 557 | ret = register_memory(mem); |
499 | if (!ret) | 558 | if (!ret) |
500 | ret = mem_create_simple_file(mem, phys_index); | 559 | ret = mem_create_simple_file(mem, phys_index); |
501 | if (!ret) | 560 | if (!ret) |
561 | ret = mem_create_simple_file(mem, end_phys_index); | ||
562 | if (!ret) | ||
502 | ret = mem_create_simple_file(mem, state); | 563 | ret = mem_create_simple_file(mem, state); |
503 | if (!ret) | 564 | if (!ret) |
504 | ret = mem_create_simple_file(mem, phys_device); | 565 | ret = mem_create_simple_file(mem, phys_device); |
505 | if (!ret) | 566 | if (!ret) |
506 | ret = mem_create_simple_file(mem, removable); | 567 | ret = mem_create_simple_file(mem, removable); |
568 | |||
569 | *memory = mem; | ||
570 | return ret; | ||
571 | } | ||
572 | |||
573 | static int add_memory_section(int nid, struct mem_section *section, | ||
574 | unsigned long state, enum mem_add_context context) | ||
575 | { | ||
576 | struct memory_block *mem; | ||
577 | int ret = 0; | ||
578 | |||
579 | mutex_lock(&mem_sysfs_mutex); | ||
580 | |||
581 | mem = find_memory_block(section); | ||
582 | if (mem) { | ||
583 | mem->section_count++; | ||
584 | kobject_put(&mem->sysdev.kobj); | ||
585 | } else | ||
586 | ret = init_memory_block(&mem, section, state); | ||
587 | |||
507 | if (!ret) { | 588 | if (!ret) { |
508 | if (context == HOTPLUG) | 589 | if (context == HOTPLUG && |
590 | mem->section_count == sections_per_block) | ||
509 | ret = register_mem_sect_under_node(mem, nid); | 591 | ret = register_mem_sect_under_node(mem, nid); |
510 | } | 592 | } |
511 | 593 | ||
@@ -520,16 +602,19 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, | |||
520 | 602 | ||
521 | mutex_lock(&mem_sysfs_mutex); | 603 | mutex_lock(&mem_sysfs_mutex); |
522 | mem = find_memory_block(section); | 604 | mem = find_memory_block(section); |
605 | unregister_mem_sect_under_nodes(mem, __section_nr(section)); | ||
523 | 606 | ||
524 | mem->section_count--; | 607 | mem->section_count--; |
525 | if (mem->section_count == 0) { | 608 | if (mem->section_count == 0) { |
526 | unregister_mem_sect_under_nodes(mem); | ||
527 | mem_remove_simple_file(mem, phys_index); | 609 | mem_remove_simple_file(mem, phys_index); |
610 | mem_remove_simple_file(mem, end_phys_index); | ||
528 | mem_remove_simple_file(mem, state); | 611 | mem_remove_simple_file(mem, state); |
529 | mem_remove_simple_file(mem, phys_device); | 612 | mem_remove_simple_file(mem, phys_device); |
530 | mem_remove_simple_file(mem, removable); | 613 | mem_remove_simple_file(mem, removable); |
531 | unregister_memory(mem, section); | 614 | unregister_memory(mem); |
532 | } | 615 | kfree(mem); |
616 | } else | ||
617 | kobject_put(&mem->sysdev.kobj); | ||
533 | 618 | ||
534 | mutex_unlock(&mem_sysfs_mutex); | 619 | mutex_unlock(&mem_sysfs_mutex); |
535 | return 0; | 620 | return 0; |
@@ -541,7 +626,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, | |||
541 | */ | 626 | */ |
542 | int register_new_memory(int nid, struct mem_section *section) | 627 | int register_new_memory(int nid, struct mem_section *section) |
543 | { | 628 | { |
544 | return add_memory_block(nid, section, MEM_OFFLINE, HOTPLUG); | 629 | return add_memory_section(nid, section, MEM_OFFLINE, HOTPLUG); |
545 | } | 630 | } |
546 | 631 | ||
547 | int unregister_memory_section(struct mem_section *section) | 632 | int unregister_memory_section(struct mem_section *section) |
@@ -560,12 +645,16 @@ int __init memory_dev_init(void) | |||
560 | unsigned int i; | 645 | unsigned int i; |
561 | int ret; | 646 | int ret; |
562 | int err; | 647 | int err; |
648 | unsigned long block_sz; | ||
563 | 649 | ||
564 | memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; | 650 | memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; |
565 | ret = sysdev_class_register(&memory_sysdev_class); | 651 | ret = sysdev_class_register(&memory_sysdev_class); |
566 | if (ret) | 652 | if (ret) |
567 | goto out; | 653 | goto out; |
568 | 654 | ||
655 | block_sz = get_memory_block_size(); | ||
656 | sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE; | ||
657 | |||
569 | /* | 658 | /* |
570 | * Create entries for memory sections that were found | 659 | * Create entries for memory sections that were found |
571 | * during boot and have been initialized | 660 | * during boot and have been initialized |
@@ -573,8 +662,8 @@ int __init memory_dev_init(void) | |||
573 | for (i = 0; i < NR_MEM_SECTIONS; i++) { | 662 | for (i = 0; i < NR_MEM_SECTIONS; i++) { |
574 | if (!present_section_nr(i)) | 663 | if (!present_section_nr(i)) |
575 | continue; | 664 | continue; |
576 | err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, | 665 | err = add_memory_section(0, __nr_to_section(i), MEM_ONLINE, |
577 | BOOT); | 666 | BOOT); |
578 | if (!ret) | 667 | if (!ret) |
579 | ret = err; | 668 | ret = err; |
580 | } | 669 | } |
diff --git a/drivers/base/node.c b/drivers/base/node.c index 36b43052001d..b3b72d64e805 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
@@ -375,8 +375,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid) | |||
375 | return -EFAULT; | 375 | return -EFAULT; |
376 | if (!node_online(nid)) | 376 | if (!node_online(nid)) |
377 | return 0; | 377 | return 0; |
378 | sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); | 378 | |
379 | sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; | 379 | sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr); |
380 | sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr); | ||
381 | sect_end_pfn += PAGES_PER_SECTION - 1; | ||
380 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { | 382 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { |
381 | int page_nid; | 383 | int page_nid; |
382 | 384 | ||
@@ -400,7 +402,8 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid) | |||
400 | } | 402 | } |
401 | 403 | ||
402 | /* unregister memory section under all nodes that it spans */ | 404 | /* unregister memory section under all nodes that it spans */ |
403 | int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) | 405 | int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
406 | unsigned long phys_index) | ||
404 | { | 407 | { |
405 | NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); | 408 | NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); |
406 | unsigned long pfn, sect_start_pfn, sect_end_pfn; | 409 | unsigned long pfn, sect_start_pfn, sect_end_pfn; |
@@ -412,7 +415,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) | |||
412 | if (!unlinked_nodes) | 415 | if (!unlinked_nodes) |
413 | return -ENOMEM; | 416 | return -ENOMEM; |
414 | nodes_clear(*unlinked_nodes); | 417 | nodes_clear(*unlinked_nodes); |
415 | sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); | 418 | |
419 | sect_start_pfn = section_nr_to_pfn(phys_index); | ||
416 | sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; | 420 | sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; |
417 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { | 421 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { |
418 | int nid; | 422 | int nid; |
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 1667aaf4fde6..f6fb54741602 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -166,6 +166,36 @@ EXPORT_SYMBOL_GPL(sysdev_class_unregister); | |||
166 | 166 | ||
167 | static DEFINE_MUTEX(sysdev_drivers_lock); | 167 | static DEFINE_MUTEX(sysdev_drivers_lock); |
168 | 168 | ||
169 | /* | ||
170 | * @dev != NULL means that we're unwinding because some drv->add() | ||
171 | * failed for some reason. You need to grab sysdev_drivers_lock before | ||
172 | * calling this. | ||
173 | */ | ||
174 | static void __sysdev_driver_remove(struct sysdev_class *cls, | ||
175 | struct sysdev_driver *drv, | ||
176 | struct sys_device *from_dev) | ||
177 | { | ||
178 | struct sys_device *dev = from_dev; | ||
179 | |||
180 | list_del_init(&drv->entry); | ||
181 | if (!cls) | ||
182 | return; | ||
183 | |||
184 | if (!drv->remove) | ||
185 | goto kset_put; | ||
186 | |||
187 | if (dev) | ||
188 | list_for_each_entry_continue_reverse(dev, &cls->kset.list, | ||
189 | kobj.entry) | ||
190 | drv->remove(dev); | ||
191 | else | ||
192 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) | ||
193 | drv->remove(dev); | ||
194 | |||
195 | kset_put: | ||
196 | kset_put(&cls->kset); | ||
197 | } | ||
198 | |||
169 | /** | 199 | /** |
170 | * sysdev_driver_register - Register auxillary driver | 200 | * sysdev_driver_register - Register auxillary driver |
171 | * @cls: Device class driver belongs to. | 201 | * @cls: Device class driver belongs to. |
@@ -175,14 +205,14 @@ static DEFINE_MUTEX(sysdev_drivers_lock); | |||
175 | * called on each operation on devices of that class. The refcount | 205 | * called on each operation on devices of that class. The refcount |
176 | * of @cls is incremented. | 206 | * of @cls is incremented. |
177 | */ | 207 | */ |
178 | |||
179 | int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) | 208 | int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) |
180 | { | 209 | { |
210 | struct sys_device *dev = NULL; | ||
181 | int err = 0; | 211 | int err = 0; |
182 | 212 | ||
183 | if (!cls) { | 213 | if (!cls) { |
184 | WARN(1, KERN_WARNING "sysdev: invalid class passed to " | 214 | WARN(1, KERN_WARNING "sysdev: invalid class passed to %s!\n", |
185 | "sysdev_driver_register!\n"); | 215 | __func__); |
186 | return -EINVAL; | 216 | return -EINVAL; |
187 | } | 217 | } |
188 | 218 | ||
@@ -198,19 +228,27 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) | |||
198 | 228 | ||
199 | /* If devices of this class already exist, tell the driver */ | 229 | /* If devices of this class already exist, tell the driver */ |
200 | if (drv->add) { | 230 | if (drv->add) { |
201 | struct sys_device *dev; | 231 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) { |
202 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) | 232 | err = drv->add(dev); |
203 | drv->add(dev); | 233 | if (err) |
234 | goto unwind; | ||
235 | } | ||
204 | } | 236 | } |
205 | } else { | 237 | } else { |
206 | err = -EINVAL; | 238 | err = -EINVAL; |
207 | WARN(1, KERN_ERR "%s: invalid device class\n", __func__); | 239 | WARN(1, KERN_ERR "%s: invalid device class\n", __func__); |
208 | } | 240 | } |
241 | |||
242 | goto unlock; | ||
243 | |||
244 | unwind: | ||
245 | __sysdev_driver_remove(cls, drv, dev); | ||
246 | |||
247 | unlock: | ||
209 | mutex_unlock(&sysdev_drivers_lock); | 248 | mutex_unlock(&sysdev_drivers_lock); |
210 | return err; | 249 | return err; |
211 | } | 250 | } |
212 | 251 | ||
213 | |||
214 | /** | 252 | /** |
215 | * sysdev_driver_unregister - Remove an auxillary driver. | 253 | * sysdev_driver_unregister - Remove an auxillary driver. |
216 | * @cls: Class driver belongs to. | 254 | * @cls: Class driver belongs to. |
@@ -220,23 +258,12 @@ void sysdev_driver_unregister(struct sysdev_class *cls, | |||
220 | struct sysdev_driver *drv) | 258 | struct sysdev_driver *drv) |
221 | { | 259 | { |
222 | mutex_lock(&sysdev_drivers_lock); | 260 | mutex_lock(&sysdev_drivers_lock); |
223 | list_del_init(&drv->entry); | 261 | __sysdev_driver_remove(cls, drv, NULL); |
224 | if (cls) { | ||
225 | if (drv->remove) { | ||
226 | struct sys_device *dev; | ||
227 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) | ||
228 | drv->remove(dev); | ||
229 | } | ||
230 | kset_put(&cls->kset); | ||
231 | } | ||
232 | mutex_unlock(&sysdev_drivers_lock); | 262 | mutex_unlock(&sysdev_drivers_lock); |
233 | } | 263 | } |
234 | |||
235 | EXPORT_SYMBOL_GPL(sysdev_driver_register); | 264 | EXPORT_SYMBOL_GPL(sysdev_driver_register); |
236 | EXPORT_SYMBOL_GPL(sysdev_driver_unregister); | 265 | EXPORT_SYMBOL_GPL(sysdev_driver_unregister); |
237 | 266 | ||
238 | |||
239 | |||
240 | /** | 267 | /** |
241 | * sysdev_register - add a system device to the tree | 268 | * sysdev_register - add a system device to the tree |
242 | * @sysdev: device in question | 269 | * @sysdev: device in question |
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index e710424b59ea..3c56afc5eb1b 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig | |||
@@ -113,6 +113,17 @@ config DMIID | |||
113 | information from userspace through /sys/class/dmi/id/ or if you want | 113 | information from userspace through /sys/class/dmi/id/ or if you want |
114 | DMI-based module auto-loading. | 114 | DMI-based module auto-loading. |
115 | 115 | ||
116 | config DMI_SYSFS | ||
117 | tristate "DMI table support in sysfs" | ||
118 | depends on SYSFS && DMI | ||
119 | default n | ||
120 | help | ||
121 | Say Y or M here to enable the exporting of the raw DMI table | ||
122 | data via sysfs. This is useful for consuming the data without | ||
123 | requiring any access to /dev/mem at all. Tables are found | ||
124 | under /sys/firmware/dmi when this option is enabled and | ||
125 | loaded. | ||
126 | |||
116 | config ISCSI_IBFT_FIND | 127 | config ISCSI_IBFT_FIND |
117 | bool "iSCSI Boot Firmware Table Attributes" | 128 | bool "iSCSI Boot Firmware Table Attributes" |
118 | depends on X86 | 129 | depends on X86 |
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 1c3c17343dbe..20c17fca1232 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile | |||
@@ -2,6 +2,7 @@ | |||
2 | # Makefile for the linux kernel. | 2 | # Makefile for the linux kernel. |
3 | # | 3 | # |
4 | obj-$(CONFIG_DMI) += dmi_scan.o | 4 | obj-$(CONFIG_DMI) += dmi_scan.o |
5 | obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o | ||
5 | obj-$(CONFIG_EDD) += edd.o | 6 | obj-$(CONFIG_EDD) += edd.o |
6 | obj-$(CONFIG_EFI_VARS) += efivars.o | 7 | obj-$(CONFIG_EFI_VARS) += efivars.o |
7 | obj-$(CONFIG_EFI_PCDP) += pcdp.o | 8 | obj-$(CONFIG_EFI_PCDP) += pcdp.o |
diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c new file mode 100644 index 000000000000..eb26d62e5188 --- /dev/null +++ b/drivers/firmware/dmi-sysfs.c | |||
@@ -0,0 +1,696 @@ | |||
1 | /* | ||
2 | * dmi-sysfs.c | ||
3 | * | ||
4 | * This module exports the DMI tables read-only to userspace through the | ||
5 | * sysfs file system. | ||
6 | * | ||
7 | * Data is currently found below | ||
8 | * /sys/firmware/dmi/... | ||
9 | * | ||
10 | * DMI attributes are presented in attribute files with names | ||
11 | * formatted using %d-%d, so that the first integer indicates the | ||
12 | * structure type (0-255), and the second field is the instance of that | ||
13 | * entry. | ||
14 | * | ||
15 | * Copyright 2011 Google, Inc. | ||
16 | */ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/kobject.h> | ||
23 | #include <linux/dmi.h> | ||
24 | #include <linux/capability.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/list.h> | ||
27 | #include <linux/io.h> | ||
28 | |||
29 | #define MAX_ENTRY_TYPE 255 /* Most of these aren't used, but we consider | ||
30 | the top entry type is only 8 bits */ | ||
31 | |||
32 | struct dmi_sysfs_entry { | ||
33 | struct dmi_header dh; | ||
34 | struct kobject kobj; | ||
35 | int instance; | ||
36 | int position; | ||
37 | struct list_head list; | ||
38 | struct kobject *child; | ||
39 | }; | ||
40 | |||
41 | /* | ||
42 | * Global list of dmi_sysfs_entry. Even though this should only be | ||
43 | * manipulated at setup and teardown, the lazy nature of the kobject | ||
44 | * system means we get lazy removes. | ||
45 | */ | ||
46 | static LIST_HEAD(entry_list); | ||
47 | static DEFINE_SPINLOCK(entry_list_lock); | ||
48 | |||
49 | /* dmi_sysfs_attribute - Top level attribute. used by all entries. */ | ||
50 | struct dmi_sysfs_attribute { | ||
51 | struct attribute attr; | ||
52 | ssize_t (*show)(struct dmi_sysfs_entry *entry, char *buf); | ||
53 | }; | ||
54 | |||
55 | #define DMI_SYSFS_ATTR(_entry, _name) \ | ||
56 | struct dmi_sysfs_attribute dmi_sysfs_attr_##_entry##_##_name = { \ | ||
57 | .attr = {.name = __stringify(_name), .mode = 0400}, \ | ||
58 | .show = dmi_sysfs_##_entry##_##_name, \ | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * dmi_sysfs_mapped_attribute - Attribute where we require the entry be | ||
63 | * mapped in. Use in conjunction with dmi_sysfs_specialize_attr_ops. | ||
64 | */ | ||
65 | struct dmi_sysfs_mapped_attribute { | ||
66 | struct attribute attr; | ||
67 | ssize_t (*show)(struct dmi_sysfs_entry *entry, | ||
68 | const struct dmi_header *dh, | ||
69 | char *buf); | ||
70 | }; | ||
71 | |||
72 | #define DMI_SYSFS_MAPPED_ATTR(_entry, _name) \ | ||
73 | struct dmi_sysfs_mapped_attribute dmi_sysfs_attr_##_entry##_##_name = { \ | ||
74 | .attr = {.name = __stringify(_name), .mode = 0400}, \ | ||
75 | .show = dmi_sysfs_##_entry##_##_name, \ | ||
76 | } | ||
77 | |||
78 | /************************************************* | ||
79 | * Generic DMI entry support. | ||
80 | *************************************************/ | ||
81 | static void dmi_entry_free(struct kobject *kobj) | ||
82 | { | ||
83 | kfree(kobj); | ||
84 | } | ||
85 | |||
86 | static struct dmi_sysfs_entry *to_entry(struct kobject *kobj) | ||
87 | { | ||
88 | return container_of(kobj, struct dmi_sysfs_entry, kobj); | ||
89 | } | ||
90 | |||
91 | static struct dmi_sysfs_attribute *to_attr(struct attribute *attr) | ||
92 | { | ||
93 | return container_of(attr, struct dmi_sysfs_attribute, attr); | ||
94 | } | ||
95 | |||
96 | static ssize_t dmi_sysfs_attr_show(struct kobject *kobj, | ||
97 | struct attribute *_attr, char *buf) | ||
98 | { | ||
99 | struct dmi_sysfs_entry *entry = to_entry(kobj); | ||
100 | struct dmi_sysfs_attribute *attr = to_attr(_attr); | ||
101 | |||
102 | /* DMI stuff is only ever admin visible */ | ||
103 | if (!capable(CAP_SYS_ADMIN)) | ||
104 | return -EACCES; | ||
105 | |||
106 | return attr->show(entry, buf); | ||
107 | } | ||
108 | |||
109 | static const struct sysfs_ops dmi_sysfs_attr_ops = { | ||
110 | .show = dmi_sysfs_attr_show, | ||
111 | }; | ||
112 | |||
113 | typedef ssize_t (*dmi_callback)(struct dmi_sysfs_entry *, | ||
114 | const struct dmi_header *dh, void *); | ||
115 | |||
116 | struct find_dmi_data { | ||
117 | struct dmi_sysfs_entry *entry; | ||
118 | dmi_callback callback; | ||
119 | void *private; | ||
120 | int instance_countdown; | ||
121 | ssize_t ret; | ||
122 | }; | ||
123 | |||
124 | static void find_dmi_entry_helper(const struct dmi_header *dh, | ||
125 | void *_data) | ||
126 | { | ||
127 | struct find_dmi_data *data = _data; | ||
128 | struct dmi_sysfs_entry *entry = data->entry; | ||
129 | |||
130 | /* Is this the entry we want? */ | ||
131 | if (dh->type != entry->dh.type) | ||
132 | return; | ||
133 | |||
134 | if (data->instance_countdown != 0) { | ||
135 | /* try the next instance? */ | ||
136 | data->instance_countdown--; | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * Don't ever revisit the instance. Short circuit later | ||
142 | * instances by letting the instance_countdown run negative | ||
143 | */ | ||
144 | data->instance_countdown--; | ||
145 | |||
146 | /* Found the entry */ | ||
147 | data->ret = data->callback(entry, dh, data->private); | ||
148 | } | ||
149 | |||
150 | /* State for passing the read parameters through dmi_find_entry() */ | ||
151 | struct dmi_read_state { | ||
152 | char *buf; | ||
153 | loff_t pos; | ||
154 | size_t count; | ||
155 | }; | ||
156 | |||
157 | static ssize_t find_dmi_entry(struct dmi_sysfs_entry *entry, | ||
158 | dmi_callback callback, void *private) | ||
159 | { | ||
160 | struct find_dmi_data data = { | ||
161 | .entry = entry, | ||
162 | .callback = callback, | ||
163 | .private = private, | ||
164 | .instance_countdown = entry->instance, | ||
165 | .ret = -EIO, /* To signal the entry disappeared */ | ||
166 | }; | ||
167 | int ret; | ||
168 | |||
169 | ret = dmi_walk(find_dmi_entry_helper, &data); | ||
170 | /* This shouldn't happen, but just in case. */ | ||
171 | if (ret) | ||
172 | return -EINVAL; | ||
173 | return data.ret; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * Calculate and return the byte length of the dmi entry identified by | ||
178 | * dh. This includes both the formatted portion as well as the | ||
179 | * unformatted string space, including the two trailing nul characters. | ||
180 | */ | ||
181 | static size_t dmi_entry_length(const struct dmi_header *dh) | ||
182 | { | ||
183 | const char *p = (const char *)dh; | ||
184 | |||
185 | p += dh->length; | ||
186 | |||
187 | while (p[0] || p[1]) | ||
188 | p++; | ||
189 | |||
190 | return 2 + p - (const char *)dh; | ||
191 | } | ||
192 | |||
193 | /************************************************* | ||
194 | * Support bits for specialized DMI entry support | ||
195 | *************************************************/ | ||
196 | struct dmi_entry_attr_show_data { | ||
197 | struct attribute *attr; | ||
198 | char *buf; | ||
199 | }; | ||
200 | |||
201 | static ssize_t dmi_entry_attr_show_helper(struct dmi_sysfs_entry *entry, | ||
202 | const struct dmi_header *dh, | ||
203 | void *_data) | ||
204 | { | ||
205 | struct dmi_entry_attr_show_data *data = _data; | ||
206 | struct dmi_sysfs_mapped_attribute *attr; | ||
207 | |||
208 | attr = container_of(data->attr, | ||
209 | struct dmi_sysfs_mapped_attribute, attr); | ||
210 | return attr->show(entry, dh, data->buf); | ||
211 | } | ||
212 | |||
213 | static ssize_t dmi_entry_attr_show(struct kobject *kobj, | ||
214 | struct attribute *attr, | ||
215 | char *buf) | ||
216 | { | ||
217 | struct dmi_entry_attr_show_data data = { | ||
218 | .attr = attr, | ||
219 | .buf = buf, | ||
220 | }; | ||
221 | /* Find the entry according to our parent and call the | ||
222 | * normalized show method hanging off of the attribute */ | ||
223 | return find_dmi_entry(to_entry(kobj->parent), | ||
224 | dmi_entry_attr_show_helper, &data); | ||
225 | } | ||
226 | |||
227 | static const struct sysfs_ops dmi_sysfs_specialize_attr_ops = { | ||
228 | .show = dmi_entry_attr_show, | ||
229 | }; | ||
230 | |||
231 | /************************************************* | ||
232 | * Specialized DMI entry support. | ||
233 | *************************************************/ | ||
234 | |||
235 | /*** Type 15 - System Event Table ***/ | ||
236 | |||
237 | #define DMI_SEL_ACCESS_METHOD_IO8 0x00 | ||
238 | #define DMI_SEL_ACCESS_METHOD_IO2x8 0x01 | ||
239 | #define DMI_SEL_ACCESS_METHOD_IO16 0x02 | ||
240 | #define DMI_SEL_ACCESS_METHOD_PHYS32 0x03 | ||
241 | #define DMI_SEL_ACCESS_METHOD_GPNV 0x04 | ||
242 | |||
243 | struct dmi_system_event_log { | ||
244 | struct dmi_header header; | ||
245 | u16 area_length; | ||
246 | u16 header_start_offset; | ||
247 | u16 data_start_offset; | ||
248 | u8 access_method; | ||
249 | u8 status; | ||
250 | u32 change_token; | ||
251 | union { | ||
252 | struct { | ||
253 | u16 index_addr; | ||
254 | u16 data_addr; | ||
255 | } io; | ||
256 | u32 phys_addr32; | ||
257 | u16 gpnv_handle; | ||
258 | u32 access_method_address; | ||
259 | }; | ||
260 | u8 header_format; | ||
261 | u8 type_descriptors_supported_count; | ||
262 | u8 per_log_type_descriptor_length; | ||
263 | u8 supported_log_type_descriptos[0]; | ||
264 | } __packed; | ||
265 | |||
266 | #define DMI_SYSFS_SEL_FIELD(_field) \ | ||
267 | static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \ | ||
268 | const struct dmi_header *dh, \ | ||
269 | char *buf) \ | ||
270 | { \ | ||
271 | struct dmi_system_event_log sel; \ | ||
272 | if (sizeof(sel) > dmi_entry_length(dh)) \ | ||
273 | return -EIO; \ | ||
274 | memcpy(&sel, dh, sizeof(sel)); \ | ||
275 | return sprintf(buf, "%u\n", sel._field); \ | ||
276 | } \ | ||
277 | static DMI_SYSFS_MAPPED_ATTR(sel, _field) | ||
278 | |||
279 | DMI_SYSFS_SEL_FIELD(area_length); | ||
280 | DMI_SYSFS_SEL_FIELD(header_start_offset); | ||
281 | DMI_SYSFS_SEL_FIELD(data_start_offset); | ||
282 | DMI_SYSFS_SEL_FIELD(access_method); | ||
283 | DMI_SYSFS_SEL_FIELD(status); | ||
284 | DMI_SYSFS_SEL_FIELD(change_token); | ||
285 | DMI_SYSFS_SEL_FIELD(access_method_address); | ||
286 | DMI_SYSFS_SEL_FIELD(header_format); | ||
287 | DMI_SYSFS_SEL_FIELD(type_descriptors_supported_count); | ||
288 | DMI_SYSFS_SEL_FIELD(per_log_type_descriptor_length); | ||
289 | |||
290 | static struct attribute *dmi_sysfs_sel_attrs[] = { | ||
291 | &dmi_sysfs_attr_sel_area_length.attr, | ||
292 | &dmi_sysfs_attr_sel_header_start_offset.attr, | ||
293 | &dmi_sysfs_attr_sel_data_start_offset.attr, | ||
294 | &dmi_sysfs_attr_sel_access_method.attr, | ||
295 | &dmi_sysfs_attr_sel_status.attr, | ||
296 | &dmi_sysfs_attr_sel_change_token.attr, | ||
297 | &dmi_sysfs_attr_sel_access_method_address.attr, | ||
298 | &dmi_sysfs_attr_sel_header_format.attr, | ||
299 | &dmi_sysfs_attr_sel_type_descriptors_supported_count.attr, | ||
300 | &dmi_sysfs_attr_sel_per_log_type_descriptor_length.attr, | ||
301 | NULL, | ||
302 | }; | ||
303 | |||
304 | |||
305 | static struct kobj_type dmi_system_event_log_ktype = { | ||
306 | .release = dmi_entry_free, | ||
307 | .sysfs_ops = &dmi_sysfs_specialize_attr_ops, | ||
308 | .default_attrs = dmi_sysfs_sel_attrs, | ||
309 | }; | ||
310 | |||
311 | typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel, | ||
312 | loff_t offset); | ||
313 | |||
314 | static DEFINE_MUTEX(io_port_lock); | ||
315 | |||
316 | static u8 read_sel_8bit_indexed_io(const struct dmi_system_event_log *sel, | ||
317 | loff_t offset) | ||
318 | { | ||
319 | u8 ret; | ||
320 | |||
321 | mutex_lock(&io_port_lock); | ||
322 | outb((u8)offset, sel->io.index_addr); | ||
323 | ret = inb(sel->io.data_addr); | ||
324 | mutex_unlock(&io_port_lock); | ||
325 | return ret; | ||
326 | } | ||
327 | |||
328 | static u8 read_sel_2x8bit_indexed_io(const struct dmi_system_event_log *sel, | ||
329 | loff_t offset) | ||
330 | { | ||
331 | u8 ret; | ||
332 | |||
333 | mutex_lock(&io_port_lock); | ||
334 | outb((u8)offset, sel->io.index_addr); | ||
335 | outb((u8)(offset >> 8), sel->io.index_addr + 1); | ||
336 | ret = inb(sel->io.data_addr); | ||
337 | mutex_unlock(&io_port_lock); | ||
338 | return ret; | ||
339 | } | ||
340 | |||
341 | static u8 read_sel_16bit_indexed_io(const struct dmi_system_event_log *sel, | ||
342 | loff_t offset) | ||
343 | { | ||
344 | u8 ret; | ||
345 | |||
346 | mutex_lock(&io_port_lock); | ||
347 | outw((u16)offset, sel->io.index_addr); | ||
348 | ret = inb(sel->io.data_addr); | ||
349 | mutex_unlock(&io_port_lock); | ||
350 | return ret; | ||
351 | } | ||
352 | |||
353 | static sel_io_reader sel_io_readers[] = { | ||
354 | [DMI_SEL_ACCESS_METHOD_IO8] = read_sel_8bit_indexed_io, | ||
355 | [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io, | ||
356 | [DMI_SEL_ACCESS_METHOD_IO16] = read_sel_16bit_indexed_io, | ||
357 | }; | ||
358 | |||
359 | static ssize_t dmi_sel_raw_read_io(struct dmi_sysfs_entry *entry, | ||
360 | const struct dmi_system_event_log *sel, | ||
361 | char *buf, loff_t pos, size_t count) | ||
362 | { | ||
363 | ssize_t wrote = 0; | ||
364 | |||
365 | sel_io_reader io_reader = sel_io_readers[sel->access_method]; | ||
366 | |||
367 | while (count && pos < sel->area_length) { | ||
368 | count--; | ||
369 | *(buf++) = io_reader(sel, pos++); | ||
370 | wrote++; | ||
371 | } | ||
372 | |||
373 | return wrote; | ||
374 | } | ||
375 | |||
376 | static ssize_t dmi_sel_raw_read_phys32(struct dmi_sysfs_entry *entry, | ||
377 | const struct dmi_system_event_log *sel, | ||
378 | char *buf, loff_t pos, size_t count) | ||
379 | { | ||
380 | u8 __iomem *mapped; | ||
381 | ssize_t wrote = 0; | ||
382 | |||
383 | mapped = ioremap(sel->access_method_address, sel->area_length); | ||
384 | if (!mapped) | ||
385 | return -EIO; | ||
386 | |||
387 | while (count && pos < sel->area_length) { | ||
388 | count--; | ||
389 | *(buf++) = readb(mapped + pos++); | ||
390 | wrote++; | ||
391 | } | ||
392 | |||
393 | iounmap(mapped); | ||
394 | return wrote; | ||
395 | } | ||
396 | |||
397 | static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry, | ||
398 | const struct dmi_header *dh, | ||
399 | void *_state) | ||
400 | { | ||
401 | struct dmi_read_state *state = _state; | ||
402 | struct dmi_system_event_log sel; | ||
403 | |||
404 | if (sizeof(sel) > dmi_entry_length(dh)) | ||
405 | return -EIO; | ||
406 | |||
407 | memcpy(&sel, dh, sizeof(sel)); | ||
408 | |||
409 | switch (sel.access_method) { | ||
410 | case DMI_SEL_ACCESS_METHOD_IO8: | ||
411 | case DMI_SEL_ACCESS_METHOD_IO2x8: | ||
412 | case DMI_SEL_ACCESS_METHOD_IO16: | ||
413 | return dmi_sel_raw_read_io(entry, &sel, state->buf, | ||
414 | state->pos, state->count); | ||
415 | case DMI_SEL_ACCESS_METHOD_PHYS32: | ||
416 | return dmi_sel_raw_read_phys32(entry, &sel, state->buf, | ||
417 | state->pos, state->count); | ||
418 | case DMI_SEL_ACCESS_METHOD_GPNV: | ||
419 | pr_info("dmi-sysfs: GPNV support missing.\n"); | ||
420 | return -EIO; | ||
421 | default: | ||
422 | pr_info("dmi-sysfs: Unknown access method %02x\n", | ||
423 | sel.access_method); | ||
424 | return -EIO; | ||
425 | } | ||
426 | } | ||
427 | |||
428 | static ssize_t dmi_sel_raw_read(struct file *filp, struct kobject *kobj, | ||
429 | struct bin_attribute *bin_attr, | ||
430 | char *buf, loff_t pos, size_t count) | ||
431 | { | ||
432 | struct dmi_sysfs_entry *entry = to_entry(kobj->parent); | ||
433 | struct dmi_read_state state = { | ||
434 | .buf = buf, | ||
435 | .pos = pos, | ||
436 | .count = count, | ||
437 | }; | ||
438 | |||
439 | return find_dmi_entry(entry, dmi_sel_raw_read_helper, &state); | ||
440 | } | ||
441 | |||
442 | static struct bin_attribute dmi_sel_raw_attr = { | ||
443 | .attr = {.name = "raw_event_log", .mode = 0400}, | ||
444 | .read = dmi_sel_raw_read, | ||
445 | }; | ||
446 | |||
447 | static int dmi_system_event_log(struct dmi_sysfs_entry *entry) | ||
448 | { | ||
449 | int ret; | ||
450 | |||
451 | entry->child = kzalloc(sizeof(*entry->child), GFP_KERNEL); | ||
452 | if (!entry->child) | ||
453 | return -ENOMEM; | ||
454 | ret = kobject_init_and_add(entry->child, | ||
455 | &dmi_system_event_log_ktype, | ||
456 | &entry->kobj, | ||
457 | "system_event_log"); | ||
458 | if (ret) | ||
459 | goto out_free; | ||
460 | |||
461 | ret = sysfs_create_bin_file(entry->child, &dmi_sel_raw_attr); | ||
462 | if (ret) | ||
463 | goto out_del; | ||
464 | |||
465 | return 0; | ||
466 | |||
467 | out_del: | ||
468 | kobject_del(entry->child); | ||
469 | out_free: | ||
470 | kfree(entry->child); | ||
471 | return ret; | ||
472 | } | ||
473 | |||
474 | /************************************************* | ||
475 | * Generic DMI entry support. | ||
476 | *************************************************/ | ||
477 | |||
478 | static ssize_t dmi_sysfs_entry_length(struct dmi_sysfs_entry *entry, char *buf) | ||
479 | { | ||
480 | return sprintf(buf, "%d\n", entry->dh.length); | ||
481 | } | ||
482 | |||
483 | static ssize_t dmi_sysfs_entry_handle(struct dmi_sysfs_entry *entry, char *buf) | ||
484 | { | ||
485 | return sprintf(buf, "%d\n", entry->dh.handle); | ||
486 | } | ||
487 | |||
488 | static ssize_t dmi_sysfs_entry_type(struct dmi_sysfs_entry *entry, char *buf) | ||
489 | { | ||
490 | return sprintf(buf, "%d\n", entry->dh.type); | ||
491 | } | ||
492 | |||
493 | static ssize_t dmi_sysfs_entry_instance(struct dmi_sysfs_entry *entry, | ||
494 | char *buf) | ||
495 | { | ||
496 | return sprintf(buf, "%d\n", entry->instance); | ||
497 | } | ||
498 | |||
499 | static ssize_t dmi_sysfs_entry_position(struct dmi_sysfs_entry *entry, | ||
500 | char *buf) | ||
501 | { | ||
502 | return sprintf(buf, "%d\n", entry->position); | ||
503 | } | ||
504 | |||
505 | static DMI_SYSFS_ATTR(entry, length); | ||
506 | static DMI_SYSFS_ATTR(entry, handle); | ||
507 | static DMI_SYSFS_ATTR(entry, type); | ||
508 | static DMI_SYSFS_ATTR(entry, instance); | ||
509 | static DMI_SYSFS_ATTR(entry, position); | ||
510 | |||
511 | static struct attribute *dmi_sysfs_entry_attrs[] = { | ||
512 | &dmi_sysfs_attr_entry_length.attr, | ||
513 | &dmi_sysfs_attr_entry_handle.attr, | ||
514 | &dmi_sysfs_attr_entry_type.attr, | ||
515 | &dmi_sysfs_attr_entry_instance.attr, | ||
516 | &dmi_sysfs_attr_entry_position.attr, | ||
517 | NULL, | ||
518 | }; | ||
519 | |||
520 | static ssize_t dmi_entry_raw_read_helper(struct dmi_sysfs_entry *entry, | ||
521 | const struct dmi_header *dh, | ||
522 | void *_state) | ||
523 | { | ||
524 | struct dmi_read_state *state = _state; | ||
525 | size_t entry_length; | ||
526 | |||
527 | entry_length = dmi_entry_length(dh); | ||
528 | |||
529 | return memory_read_from_buffer(state->buf, state->count, | ||
530 | &state->pos, dh, entry_length); | ||
531 | } | ||
532 | |||
533 | static ssize_t dmi_entry_raw_read(struct file *filp, | ||
534 | struct kobject *kobj, | ||
535 | struct bin_attribute *bin_attr, | ||
536 | char *buf, loff_t pos, size_t count) | ||
537 | { | ||
538 | struct dmi_sysfs_entry *entry = to_entry(kobj); | ||
539 | struct dmi_read_state state = { | ||
540 | .buf = buf, | ||
541 | .pos = pos, | ||
542 | .count = count, | ||
543 | }; | ||
544 | |||
545 | return find_dmi_entry(entry, dmi_entry_raw_read_helper, &state); | ||
546 | } | ||
547 | |||
548 | static const struct bin_attribute dmi_entry_raw_attr = { | ||
549 | .attr = {.name = "raw", .mode = 0400}, | ||
550 | .read = dmi_entry_raw_read, | ||
551 | }; | ||
552 | |||
553 | static void dmi_sysfs_entry_release(struct kobject *kobj) | ||
554 | { | ||
555 | struct dmi_sysfs_entry *entry = to_entry(kobj); | ||
556 | sysfs_remove_bin_file(&entry->kobj, &dmi_entry_raw_attr); | ||
557 | spin_lock(&entry_list_lock); | ||
558 | list_del(&entry->list); | ||
559 | spin_unlock(&entry_list_lock); | ||
560 | kfree(entry); | ||
561 | } | ||
562 | |||
563 | static struct kobj_type dmi_sysfs_entry_ktype = { | ||
564 | .release = dmi_sysfs_entry_release, | ||
565 | .sysfs_ops = &dmi_sysfs_attr_ops, | ||
566 | .default_attrs = dmi_sysfs_entry_attrs, | ||
567 | }; | ||
568 | |||
569 | static struct kobject *dmi_kobj; | ||
570 | static struct kset *dmi_kset; | ||
571 | |||
572 | /* Global count of all instances seen. Only for setup */ | ||
573 | static int __initdata instance_counts[MAX_ENTRY_TYPE + 1]; | ||
574 | |||
575 | /* Global positional count of all entries seen. Only for setup */ | ||
576 | static int __initdata position_count; | ||
577 | |||
578 | static void __init dmi_sysfs_register_handle(const struct dmi_header *dh, | ||
579 | void *_ret) | ||
580 | { | ||
581 | struct dmi_sysfs_entry *entry; | ||
582 | int *ret = _ret; | ||
583 | |||
584 | /* If a previous entry saw an error, short circuit */ | ||
585 | if (*ret) | ||
586 | return; | ||
587 | |||
588 | /* Allocate and register a new entry into the entries set */ | ||
589 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); | ||
590 | if (!entry) { | ||
591 | *ret = -ENOMEM; | ||
592 | return; | ||
593 | } | ||
594 | |||
595 | /* Set the key */ | ||
596 | memcpy(&entry->dh, dh, sizeof(*dh)); | ||
597 | entry->instance = instance_counts[dh->type]++; | ||
598 | entry->position = position_count++; | ||
599 | |||
600 | entry->kobj.kset = dmi_kset; | ||
601 | *ret = kobject_init_and_add(&entry->kobj, &dmi_sysfs_entry_ktype, NULL, | ||
602 | "%d-%d", dh->type, entry->instance); | ||
603 | |||
604 | if (*ret) { | ||
605 | kfree(entry); | ||
606 | return; | ||
607 | } | ||
608 | |||
609 | /* Thread on the global list for cleanup */ | ||
610 | spin_lock(&entry_list_lock); | ||
611 | list_add_tail(&entry->list, &entry_list); | ||
612 | spin_unlock(&entry_list_lock); | ||
613 | |||
614 | /* Handle specializations by type */ | ||
615 | switch (dh->type) { | ||
616 | case DMI_ENTRY_SYSTEM_EVENT_LOG: | ||
617 | *ret = dmi_system_event_log(entry); | ||
618 | break; | ||
619 | default: | ||
620 | /* No specialization */ | ||
621 | break; | ||
622 | } | ||
623 | if (*ret) | ||
624 | goto out_err; | ||
625 | |||
626 | /* Create the raw binary file to access the entry */ | ||
627 | *ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr); | ||
628 | if (*ret) | ||
629 | goto out_err; | ||
630 | |||
631 | return; | ||
632 | out_err: | ||
633 | kobject_put(entry->child); | ||
634 | kobject_put(&entry->kobj); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | static void cleanup_entry_list(void) | ||
639 | { | ||
640 | struct dmi_sysfs_entry *entry, *next; | ||
641 | |||
642 | /* No locks, we are on our way out */ | ||
643 | list_for_each_entry_safe(entry, next, &entry_list, list) { | ||
644 | kobject_put(entry->child); | ||
645 | kobject_put(&entry->kobj); | ||
646 | } | ||
647 | } | ||
648 | |||
649 | static int __init dmi_sysfs_init(void) | ||
650 | { | ||
651 | int error = -ENOMEM; | ||
652 | int val; | ||
653 | |||
654 | /* Set up our directory */ | ||
655 | dmi_kobj = kobject_create_and_add("dmi", firmware_kobj); | ||
656 | if (!dmi_kobj) | ||
657 | goto err; | ||
658 | |||
659 | dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj); | ||
660 | if (!dmi_kset) | ||
661 | goto err; | ||
662 | |||
663 | val = 0; | ||
664 | error = dmi_walk(dmi_sysfs_register_handle, &val); | ||
665 | if (error) | ||
666 | goto err; | ||
667 | if (val) { | ||
668 | error = val; | ||
669 | goto err; | ||
670 | } | ||
671 | |||
672 | pr_debug("dmi-sysfs: loaded.\n"); | ||
673 | |||
674 | return 0; | ||
675 | err: | ||
676 | cleanup_entry_list(); | ||
677 | kset_unregister(dmi_kset); | ||
678 | kobject_put(dmi_kobj); | ||
679 | return error; | ||
680 | } | ||
681 | |||
682 | /* clean up everything. */ | ||
683 | static void __exit dmi_sysfs_exit(void) | ||
684 | { | ||
685 | pr_debug("dmi-sysfs: unloading.\n"); | ||
686 | cleanup_entry_list(); | ||
687 | kset_unregister(dmi_kset); | ||
688 | kobject_put(dmi_kobj); | ||
689 | } | ||
690 | |||
691 | module_init(dmi_sysfs_init); | ||
692 | module_exit(dmi_sysfs_exit); | ||
693 | |||
694 | MODULE_AUTHOR("Mike Waychison <mikew@google.com>"); | ||
695 | MODULE_DESCRIPTION("DMI sysfs support"); | ||
696 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index 2a62ec6390e0..ff0c373e3bbf 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
@@ -90,17 +90,6 @@ MODULE_LICENSE("GPL"); | |||
90 | MODULE_VERSION(EFIVARS_VERSION); | 90 | MODULE_VERSION(EFIVARS_VERSION); |
91 | 91 | ||
92 | /* | 92 | /* |
93 | * efivars_lock protects two things: | ||
94 | * 1) efivar_list - adds, removals, reads, writes | ||
95 | * 2) efi.[gs]et_variable() calls. | ||
96 | * It must not be held when creating sysfs entries or calling kmalloc. | ||
97 | * efi.get_next_variable() is only called from efivars_init(), | ||
98 | * which is protected by the BKL, so that path is safe. | ||
99 | */ | ||
100 | static DEFINE_SPINLOCK(efivars_lock); | ||
101 | static LIST_HEAD(efivar_list); | ||
102 | |||
103 | /* | ||
104 | * The maximum size of VariableName + Data = 1024 | 93 | * The maximum size of VariableName + Data = 1024 |
105 | * Therefore, it's reasonable to save that much | 94 | * Therefore, it's reasonable to save that much |
106 | * space in each part of the structure, | 95 | * space in each part of the structure, |
@@ -118,6 +107,7 @@ struct efi_variable { | |||
118 | 107 | ||
119 | 108 | ||
120 | struct efivar_entry { | 109 | struct efivar_entry { |
110 | struct efivars *efivars; | ||
121 | struct efi_variable var; | 111 | struct efi_variable var; |
122 | struct list_head list; | 112 | struct list_head list; |
123 | struct kobject kobj; | 113 | struct kobject kobj; |
@@ -144,9 +134,10 @@ struct efivar_attribute efivar_attr_##_name = { \ | |||
144 | * Prototype for sysfs creation function | 134 | * Prototype for sysfs creation function |
145 | */ | 135 | */ |
146 | static int | 136 | static int |
147 | efivar_create_sysfs_entry(unsigned long variable_name_size, | 137 | efivar_create_sysfs_entry(struct efivars *efivars, |
148 | efi_char16_t *variable_name, | 138 | unsigned long variable_name_size, |
149 | efi_guid_t *vendor_guid); | 139 | efi_char16_t *variable_name, |
140 | efi_guid_t *vendor_guid); | ||
150 | 141 | ||
151 | /* Return the number of unicode characters in data */ | 142 | /* Return the number of unicode characters in data */ |
152 | static unsigned long | 143 | static unsigned long |
@@ -170,18 +161,18 @@ utf8_strsize(efi_char16_t *data, unsigned long maxlength) | |||
170 | } | 161 | } |
171 | 162 | ||
172 | static efi_status_t | 163 | static efi_status_t |
173 | get_var_data(struct efi_variable *var) | 164 | get_var_data(struct efivars *efivars, struct efi_variable *var) |
174 | { | 165 | { |
175 | efi_status_t status; | 166 | efi_status_t status; |
176 | 167 | ||
177 | spin_lock(&efivars_lock); | 168 | spin_lock(&efivars->lock); |
178 | var->DataSize = 1024; | 169 | var->DataSize = 1024; |
179 | status = efi.get_variable(var->VariableName, | 170 | status = efivars->ops->get_variable(var->VariableName, |
180 | &var->VendorGuid, | 171 | &var->VendorGuid, |
181 | &var->Attributes, | 172 | &var->Attributes, |
182 | &var->DataSize, | 173 | &var->DataSize, |
183 | var->Data); | 174 | var->Data); |
184 | spin_unlock(&efivars_lock); | 175 | spin_unlock(&efivars->lock); |
185 | if (status != EFI_SUCCESS) { | 176 | if (status != EFI_SUCCESS) { |
186 | printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n", | 177 | printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n", |
187 | status); | 178 | status); |
@@ -215,7 +206,7 @@ efivar_attr_read(struct efivar_entry *entry, char *buf) | |||
215 | if (!entry || !buf) | 206 | if (!entry || !buf) |
216 | return -EINVAL; | 207 | return -EINVAL; |
217 | 208 | ||
218 | status = get_var_data(var); | 209 | status = get_var_data(entry->efivars, var); |
219 | if (status != EFI_SUCCESS) | 210 | if (status != EFI_SUCCESS) |
220 | return -EIO; | 211 | return -EIO; |
221 | 212 | ||
@@ -238,7 +229,7 @@ efivar_size_read(struct efivar_entry *entry, char *buf) | |||
238 | if (!entry || !buf) | 229 | if (!entry || !buf) |
239 | return -EINVAL; | 230 | return -EINVAL; |
240 | 231 | ||
241 | status = get_var_data(var); | 232 | status = get_var_data(entry->efivars, var); |
242 | if (status != EFI_SUCCESS) | 233 | if (status != EFI_SUCCESS) |
243 | return -EIO; | 234 | return -EIO; |
244 | 235 | ||
@@ -255,7 +246,7 @@ efivar_data_read(struct efivar_entry *entry, char *buf) | |||
255 | if (!entry || !buf) | 246 | if (!entry || !buf) |
256 | return -EINVAL; | 247 | return -EINVAL; |
257 | 248 | ||
258 | status = get_var_data(var); | 249 | status = get_var_data(entry->efivars, var); |
259 | if (status != EFI_SUCCESS) | 250 | if (status != EFI_SUCCESS) |
260 | return -EIO; | 251 | return -EIO; |
261 | 252 | ||
@@ -270,6 +261,7 @@ static ssize_t | |||
270 | efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) | 261 | efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) |
271 | { | 262 | { |
272 | struct efi_variable *new_var, *var = &entry->var; | 263 | struct efi_variable *new_var, *var = &entry->var; |
264 | struct efivars *efivars = entry->efivars; | ||
273 | efi_status_t status = EFI_NOT_FOUND; | 265 | efi_status_t status = EFI_NOT_FOUND; |
274 | 266 | ||
275 | if (count != sizeof(struct efi_variable)) | 267 | if (count != sizeof(struct efi_variable)) |
@@ -291,14 +283,14 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) | |||
291 | return -EINVAL; | 283 | return -EINVAL; |
292 | } | 284 | } |
293 | 285 | ||
294 | spin_lock(&efivars_lock); | 286 | spin_lock(&efivars->lock); |
295 | status = efi.set_variable(new_var->VariableName, | 287 | status = efivars->ops->set_variable(new_var->VariableName, |
296 | &new_var->VendorGuid, | 288 | &new_var->VendorGuid, |
297 | new_var->Attributes, | 289 | new_var->Attributes, |
298 | new_var->DataSize, | 290 | new_var->DataSize, |
299 | new_var->Data); | 291 | new_var->Data); |
300 | 292 | ||
301 | spin_unlock(&efivars_lock); | 293 | spin_unlock(&efivars->lock); |
302 | 294 | ||
303 | if (status != EFI_SUCCESS) { | 295 | if (status != EFI_SUCCESS) { |
304 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", | 296 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", |
@@ -319,7 +311,7 @@ efivar_show_raw(struct efivar_entry *entry, char *buf) | |||
319 | if (!entry || !buf) | 311 | if (!entry || !buf) |
320 | return 0; | 312 | return 0; |
321 | 313 | ||
322 | status = get_var_data(var); | 314 | status = get_var_data(entry->efivars, var); |
323 | if (status != EFI_SUCCESS) | 315 | if (status != EFI_SUCCESS) |
324 | return -EIO; | 316 | return -EIO; |
325 | 317 | ||
@@ -407,6 +399,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
407 | char *buf, loff_t pos, size_t count) | 399 | char *buf, loff_t pos, size_t count) |
408 | { | 400 | { |
409 | struct efi_variable *new_var = (struct efi_variable *)buf; | 401 | struct efi_variable *new_var = (struct efi_variable *)buf; |
402 | struct efivars *efivars = bin_attr->private; | ||
410 | struct efivar_entry *search_efivar, *n; | 403 | struct efivar_entry *search_efivar, *n; |
411 | unsigned long strsize1, strsize2; | 404 | unsigned long strsize1, strsize2; |
412 | efi_status_t status = EFI_NOT_FOUND; | 405 | efi_status_t status = EFI_NOT_FOUND; |
@@ -415,12 +408,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
415 | if (!capable(CAP_SYS_ADMIN)) | 408 | if (!capable(CAP_SYS_ADMIN)) |
416 | return -EACCES; | 409 | return -EACCES; |
417 | 410 | ||
418 | spin_lock(&efivars_lock); | 411 | spin_lock(&efivars->lock); |
419 | 412 | ||
420 | /* | 413 | /* |
421 | * Does this variable already exist? | 414 | * Does this variable already exist? |
422 | */ | 415 | */ |
423 | list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { | 416 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
424 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 417 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); |
425 | strsize2 = utf8_strsize(new_var->VariableName, 1024); | 418 | strsize2 = utf8_strsize(new_var->VariableName, 1024); |
426 | if (strsize1 == strsize2 && | 419 | if (strsize1 == strsize2 && |
@@ -433,28 +426,31 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
433 | } | 426 | } |
434 | } | 427 | } |
435 | if (found) { | 428 | if (found) { |
436 | spin_unlock(&efivars_lock); | 429 | spin_unlock(&efivars->lock); |
437 | return -EINVAL; | 430 | return -EINVAL; |
438 | } | 431 | } |
439 | 432 | ||
440 | /* now *really* create the variable via EFI */ | 433 | /* now *really* create the variable via EFI */ |
441 | status = efi.set_variable(new_var->VariableName, | 434 | status = efivars->ops->set_variable(new_var->VariableName, |
442 | &new_var->VendorGuid, | 435 | &new_var->VendorGuid, |
443 | new_var->Attributes, | 436 | new_var->Attributes, |
444 | new_var->DataSize, | 437 | new_var->DataSize, |
445 | new_var->Data); | 438 | new_var->Data); |
446 | 439 | ||
447 | if (status != EFI_SUCCESS) { | 440 | if (status != EFI_SUCCESS) { |
448 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", | 441 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", |
449 | status); | 442 | status); |
450 | spin_unlock(&efivars_lock); | 443 | spin_unlock(&efivars->lock); |
451 | return -EIO; | 444 | return -EIO; |
452 | } | 445 | } |
453 | spin_unlock(&efivars_lock); | 446 | spin_unlock(&efivars->lock); |
454 | 447 | ||
455 | /* Create the entry in sysfs. Locking is not required here */ | 448 | /* Create the entry in sysfs. Locking is not required here */ |
456 | status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName, | 449 | status = efivar_create_sysfs_entry(efivars, |
457 | 1024), new_var->VariableName, &new_var->VendorGuid); | 450 | utf8_strsize(new_var->VariableName, |
451 | 1024), | ||
452 | new_var->VariableName, | ||
453 | &new_var->VendorGuid); | ||
458 | if (status) { | 454 | if (status) { |
459 | printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n"); | 455 | printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n"); |
460 | } | 456 | } |
@@ -466,6 +462,7 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
466 | char *buf, loff_t pos, size_t count) | 462 | char *buf, loff_t pos, size_t count) |
467 | { | 463 | { |
468 | struct efi_variable *del_var = (struct efi_variable *)buf; | 464 | struct efi_variable *del_var = (struct efi_variable *)buf; |
465 | struct efivars *efivars = bin_attr->private; | ||
469 | struct efivar_entry *search_efivar, *n; | 466 | struct efivar_entry *search_efivar, *n; |
470 | unsigned long strsize1, strsize2; | 467 | unsigned long strsize1, strsize2; |
471 | efi_status_t status = EFI_NOT_FOUND; | 468 | efi_status_t status = EFI_NOT_FOUND; |
@@ -474,12 +471,12 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
474 | if (!capable(CAP_SYS_ADMIN)) | 471 | if (!capable(CAP_SYS_ADMIN)) |
475 | return -EACCES; | 472 | return -EACCES; |
476 | 473 | ||
477 | spin_lock(&efivars_lock); | 474 | spin_lock(&efivars->lock); |
478 | 475 | ||
479 | /* | 476 | /* |
480 | * Does this variable already exist? | 477 | * Does this variable already exist? |
481 | */ | 478 | */ |
482 | list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { | 479 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
483 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 480 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); |
484 | strsize2 = utf8_strsize(del_var->VariableName, 1024); | 481 | strsize2 = utf8_strsize(del_var->VariableName, 1024); |
485 | if (strsize1 == strsize2 && | 482 | if (strsize1 == strsize2 && |
@@ -492,44 +489,34 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
492 | } | 489 | } |
493 | } | 490 | } |
494 | if (!found) { | 491 | if (!found) { |
495 | spin_unlock(&efivars_lock); | 492 | spin_unlock(&efivars->lock); |
496 | return -EINVAL; | 493 | return -EINVAL; |
497 | } | 494 | } |
498 | /* force the Attributes/DataSize to 0 to ensure deletion */ | 495 | /* force the Attributes/DataSize to 0 to ensure deletion */ |
499 | del_var->Attributes = 0; | 496 | del_var->Attributes = 0; |
500 | del_var->DataSize = 0; | 497 | del_var->DataSize = 0; |
501 | 498 | ||
502 | status = efi.set_variable(del_var->VariableName, | 499 | status = efivars->ops->set_variable(del_var->VariableName, |
503 | &del_var->VendorGuid, | 500 | &del_var->VendorGuid, |
504 | del_var->Attributes, | 501 | del_var->Attributes, |
505 | del_var->DataSize, | 502 | del_var->DataSize, |
506 | del_var->Data); | 503 | del_var->Data); |
507 | 504 | ||
508 | if (status != EFI_SUCCESS) { | 505 | if (status != EFI_SUCCESS) { |
509 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", | 506 | printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", |
510 | status); | 507 | status); |
511 | spin_unlock(&efivars_lock); | 508 | spin_unlock(&efivars->lock); |
512 | return -EIO; | 509 | return -EIO; |
513 | } | 510 | } |
514 | list_del(&search_efivar->list); | 511 | list_del(&search_efivar->list); |
515 | /* We need to release this lock before unregistering. */ | 512 | /* We need to release this lock before unregistering. */ |
516 | spin_unlock(&efivars_lock); | 513 | spin_unlock(&efivars->lock); |
517 | efivar_unregister(search_efivar); | 514 | efivar_unregister(search_efivar); |
518 | 515 | ||
519 | /* It's dead Jim.... */ | 516 | /* It's dead Jim.... */ |
520 | return count; | 517 | return count; |
521 | } | 518 | } |
522 | 519 | ||
523 | static struct bin_attribute var_subsys_attr_new_var = { | ||
524 | .attr = {.name = "new_var", .mode = 0200}, | ||
525 | .write = efivar_create, | ||
526 | }; | ||
527 | |||
528 | static struct bin_attribute var_subsys_attr_del_var = { | ||
529 | .attr = {.name = "del_var", .mode = 0200}, | ||
530 | .write = efivar_delete, | ||
531 | }; | ||
532 | |||
533 | /* | 520 | /* |
534 | * Let's not leave out systab information that snuck into | 521 | * Let's not leave out systab information that snuck into |
535 | * the efivars driver | 522 | * the efivars driver |
@@ -572,8 +559,6 @@ static struct attribute_group efi_subsys_attr_group = { | |||
572 | .attrs = efi_subsys_attrs, | 559 | .attrs = efi_subsys_attrs, |
573 | }; | 560 | }; |
574 | 561 | ||
575 | |||
576 | static struct kset *vars_kset; | ||
577 | static struct kobject *efi_kobj; | 562 | static struct kobject *efi_kobj; |
578 | 563 | ||
579 | /* | 564 | /* |
@@ -582,13 +567,14 @@ static struct kobject *efi_kobj; | |||
582 | * variable_name_size = number of bytes required to hold | 567 | * variable_name_size = number of bytes required to hold |
583 | * variable_name (not counting the NULL | 568 | * variable_name (not counting the NULL |
584 | * character at the end. | 569 | * character at the end. |
585 | * efivars_lock is not held on entry or exit. | 570 | * efivars->lock is not held on entry or exit. |
586 | * Returns 1 on failure, 0 on success | 571 | * Returns 1 on failure, 0 on success |
587 | */ | 572 | */ |
588 | static int | 573 | static int |
589 | efivar_create_sysfs_entry(unsigned long variable_name_size, | 574 | efivar_create_sysfs_entry(struct efivars *efivars, |
590 | efi_char16_t *variable_name, | 575 | unsigned long variable_name_size, |
591 | efi_guid_t *vendor_guid) | 576 | efi_char16_t *variable_name, |
577 | efi_guid_t *vendor_guid) | ||
592 | { | 578 | { |
593 | int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38; | 579 | int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38; |
594 | char *short_name; | 580 | char *short_name; |
@@ -603,6 +589,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, | |||
603 | return 1; | 589 | return 1; |
604 | } | 590 | } |
605 | 591 | ||
592 | new_efivar->efivars = efivars; | ||
606 | memcpy(new_efivar->var.VariableName, variable_name, | 593 | memcpy(new_efivar->var.VariableName, variable_name, |
607 | variable_name_size); | 594 | variable_name_size); |
608 | memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t)); | 595 | memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t)); |
@@ -618,7 +605,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, | |||
618 | *(short_name + strlen(short_name)) = '-'; | 605 | *(short_name + strlen(short_name)) = '-'; |
619 | efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); | 606 | efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); |
620 | 607 | ||
621 | new_efivar->kobj.kset = vars_kset; | 608 | new_efivar->kobj.kset = efivars->kset; |
622 | i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL, | 609 | i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL, |
623 | "%s", short_name); | 610 | "%s", short_name); |
624 | if (i) { | 611 | if (i) { |
@@ -631,22 +618,95 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, | |||
631 | kfree(short_name); | 618 | kfree(short_name); |
632 | short_name = NULL; | 619 | short_name = NULL; |
633 | 620 | ||
634 | spin_lock(&efivars_lock); | 621 | spin_lock(&efivars->lock); |
635 | list_add(&new_efivar->list, &efivar_list); | 622 | list_add(&new_efivar->list, &efivars->list); |
636 | spin_unlock(&efivars_lock); | 623 | spin_unlock(&efivars->lock); |
637 | 624 | ||
638 | return 0; | 625 | return 0; |
639 | } | 626 | } |
640 | /* | ||
641 | * For now we register the efi subsystem with the firmware subsystem | ||
642 | * and the vars subsystem with the efi subsystem. In the future, it | ||
643 | * might make sense to split off the efi subsystem into its own | ||
644 | * driver, but for now only efivars will register with it, so just | ||
645 | * include it here. | ||
646 | */ | ||
647 | 627 | ||
648 | static int __init | 628 | static int |
649 | efivars_init(void) | 629 | create_efivars_bin_attributes(struct efivars *efivars) |
630 | { | ||
631 | struct bin_attribute *attr; | ||
632 | int error; | ||
633 | |||
634 | /* new_var */ | ||
635 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | ||
636 | if (!attr) | ||
637 | return -ENOMEM; | ||
638 | |||
639 | attr->attr.name = "new_var"; | ||
640 | attr->attr.mode = 0200; | ||
641 | attr->write = efivar_create; | ||
642 | attr->private = efivars; | ||
643 | efivars->new_var = attr; | ||
644 | |||
645 | /* del_var */ | ||
646 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | ||
647 | if (!attr) { | ||
648 | error = -ENOMEM; | ||
649 | goto out_free; | ||
650 | } | ||
651 | attr->attr.name = "del_var"; | ||
652 | attr->attr.mode = 0200; | ||
653 | attr->write = efivar_delete; | ||
654 | attr->private = efivars; | ||
655 | efivars->del_var = attr; | ||
656 | |||
657 | sysfs_bin_attr_init(efivars->new_var); | ||
658 | sysfs_bin_attr_init(efivars->del_var); | ||
659 | |||
660 | /* Register */ | ||
661 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
662 | efivars->new_var); | ||
663 | if (error) { | ||
664 | printk(KERN_ERR "efivars: unable to create new_var sysfs file" | ||
665 | " due to error %d\n", error); | ||
666 | goto out_free; | ||
667 | } | ||
668 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
669 | efivars->del_var); | ||
670 | if (error) { | ||
671 | printk(KERN_ERR "efivars: unable to create del_var sysfs file" | ||
672 | " due to error %d\n", error); | ||
673 | sysfs_remove_bin_file(&efivars->kset->kobj, | ||
674 | efivars->new_var); | ||
675 | goto out_free; | ||
676 | } | ||
677 | |||
678 | return 0; | ||
679 | out_free: | ||
680 | kfree(efivars->new_var); | ||
681 | efivars->new_var = NULL; | ||
682 | kfree(efivars->new_var); | ||
683 | efivars->new_var = NULL; | ||
684 | return error; | ||
685 | } | ||
686 | |||
687 | void unregister_efivars(struct efivars *efivars) | ||
688 | { | ||
689 | struct efivar_entry *entry, *n; | ||
690 | |||
691 | list_for_each_entry_safe(entry, n, &efivars->list, list) { | ||
692 | spin_lock(&efivars->lock); | ||
693 | list_del(&entry->list); | ||
694 | spin_unlock(&efivars->lock); | ||
695 | efivar_unregister(entry); | ||
696 | } | ||
697 | if (efivars->new_var) | ||
698 | sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var); | ||
699 | if (efivars->del_var) | ||
700 | sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var); | ||
701 | kfree(efivars->new_var); | ||
702 | kfree(efivars->del_var); | ||
703 | kset_unregister(efivars->kset); | ||
704 | } | ||
705 | EXPORT_SYMBOL_GPL(unregister_efivars); | ||
706 | |||
707 | int register_efivars(struct efivars *efivars, | ||
708 | const struct efivar_operations *ops, | ||
709 | struct kobject *parent_kobj) | ||
650 | { | 710 | { |
651 | efi_status_t status = EFI_NOT_FOUND; | 711 | efi_status_t status = EFI_NOT_FOUND; |
652 | efi_guid_t vendor_guid; | 712 | efi_guid_t vendor_guid; |
@@ -654,31 +714,21 @@ efivars_init(void) | |||
654 | unsigned long variable_name_size = 1024; | 714 | unsigned long variable_name_size = 1024; |
655 | int error = 0; | 715 | int error = 0; |
656 | 716 | ||
657 | if (!efi_enabled) | ||
658 | return -ENODEV; | ||
659 | |||
660 | variable_name = kzalloc(variable_name_size, GFP_KERNEL); | 717 | variable_name = kzalloc(variable_name_size, GFP_KERNEL); |
661 | if (!variable_name) { | 718 | if (!variable_name) { |
662 | printk(KERN_ERR "efivars: Memory allocation failed.\n"); | 719 | printk(KERN_ERR "efivars: Memory allocation failed.\n"); |
663 | return -ENOMEM; | 720 | return -ENOMEM; |
664 | } | 721 | } |
665 | 722 | ||
666 | printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, | 723 | spin_lock_init(&efivars->lock); |
667 | EFIVARS_DATE); | 724 | INIT_LIST_HEAD(&efivars->list); |
725 | efivars->ops = ops; | ||
668 | 726 | ||
669 | /* For now we'll register the efi directory at /sys/firmware/efi */ | 727 | efivars->kset = kset_create_and_add("vars", NULL, parent_kobj); |
670 | efi_kobj = kobject_create_and_add("efi", firmware_kobj); | 728 | if (!efivars->kset) { |
671 | if (!efi_kobj) { | ||
672 | printk(KERN_ERR "efivars: Firmware registration failed.\n"); | ||
673 | error = -ENOMEM; | ||
674 | goto out_free; | ||
675 | } | ||
676 | |||
677 | vars_kset = kset_create_and_add("vars", NULL, efi_kobj); | ||
678 | if (!vars_kset) { | ||
679 | printk(KERN_ERR "efivars: Subsystem registration failed.\n"); | 729 | printk(KERN_ERR "efivars: Subsystem registration failed.\n"); |
680 | error = -ENOMEM; | 730 | error = -ENOMEM; |
681 | goto out_firmware_unregister; | 731 | goto out; |
682 | } | 732 | } |
683 | 733 | ||
684 | /* | 734 | /* |
@@ -689,14 +739,15 @@ efivars_init(void) | |||
689 | do { | 739 | do { |
690 | variable_name_size = 1024; | 740 | variable_name_size = 1024; |
691 | 741 | ||
692 | status = efi.get_next_variable(&variable_name_size, | 742 | status = ops->get_next_variable(&variable_name_size, |
693 | variable_name, | 743 | variable_name, |
694 | &vendor_guid); | 744 | &vendor_guid); |
695 | switch (status) { | 745 | switch (status) { |
696 | case EFI_SUCCESS: | 746 | case EFI_SUCCESS: |
697 | efivar_create_sysfs_entry(variable_name_size, | 747 | efivar_create_sysfs_entry(efivars, |
698 | variable_name, | 748 | variable_name_size, |
699 | &vendor_guid); | 749 | variable_name, |
750 | &vendor_guid); | ||
700 | break; | 751 | break; |
701 | case EFI_NOT_FOUND: | 752 | case EFI_NOT_FOUND: |
702 | break; | 753 | break; |
@@ -708,35 +759,60 @@ efivars_init(void) | |||
708 | } | 759 | } |
709 | } while (status != EFI_NOT_FOUND); | 760 | } while (status != EFI_NOT_FOUND); |
710 | 761 | ||
711 | /* | 762 | error = create_efivars_bin_attributes(efivars); |
712 | * Now add attributes to allow creation of new vars | ||
713 | * and deletion of existing ones... | ||
714 | */ | ||
715 | error = sysfs_create_bin_file(&vars_kset->kobj, | ||
716 | &var_subsys_attr_new_var); | ||
717 | if (error) | ||
718 | printk(KERN_ERR "efivars: unable to create new_var sysfs file" | ||
719 | " due to error %d\n", error); | ||
720 | error = sysfs_create_bin_file(&vars_kset->kobj, | ||
721 | &var_subsys_attr_del_var); | ||
722 | if (error) | 763 | if (error) |
723 | printk(KERN_ERR "efivars: unable to create del_var sysfs file" | 764 | unregister_efivars(efivars); |
724 | " due to error %d\n", error); | ||
725 | 765 | ||
726 | /* Don't forget the systab entry */ | 766 | out: |
727 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); | 767 | kfree(variable_name); |
728 | if (error) | ||
729 | printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error); | ||
730 | else | ||
731 | goto out_free; | ||
732 | 768 | ||
733 | kset_unregister(vars_kset); | 769 | return error; |
770 | } | ||
771 | EXPORT_SYMBOL_GPL(register_efivars); | ||
734 | 772 | ||
735 | out_firmware_unregister: | 773 | static struct efivars __efivars; |
736 | kobject_put(efi_kobj); | 774 | static struct efivar_operations ops; |
737 | 775 | ||
738 | out_free: | 776 | /* |
739 | kfree(variable_name); | 777 | * For now we register the efi subsystem with the firmware subsystem |
778 | * and the vars subsystem with the efi subsystem. In the future, it | ||
779 | * might make sense to split off the efi subsystem into its own | ||
780 | * driver, but for now only efivars will register with it, so just | ||
781 | * include it here. | ||
782 | */ | ||
783 | |||
784 | static int __init | ||
785 | efivars_init(void) | ||
786 | { | ||
787 | int error = 0; | ||
788 | |||
789 | printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, | ||
790 | EFIVARS_DATE); | ||
791 | |||
792 | if (!efi_enabled) | ||
793 | return 0; | ||
794 | |||
795 | /* For now we'll register the efi directory at /sys/firmware/efi */ | ||
796 | efi_kobj = kobject_create_and_add("efi", firmware_kobj); | ||
797 | if (!efi_kobj) { | ||
798 | printk(KERN_ERR "efivars: Firmware registration failed.\n"); | ||
799 | return -ENOMEM; | ||
800 | } | ||
801 | |||
802 | ops.get_variable = efi.get_variable; | ||
803 | ops.set_variable = efi.set_variable; | ||
804 | ops.get_next_variable = efi.get_next_variable; | ||
805 | error = register_efivars(&__efivars, &ops, efi_kobj); | ||
806 | |||
807 | /* Don't forget the systab entry */ | ||
808 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); | ||
809 | if (error) { | ||
810 | printk(KERN_ERR | ||
811 | "efivars: Sysfs attribute export failed with error %d.\n", | ||
812 | error); | ||
813 | unregister_efivars(&__efivars); | ||
814 | kobject_put(efi_kobj); | ||
815 | } | ||
740 | 816 | ||
741 | return error; | 817 | return error; |
742 | } | 818 | } |
@@ -744,16 +820,7 @@ out_free: | |||
744 | static void __exit | 820 | static void __exit |
745 | efivars_exit(void) | 821 | efivars_exit(void) |
746 | { | 822 | { |
747 | struct efivar_entry *entry, *n; | 823 | unregister_efivars(&__efivars); |
748 | |||
749 | list_for_each_entry_safe(entry, n, &efivar_list, list) { | ||
750 | spin_lock(&efivars_lock); | ||
751 | list_del(&entry->list); | ||
752 | spin_unlock(&efivars_lock); | ||
753 | efivar_unregister(entry); | ||
754 | } | ||
755 | |||
756 | kset_unregister(vars_kset); | ||
757 | kobject_put(efi_kobj); | 824 | kobject_put(efi_kobj); |
758 | } | 825 | } |
759 | 826 | ||
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index cc8e49db45fe..b7d5ef234ac9 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -441,7 +441,7 @@ config BMP085 | |||
441 | module will be called bmp085. | 441 | module will be called bmp085. |
442 | 442 | ||
443 | config PCH_PHUB | 443 | config PCH_PHUB |
444 | tristate "PCH Packet Hub of Intel Topcliff" | 444 | tristate "PCH Packet Hub of Intel Topcliff / OKI SEMICONDUCTOR ML7213" |
445 | depends on PCI | 445 | depends on PCI |
446 | help | 446 | help |
447 | This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of | 447 | This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of |
@@ -449,6 +449,11 @@ config PCH_PHUB | |||
449 | processor. The Topcliff has MAC address and Option ROM data in SROM. | 449 | processor. The Topcliff has MAC address and Option ROM data in SROM. |
450 | This driver can access MAC address and Option ROM data in SROM. | 450 | This driver can access MAC address and Option ROM data in SROM. |
451 | 451 | ||
452 | This driver also can be used for OKI SEMICONDUCTOR's ML7213 which is | ||
453 | for IVI(In-Vehicle Infotainment) use. | ||
454 | ML7213 is companion chip for Intel Atom E6xx series. | ||
455 | ML7213 is completely compatible for Intel EG20T PCH. | ||
456 | |||
452 | To compile this driver as a module, choose M here: the module will | 457 | To compile this driver as a module, choose M here: the module will |
453 | be called pch_phub. | 458 | be called pch_phub. |
454 | 459 | ||
diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c index 744b804aca15..98bffc471b17 100644 --- a/drivers/misc/pch_phub.c +++ b/drivers/misc/pch_phub.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. | 2 | * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
@@ -33,7 +33,12 @@ | |||
33 | #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ | 33 | #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ |
34 | #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ | 34 | #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ |
35 | #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ | 35 | #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ |
36 | #define PCH_PHUB_ROM_START_ADDR 0x14 /* ROM data area start address offset */ | 36 | #define PCH_PHUB_MAC_START_ADDR 0x20C /* MAC data area start address offset */ |
37 | #define PCH_PHUB_ROM_START_ADDR_EG20T 0x14 /* ROM data area start address offset | ||
38 | (Intel EG20T PCH)*/ | ||
39 | #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address | ||
40 | offset(OKI SEMICONDUCTOR ML7213) | ||
41 | */ | ||
37 | 42 | ||
38 | /* MAX number of INT_REDUCE_CONTROL registers */ | 43 | /* MAX number of INT_REDUCE_CONTROL registers */ |
39 | #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 | 44 | #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 |
@@ -42,6 +47,10 @@ | |||
42 | #define CLKCFG_CAN_50MHZ 0x12000000 | 47 | #define CLKCFG_CAN_50MHZ 0x12000000 |
43 | #define CLKCFG_CANCLK_MASK 0xFF000000 | 48 | #define CLKCFG_CANCLK_MASK 0xFF000000 |
44 | 49 | ||
50 | /* Macros for ML7213 */ | ||
51 | #define PCI_VENDOR_ID_ROHM 0x10db | ||
52 | #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A | ||
53 | |||
45 | /* SROM ACCESS Macro */ | 54 | /* SROM ACCESS Macro */ |
46 | #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) | 55 | #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) |
47 | 56 | ||
@@ -298,7 +307,7 @@ static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip, | |||
298 | { | 307 | { |
299 | unsigned int mem_addr; | 308 | unsigned int mem_addr; |
300 | 309 | ||
301 | mem_addr = PCH_PHUB_ROM_START_ADDR + | 310 | mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + |
302 | pch_phub_mac_offset[offset_address]; | 311 | pch_phub_mac_offset[offset_address]; |
303 | 312 | ||
304 | pch_phub_read_serial_rom(chip, mem_addr, data); | 313 | pch_phub_read_serial_rom(chip, mem_addr, data); |
@@ -315,7 +324,7 @@ static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip, | |||
315 | int retval; | 324 | int retval; |
316 | unsigned int mem_addr; | 325 | unsigned int mem_addr; |
317 | 326 | ||
318 | mem_addr = PCH_PHUB_ROM_START_ADDR + | 327 | mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + |
319 | pch_phub_mac_offset[offset_address]; | 328 | pch_phub_mac_offset[offset_address]; |
320 | 329 | ||
321 | retval = pch_phub_write_serial_rom(chip, mem_addr, data); | 330 | retval = pch_phub_write_serial_rom(chip, mem_addr, data); |
@@ -594,23 +603,38 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev, | |||
594 | "pch_phub_extrom_base_address variable is %p\n", __func__, | 603 | "pch_phub_extrom_base_address variable is %p\n", __func__, |
595 | chip->pch_phub_extrom_base_address); | 604 | chip->pch_phub_extrom_base_address); |
596 | 605 | ||
597 | pci_set_drvdata(pdev, chip); | 606 | if (id->driver_data == 1) { |
598 | 607 | retval = sysfs_create_file(&pdev->dev.kobj, | |
599 | retval = sysfs_create_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); | 608 | &dev_attr_pch_mac.attr); |
600 | if (retval) | 609 | if (retval) |
601 | goto err_sysfs_create; | 610 | goto err_sysfs_create; |
602 | |||
603 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); | ||
604 | if (retval) | ||
605 | goto exit_bin_attr; | ||
606 | |||
607 | pch_phub_read_modify_write_reg(chip, (unsigned int)CLKCFG_REG_OFFSET, | ||
608 | CLKCFG_CAN_50MHZ, CLKCFG_CANCLK_MASK); | ||
609 | 611 | ||
610 | /* set the prefech value */ | 612 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); |
611 | iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); | 613 | if (retval) |
612 | /* set the interrupt delay value */ | 614 | goto exit_bin_attr; |
613 | iowrite32(0x25, chip->pch_phub_base_address + 0x44); | 615 | |
616 | pch_phub_read_modify_write_reg(chip, | ||
617 | (unsigned int)CLKCFG_REG_OFFSET, | ||
618 | CLKCFG_CAN_50MHZ, | ||
619 | CLKCFG_CANCLK_MASK); | ||
620 | |||
621 | /* set the prefech value */ | ||
622 | iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); | ||
623 | /* set the interrupt delay value */ | ||
624 | iowrite32(0x25, chip->pch_phub_base_address + 0x44); | ||
625 | } else if (id->driver_data == 2) { | ||
626 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); | ||
627 | if (retval) | ||
628 | goto err_sysfs_create; | ||
629 | /* set the prefech value | ||
630 | * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a | ||
631 | * Device4(SDIO #0,1,2):f | ||
632 | * Device6(SATA 2):f | ||
633 | * Device8(USB OHCI #0/ USB EHCI #0):a | ||
634 | */ | ||
635 | iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14); | ||
636 | } | ||
637 | pci_set_drvdata(pdev, chip); | ||
614 | 638 | ||
615 | return 0; | 639 | return 0; |
616 | exit_bin_attr: | 640 | exit_bin_attr: |
@@ -687,8 +711,9 @@ static int pch_phub_resume(struct pci_dev *pdev) | |||
687 | #endif /* CONFIG_PM */ | 711 | #endif /* CONFIG_PM */ |
688 | 712 | ||
689 | static struct pci_device_id pch_phub_pcidev_id[] = { | 713 | static struct pci_device_id pch_phub_pcidev_id[] = { |
690 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH1_PHUB)}, | 714 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, }, |
691 | {0,} | 715 | { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, |
716 | { } | ||
692 | }; | 717 | }; |
693 | 718 | ||
694 | static struct pci_driver pch_phub_driver = { | 719 | static struct pci_driver pch_phub_driver = { |
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index f9aad06d1ae5..486117f72c9f 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c | |||
@@ -25,10 +25,9 @@ | |||
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/tty.h> | 26 | #include <linux/tty.h> |
27 | 27 | ||
28 | /* understand BT, FM and GPS for now */ | 28 | #include <linux/seq_file.h> |
29 | #include <net/bluetooth/bluetooth.h> | 29 | #include <linux/skbuff.h> |
30 | #include <net/bluetooth/hci_core.h> | 30 | |
31 | #include <net/bluetooth/hci.h> | ||
32 | #include <linux/ti_wilink_st.h> | 31 | #include <linux/ti_wilink_st.h> |
33 | 32 | ||
34 | /* function pointer pointing to either, | 33 | /* function pointer pointing to either, |
@@ -38,21 +37,38 @@ | |||
38 | void (*st_recv) (void*, const unsigned char*, long); | 37 | void (*st_recv) (void*, const unsigned char*, long); |
39 | 38 | ||
40 | /********************************************************************/ | 39 | /********************************************************************/ |
41 | #if 0 | 40 | static void add_channel_to_table(struct st_data_s *st_gdata, |
42 | /* internal misc functions */ | 41 | struct st_proto_s *new_proto) |
43 | bool is_protocol_list_empty(void) | ||
44 | { | 42 | { |
45 | unsigned char i = 0; | 43 | pr_info("%s: id %d\n", __func__, new_proto->chnl_id); |
46 | pr_debug(" %s ", __func__); | 44 | /* list now has the channel id as index itself */ |
47 | for (i = 0; i < ST_MAX; i++) { | 45 | st_gdata->list[new_proto->chnl_id] = new_proto; |
48 | if (st_gdata->list[i] != NULL) | 46 | } |
49 | return ST_NOTEMPTY; | 47 | |
50 | /* not empty */ | 48 | static void remove_channel_from_table(struct st_data_s *st_gdata, |
49 | struct st_proto_s *proto) | ||
50 | { | ||
51 | pr_info("%s: id %d\n", __func__, proto->chnl_id); | ||
52 | st_gdata->list[proto->chnl_id] = NULL; | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * called from KIM during firmware download. | ||
57 | * | ||
58 | * This is a wrapper function to tty->ops->write_room. | ||
59 | * It returns number of free space available in | ||
60 | * uart tx buffer. | ||
61 | */ | ||
62 | int st_get_uart_wr_room(struct st_data_s *st_gdata) | ||
63 | { | ||
64 | struct tty_struct *tty; | ||
65 | if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { | ||
66 | pr_err("tty unavailable to perform write"); | ||
67 | return -1; | ||
51 | } | 68 | } |
52 | /* list empty */ | 69 | tty = st_gdata->tty; |
53 | return ST_EMPTY; | 70 | return tty->ops->write_room(tty); |
54 | } | 71 | } |
55 | #endif | ||
56 | 72 | ||
57 | /* can be called in from | 73 | /* can be called in from |
58 | * -- KIM (during fw download) | 74 | * -- KIM (during fw download) |
@@ -67,7 +83,7 @@ int st_int_write(struct st_data_s *st_gdata, | |||
67 | struct tty_struct *tty; | 83 | struct tty_struct *tty; |
68 | if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { | 84 | if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { |
69 | pr_err("tty unavailable to perform write"); | 85 | pr_err("tty unavailable to perform write"); |
70 | return -1; | 86 | return -EINVAL; |
71 | } | 87 | } |
72 | tty = st_gdata->tty; | 88 | tty = st_gdata->tty; |
73 | #ifdef VERBOSE | 89 | #ifdef VERBOSE |
@@ -82,15 +98,15 @@ int st_int_write(struct st_data_s *st_gdata, | |||
82 | * push the skb received to relevant | 98 | * push the skb received to relevant |
83 | * protocol stacks | 99 | * protocol stacks |
84 | */ | 100 | */ |
85 | void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata) | 101 | void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) |
86 | { | 102 | { |
87 | pr_info(" %s(prot:%d) ", __func__, protoid); | 103 | pr_debug(" %s(prot:%d) ", __func__, chnl_id); |
88 | 104 | ||
89 | if (unlikely | 105 | if (unlikely |
90 | (st_gdata == NULL || st_gdata->rx_skb == NULL | 106 | (st_gdata == NULL || st_gdata->rx_skb == NULL |
91 | || st_gdata->list[protoid] == NULL)) { | 107 | || st_gdata->list[chnl_id] == NULL)) { |
92 | pr_err("protocol %d not registered, no data to send?", | 108 | pr_err("chnl_id %d not registered, no data to send?", |
93 | protoid); | 109 | chnl_id); |
94 | kfree_skb(st_gdata->rx_skb); | 110 | kfree_skb(st_gdata->rx_skb); |
95 | return; | 111 | return; |
96 | } | 112 | } |
@@ -99,17 +115,17 @@ void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata) | |||
99 | * - should be just skb_queue_tail for the | 115 | * - should be just skb_queue_tail for the |
100 | * protocol stack driver | 116 | * protocol stack driver |
101 | */ | 117 | */ |
102 | if (likely(st_gdata->list[protoid]->recv != NULL)) { | 118 | if (likely(st_gdata->list[chnl_id]->recv != NULL)) { |
103 | if (unlikely | 119 | if (unlikely |
104 | (st_gdata->list[protoid]->recv | 120 | (st_gdata->list[chnl_id]->recv |
105 | (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb) | 121 | (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb) |
106 | != 0)) { | 122 | != 0)) { |
107 | pr_err(" proto stack %d's ->recv failed", protoid); | 123 | pr_err(" proto stack %d's ->recv failed", chnl_id); |
108 | kfree_skb(st_gdata->rx_skb); | 124 | kfree_skb(st_gdata->rx_skb); |
109 | return; | 125 | return; |
110 | } | 126 | } |
111 | } else { | 127 | } else { |
112 | pr_err(" proto stack %d's ->recv null", protoid); | 128 | pr_err(" proto stack %d's ->recv null", chnl_id); |
113 | kfree_skb(st_gdata->rx_skb); | 129 | kfree_skb(st_gdata->rx_skb); |
114 | } | 130 | } |
115 | return; | 131 | return; |
@@ -124,16 +140,22 @@ void st_reg_complete(struct st_data_s *st_gdata, char err) | |||
124 | { | 140 | { |
125 | unsigned char i = 0; | 141 | unsigned char i = 0; |
126 | pr_info(" %s ", __func__); | 142 | pr_info(" %s ", __func__); |
127 | for (i = 0; i < ST_MAX; i++) { | 143 | for (i = 0; i < ST_MAX_CHANNELS; i++) { |
128 | if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && | 144 | if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && |
129 | st_gdata->list[i]->reg_complete_cb != NULL)) | 145 | st_gdata->list[i]->reg_complete_cb != NULL)) { |
130 | st_gdata->list[i]->reg_complete_cb | 146 | st_gdata->list[i]->reg_complete_cb |
131 | (st_gdata->list[i]->priv_data, err); | 147 | (st_gdata->list[i]->priv_data, err); |
148 | pr_info("protocol %d's cb sent %d\n", i, err); | ||
149 | if (err) { /* cleanup registered protocol */ | ||
150 | st_gdata->protos_registered--; | ||
151 | st_gdata->list[i] = NULL; | ||
152 | } | ||
153 | } | ||
132 | } | 154 | } |
133 | } | 155 | } |
134 | 156 | ||
135 | static inline int st_check_data_len(struct st_data_s *st_gdata, | 157 | static inline int st_check_data_len(struct st_data_s *st_gdata, |
136 | int protoid, int len) | 158 | unsigned char chnl_id, int len) |
137 | { | 159 | { |
138 | int room = skb_tailroom(st_gdata->rx_skb); | 160 | int room = skb_tailroom(st_gdata->rx_skb); |
139 | 161 | ||
@@ -144,7 +166,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata, | |||
144 | * has zero length payload. So, ask ST CORE to | 166 | * has zero length payload. So, ask ST CORE to |
145 | * forward the packet to protocol driver (BT/FM/GPS) | 167 | * forward the packet to protocol driver (BT/FM/GPS) |
146 | */ | 168 | */ |
147 | st_send_frame(protoid, st_gdata); | 169 | st_send_frame(chnl_id, st_gdata); |
148 | 170 | ||
149 | } else if (len > room) { | 171 | } else if (len > room) { |
150 | /* Received packet's payload length is larger. | 172 | /* Received packet's payload length is larger. |
@@ -157,7 +179,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata, | |||
157 | /* Packet header has non-zero payload length and | 179 | /* Packet header has non-zero payload length and |
158 | * we have enough space in created skb. Lets read | 180 | * we have enough space in created skb. Lets read |
159 | * payload data */ | 181 | * payload data */ |
160 | st_gdata->rx_state = ST_BT_W4_DATA; | 182 | st_gdata->rx_state = ST_W4_DATA; |
161 | st_gdata->rx_count = len; | 183 | st_gdata->rx_count = len; |
162 | return len; | 184 | return len; |
163 | } | 185 | } |
@@ -167,6 +189,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata, | |||
167 | st_gdata->rx_state = ST_W4_PACKET_TYPE; | 189 | st_gdata->rx_state = ST_W4_PACKET_TYPE; |
168 | st_gdata->rx_skb = NULL; | 190 | st_gdata->rx_skb = NULL; |
169 | st_gdata->rx_count = 0; | 191 | st_gdata->rx_count = 0; |
192 | st_gdata->rx_chnl = 0; | ||
170 | 193 | ||
171 | return 0; | 194 | return 0; |
172 | } | 195 | } |
@@ -208,14 +231,12 @@ void st_int_recv(void *disc_data, | |||
208 | const unsigned char *data, long count) | 231 | const unsigned char *data, long count) |
209 | { | 232 | { |
210 | char *ptr; | 233 | char *ptr; |
211 | struct hci_event_hdr *eh; | 234 | struct st_proto_s *proto; |
212 | struct hci_acl_hdr *ah; | 235 | unsigned short payload_len = 0; |
213 | struct hci_sco_hdr *sh; | 236 | int len = 0, type = 0; |
214 | struct fm_event_hdr *fm; | 237 | unsigned char *plen; |
215 | struct gps_event_hdr *gps; | ||
216 | int len = 0, type = 0, dlen = 0; | ||
217 | static enum proto_type protoid = ST_MAX; | ||
218 | struct st_data_s *st_gdata = (struct st_data_s *)disc_data; | 238 | struct st_data_s *st_gdata = (struct st_data_s *)disc_data; |
239 | unsigned long flags; | ||
219 | 240 | ||
220 | ptr = (char *)data; | 241 | ptr = (char *)data; |
221 | /* tty_receive sent null ? */ | 242 | /* tty_receive sent null ? */ |
@@ -224,10 +245,11 @@ void st_int_recv(void *disc_data, | |||
224 | return; | 245 | return; |
225 | } | 246 | } |
226 | 247 | ||
227 | pr_info("count %ld rx_state %ld" | 248 | pr_debug("count %ld rx_state %ld" |
228 | "rx_count %ld", count, st_gdata->rx_state, | 249 | "rx_count %ld", count, st_gdata->rx_state, |
229 | st_gdata->rx_count); | 250 | st_gdata->rx_count); |
230 | 251 | ||
252 | spin_lock_irqsave(&st_gdata->lock, flags); | ||
231 | /* Decode received bytes here */ | 253 | /* Decode received bytes here */ |
232 | while (count) { | 254 | while (count) { |
233 | if (st_gdata->rx_count) { | 255 | if (st_gdata->rx_count) { |
@@ -242,64 +264,36 @@ void st_int_recv(void *disc_data, | |||
242 | 264 | ||
243 | /* Check ST RX state machine , where are we? */ | 265 | /* Check ST RX state machine , where are we? */ |
244 | switch (st_gdata->rx_state) { | 266 | switch (st_gdata->rx_state) { |
245 | 267 | /* Waiting for complete packet ? */ | |
246 | /* Waiting for complete packet ? */ | 268 | case ST_W4_DATA: |
247 | case ST_BT_W4_DATA: | ||
248 | pr_debug("Complete pkt received"); | 269 | pr_debug("Complete pkt received"); |
249 | |||
250 | /* Ask ST CORE to forward | 270 | /* Ask ST CORE to forward |
251 | * the packet to protocol driver */ | 271 | * the packet to protocol driver */ |
252 | st_send_frame(protoid, st_gdata); | 272 | st_send_frame(st_gdata->rx_chnl, st_gdata); |
253 | 273 | ||
254 | st_gdata->rx_state = ST_W4_PACKET_TYPE; | 274 | st_gdata->rx_state = ST_W4_PACKET_TYPE; |
255 | st_gdata->rx_skb = NULL; | 275 | st_gdata->rx_skb = NULL; |
256 | protoid = ST_MAX; /* is this required ? */ | ||
257 | continue; | 276 | continue; |
258 | 277 | /* parse the header to know details */ | |
259 | /* Waiting for Bluetooth event header ? */ | 278 | case ST_W4_HEADER: |
260 | case ST_BT_W4_EVENT_HDR: | 279 | proto = st_gdata->list[st_gdata->rx_chnl]; |
261 | eh = (struct hci_event_hdr *)st_gdata->rx_skb-> | 280 | plen = |
262 | data; | 281 | &st_gdata->rx_skb->data |
263 | 282 | [proto->offset_len_in_hdr]; | |
264 | pr_debug("Event header: evt 0x%2.2x" | 283 | pr_debug("plen pointing to %x\n", *plen); |
265 | "plen %d", eh->evt, eh->plen); | 284 | if (proto->len_size == 1)/* 1 byte len field */ |
266 | 285 | payload_len = *(unsigned char *)plen; | |
267 | st_check_data_len(st_gdata, protoid, eh->plen); | 286 | else if (proto->len_size == 2) |
268 | continue; | 287 | payload_len = |
269 | 288 | __le16_to_cpu(*(unsigned short *)plen); | |
270 | /* Waiting for Bluetooth acl header ? */ | 289 | else |
271 | case ST_BT_W4_ACL_HDR: | 290 | pr_info("%s: invalid length " |
272 | ah = (struct hci_acl_hdr *)st_gdata->rx_skb-> | 291 | "for id %d\n", |
273 | data; | 292 | __func__, proto->chnl_id); |
274 | dlen = __le16_to_cpu(ah->dlen); | 293 | st_check_data_len(st_gdata, proto->chnl_id, |
275 | 294 | payload_len); | |
276 | pr_info("ACL header: dlen %d", dlen); | 295 | pr_debug("off %d, pay len %d\n", |
277 | 296 | proto->offset_len_in_hdr, payload_len); | |
278 | st_check_data_len(st_gdata, protoid, dlen); | ||
279 | continue; | ||
280 | |||
281 | /* Waiting for Bluetooth sco header ? */ | ||
282 | case ST_BT_W4_SCO_HDR: | ||
283 | sh = (struct hci_sco_hdr *)st_gdata->rx_skb-> | ||
284 | data; | ||
285 | |||
286 | pr_info("SCO header: dlen %d", sh->dlen); | ||
287 | |||
288 | st_check_data_len(st_gdata, protoid, sh->dlen); | ||
289 | continue; | ||
290 | case ST_FM_W4_EVENT_HDR: | ||
291 | fm = (struct fm_event_hdr *)st_gdata->rx_skb-> | ||
292 | data; | ||
293 | pr_info("FM Header: "); | ||
294 | st_check_data_len(st_gdata, ST_FM, fm->plen); | ||
295 | continue; | ||
296 | /* TODO : Add GPS packet machine logic here */ | ||
297 | case ST_GPS_W4_EVENT_HDR: | ||
298 | /* [0x09 pkt hdr][R/W byte][2 byte len] */ | ||
299 | gps = (struct gps_event_hdr *)st_gdata->rx_skb-> | ||
300 | data; | ||
301 | pr_info("GPS Header: "); | ||
302 | st_check_data_len(st_gdata, ST_GPS, gps->plen); | ||
303 | continue; | 297 | continue; |
304 | } /* end of switch rx_state */ | 298 | } /* end of switch rx_state */ |
305 | } | 299 | } |
@@ -308,123 +302,56 @@ void st_int_recv(void *disc_data, | |||
308 | /* Check first byte of packet and identify module | 302 | /* Check first byte of packet and identify module |
309 | * owner (BT/FM/GPS) */ | 303 | * owner (BT/FM/GPS) */ |
310 | switch (*ptr) { | 304 | switch (*ptr) { |
311 | |||
312 | /* Bluetooth event packet? */ | ||
313 | case HCI_EVENT_PKT: | ||
314 | pr_info("Event packet"); | ||
315 | st_gdata->rx_state = ST_BT_W4_EVENT_HDR; | ||
316 | st_gdata->rx_count = HCI_EVENT_HDR_SIZE; | ||
317 | type = HCI_EVENT_PKT; | ||
318 | protoid = ST_BT; | ||
319 | break; | ||
320 | |||
321 | /* Bluetooth acl packet? */ | ||
322 | case HCI_ACLDATA_PKT: | ||
323 | pr_info("ACL packet"); | ||
324 | st_gdata->rx_state = ST_BT_W4_ACL_HDR; | ||
325 | st_gdata->rx_count = HCI_ACL_HDR_SIZE; | ||
326 | type = HCI_ACLDATA_PKT; | ||
327 | protoid = ST_BT; | ||
328 | break; | ||
329 | |||
330 | /* Bluetooth sco packet? */ | ||
331 | case HCI_SCODATA_PKT: | ||
332 | pr_info("SCO packet"); | ||
333 | st_gdata->rx_state = ST_BT_W4_SCO_HDR; | ||
334 | st_gdata->rx_count = HCI_SCO_HDR_SIZE; | ||
335 | type = HCI_SCODATA_PKT; | ||
336 | protoid = ST_BT; | ||
337 | break; | ||
338 | |||
339 | /* Channel 8(FM) packet? */ | ||
340 | case ST_FM_CH8_PKT: | ||
341 | pr_info("FM CH8 packet"); | ||
342 | type = ST_FM_CH8_PKT; | ||
343 | st_gdata->rx_state = ST_FM_W4_EVENT_HDR; | ||
344 | st_gdata->rx_count = FM_EVENT_HDR_SIZE; | ||
345 | protoid = ST_FM; | ||
346 | break; | ||
347 | |||
348 | /* Channel 9(GPS) packet? */ | ||
349 | case 0x9: /*ST_LL_GPS_CH9_PKT */ | ||
350 | pr_info("GPS CH9 packet"); | ||
351 | type = 0x9; /* ST_LL_GPS_CH9_PKT; */ | ||
352 | protoid = ST_GPS; | ||
353 | st_gdata->rx_state = ST_GPS_W4_EVENT_HDR; | ||
354 | st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/ | ||
355 | break; | ||
356 | case LL_SLEEP_IND: | 305 | case LL_SLEEP_IND: |
357 | case LL_SLEEP_ACK: | 306 | case LL_SLEEP_ACK: |
358 | case LL_WAKE_UP_IND: | 307 | case LL_WAKE_UP_IND: |
359 | pr_info("PM packet"); | 308 | pr_debug("PM packet"); |
360 | /* this takes appropriate action based on | 309 | /* this takes appropriate action based on |
361 | * sleep state received -- | 310 | * sleep state received -- |
362 | */ | 311 | */ |
363 | st_ll_sleep_state(st_gdata, *ptr); | 312 | st_ll_sleep_state(st_gdata, *ptr); |
313 | /* if WAKEUP_IND collides copy from waitq to txq | ||
314 | * and assume chip awake | ||
315 | */ | ||
316 | spin_unlock_irqrestore(&st_gdata->lock, flags); | ||
317 | if (st_ll_getstate(st_gdata) == ST_LL_AWAKE) | ||
318 | st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK); | ||
319 | spin_lock_irqsave(&st_gdata->lock, flags); | ||
320 | |||
364 | ptr++; | 321 | ptr++; |
365 | count--; | 322 | count--; |
366 | continue; | 323 | continue; |
367 | case LL_WAKE_UP_ACK: | 324 | case LL_WAKE_UP_ACK: |
368 | pr_info("PM packet"); | 325 | pr_debug("PM packet"); |
326 | |||
327 | spin_unlock_irqrestore(&st_gdata->lock, flags); | ||
369 | /* wake up ack received */ | 328 | /* wake up ack received */ |
370 | st_wakeup_ack(st_gdata, *ptr); | 329 | st_wakeup_ack(st_gdata, *ptr); |
330 | spin_lock_irqsave(&st_gdata->lock, flags); | ||
331 | |||
371 | ptr++; | 332 | ptr++; |
372 | count--; | 333 | count--; |
373 | continue; | 334 | continue; |
374 | /* Unknow packet? */ | 335 | /* Unknow packet? */ |
375 | default: | 336 | default: |
376 | pr_err("Unknown packet type %2.2x", (__u8) *ptr); | 337 | type = *ptr; |
377 | ptr++; | 338 | st_gdata->rx_skb = alloc_skb( |
378 | count--; | 339 | st_gdata->list[type]->max_frame_size, |
379 | continue; | 340 | GFP_ATOMIC); |
341 | skb_reserve(st_gdata->rx_skb, | ||
342 | st_gdata->list[type]->reserve); | ||
343 | /* next 2 required for BT only */ | ||
344 | st_gdata->rx_skb->cb[0] = type; /*pkt_type*/ | ||
345 | st_gdata->rx_skb->cb[1] = 0; /*incoming*/ | ||
346 | st_gdata->rx_chnl = *ptr; | ||
347 | st_gdata->rx_state = ST_W4_HEADER; | ||
348 | st_gdata->rx_count = st_gdata->list[type]->hdr_len; | ||
349 | pr_debug("rx_count %ld\n", st_gdata->rx_count); | ||
380 | }; | 350 | }; |
381 | ptr++; | 351 | ptr++; |
382 | count--; | 352 | count--; |
383 | |||
384 | switch (protoid) { | ||
385 | case ST_BT: | ||
386 | /* Allocate new packet to hold received data */ | ||
387 | st_gdata->rx_skb = | ||
388 | bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); | ||
389 | if (!st_gdata->rx_skb) { | ||
390 | pr_err("Can't allocate mem for new packet"); | ||
391 | st_gdata->rx_state = ST_W4_PACKET_TYPE; | ||
392 | st_gdata->rx_count = 0; | ||
393 | return; | ||
394 | } | ||
395 | bt_cb(st_gdata->rx_skb)->pkt_type = type; | ||
396 | break; | ||
397 | case ST_FM: /* for FM */ | ||
398 | st_gdata->rx_skb = | ||
399 | alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC); | ||
400 | if (!st_gdata->rx_skb) { | ||
401 | pr_err("Can't allocate mem for new packet"); | ||
402 | st_gdata->rx_state = ST_W4_PACKET_TYPE; | ||
403 | st_gdata->rx_count = 0; | ||
404 | return; | ||
405 | } | ||
406 | /* place holder 0x08 */ | ||
407 | skb_reserve(st_gdata->rx_skb, 1); | ||
408 | st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT; | ||
409 | break; | ||
410 | case ST_GPS: | ||
411 | /* for GPS */ | ||
412 | st_gdata->rx_skb = | ||
413 | alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC); | ||
414 | if (!st_gdata->rx_skb) { | ||
415 | pr_err("Can't allocate mem for new packet"); | ||
416 | st_gdata->rx_state = ST_W4_PACKET_TYPE; | ||
417 | st_gdata->rx_count = 0; | ||
418 | return; | ||
419 | } | ||
420 | /* place holder 0x09 */ | ||
421 | skb_reserve(st_gdata->rx_skb, 1); | ||
422 | st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */ | ||
423 | break; | ||
424 | case ST_MAX: | ||
425 | break; | ||
426 | } | ||
427 | } | 353 | } |
354 | spin_unlock_irqrestore(&st_gdata->lock, flags); | ||
428 | pr_debug("done %s", __func__); | 355 | pr_debug("done %s", __func__); |
429 | return; | 356 | return; |
430 | } | 357 | } |
@@ -466,7 +393,7 @@ void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb) | |||
466 | 393 | ||
467 | switch (st_ll_getstate(st_gdata)) { | 394 | switch (st_ll_getstate(st_gdata)) { |
468 | case ST_LL_AWAKE: | 395 | case ST_LL_AWAKE: |
469 | pr_info("ST LL is AWAKE, sending normally"); | 396 | pr_debug("ST LL is AWAKE, sending normally"); |
470 | skb_queue_tail(&st_gdata->txq, skb); | 397 | skb_queue_tail(&st_gdata->txq, skb); |
471 | break; | 398 | break; |
472 | case ST_LL_ASLEEP_TO_AWAKE: | 399 | case ST_LL_ASLEEP_TO_AWAKE: |
@@ -506,7 +433,7 @@ void st_tx_wakeup(struct st_data_s *st_data) | |||
506 | pr_debug("%s", __func__); | 433 | pr_debug("%s", __func__); |
507 | /* check for sending & set flag sending here */ | 434 | /* check for sending & set flag sending here */ |
508 | if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { | 435 | if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { |
509 | pr_info("ST already sending"); | 436 | pr_debug("ST already sending"); |
510 | /* keep sending */ | 437 | /* keep sending */ |
511 | set_bit(ST_TX_WAKEUP, &st_data->tx_state); | 438 | set_bit(ST_TX_WAKEUP, &st_data->tx_state); |
512 | return; | 439 | return; |
@@ -548,9 +475,9 @@ void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf) | |||
548 | { | 475 | { |
549 | seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", | 476 | seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", |
550 | st_gdata->protos_registered, | 477 | st_gdata->protos_registered, |
551 | st_gdata->list[ST_BT] != NULL ? 'R' : 'U', | 478 | st_gdata->list[0x04] != NULL ? 'R' : 'U', |
552 | st_gdata->list[ST_FM] != NULL ? 'R' : 'U', | 479 | st_gdata->list[0x08] != NULL ? 'R' : 'U', |
553 | st_gdata->list[ST_GPS] != NULL ? 'R' : 'U'); | 480 | st_gdata->list[0x09] != NULL ? 'R' : 'U'); |
554 | } | 481 | } |
555 | 482 | ||
556 | /********************************************************************/ | 483 | /********************************************************************/ |
@@ -565,20 +492,20 @@ long st_register(struct st_proto_s *new_proto) | |||
565 | unsigned long flags = 0; | 492 | unsigned long flags = 0; |
566 | 493 | ||
567 | st_kim_ref(&st_gdata, 0); | 494 | st_kim_ref(&st_gdata, 0); |
568 | pr_info("%s(%d) ", __func__, new_proto->type); | 495 | pr_info("%s(%d) ", __func__, new_proto->chnl_id); |
569 | if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL | 496 | if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL |
570 | || new_proto->reg_complete_cb == NULL) { | 497 | || new_proto->reg_complete_cb == NULL) { |
571 | pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); | 498 | pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); |
572 | return -1; | 499 | return -EINVAL; |
573 | } | 500 | } |
574 | 501 | ||
575 | if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) { | 502 | if (new_proto->chnl_id >= ST_MAX_CHANNELS) { |
576 | pr_err("protocol %d not supported", new_proto->type); | 503 | pr_err("chnl_id %d not supported", new_proto->chnl_id); |
577 | return -EPROTONOSUPPORT; | 504 | return -EPROTONOSUPPORT; |
578 | } | 505 | } |
579 | 506 | ||
580 | if (st_gdata->list[new_proto->type] != NULL) { | 507 | if (st_gdata->list[new_proto->chnl_id] != NULL) { |
581 | pr_err("protocol %d already registered", new_proto->type); | 508 | pr_err("chnl_id %d already registered", new_proto->chnl_id); |
582 | return -EALREADY; | 509 | return -EALREADY; |
583 | } | 510 | } |
584 | 511 | ||
@@ -586,11 +513,10 @@ long st_register(struct st_proto_s *new_proto) | |||
586 | spin_lock_irqsave(&st_gdata->lock, flags); | 513 | spin_lock_irqsave(&st_gdata->lock, flags); |
587 | 514 | ||
588 | if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { | 515 | if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { |
589 | pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type); | 516 | pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id); |
590 | /* fw download in progress */ | 517 | /* fw download in progress */ |
591 | st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); | ||
592 | 518 | ||
593 | st_gdata->list[new_proto->type] = new_proto; | 519 | add_channel_to_table(st_gdata, new_proto); |
594 | st_gdata->protos_registered++; | 520 | st_gdata->protos_registered++; |
595 | new_proto->write = st_write; | 521 | new_proto->write = st_write; |
596 | 522 | ||
@@ -598,7 +524,7 @@ long st_register(struct st_proto_s *new_proto) | |||
598 | spin_unlock_irqrestore(&st_gdata->lock, flags); | 524 | spin_unlock_irqrestore(&st_gdata->lock, flags); |
599 | return -EINPROGRESS; | 525 | return -EINPROGRESS; |
600 | } else if (st_gdata->protos_registered == ST_EMPTY) { | 526 | } else if (st_gdata->protos_registered == ST_EMPTY) { |
601 | pr_info(" protocol list empty :%d ", new_proto->type); | 527 | pr_info(" chnl_id list empty :%d ", new_proto->chnl_id); |
602 | set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); | 528 | set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); |
603 | st_recv = st_kim_recv; | 529 | st_recv = st_kim_recv; |
604 | 530 | ||
@@ -616,16 +542,11 @@ long st_register(struct st_proto_s *new_proto) | |||
616 | if ((st_gdata->protos_registered != ST_EMPTY) && | 542 | if ((st_gdata->protos_registered != ST_EMPTY) && |
617 | (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { | 543 | (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { |
618 | pr_err(" KIM failure complete callback "); | 544 | pr_err(" KIM failure complete callback "); |
619 | st_reg_complete(st_gdata, -1); | 545 | st_reg_complete(st_gdata, err); |
620 | } | 546 | } |
621 | 547 | return -EINVAL; | |
622 | return -1; | ||
623 | } | 548 | } |
624 | 549 | ||
625 | /* the protocol might require other gpios to be toggled | ||
626 | */ | ||
627 | st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); | ||
628 | |||
629 | clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); | 550 | clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); |
630 | st_recv = st_int_recv; | 551 | st_recv = st_int_recv; |
631 | 552 | ||
@@ -642,14 +563,14 @@ long st_register(struct st_proto_s *new_proto) | |||
642 | /* check for already registered once more, | 563 | /* check for already registered once more, |
643 | * since the above check is old | 564 | * since the above check is old |
644 | */ | 565 | */ |
645 | if (st_gdata->list[new_proto->type] != NULL) { | 566 | if (st_gdata->list[new_proto->chnl_id] != NULL) { |
646 | pr_err(" proto %d already registered ", | 567 | pr_err(" proto %d already registered ", |
647 | new_proto->type); | 568 | new_proto->chnl_id); |
648 | return -EALREADY; | 569 | return -EALREADY; |
649 | } | 570 | } |
650 | 571 | ||
651 | spin_lock_irqsave(&st_gdata->lock, flags); | 572 | spin_lock_irqsave(&st_gdata->lock, flags); |
652 | st_gdata->list[new_proto->type] = new_proto; | 573 | add_channel_to_table(st_gdata, new_proto); |
653 | st_gdata->protos_registered++; | 574 | st_gdata->protos_registered++; |
654 | new_proto->write = st_write; | 575 | new_proto->write = st_write; |
655 | spin_unlock_irqrestore(&st_gdata->lock, flags); | 576 | spin_unlock_irqrestore(&st_gdata->lock, flags); |
@@ -657,22 +578,7 @@ long st_register(struct st_proto_s *new_proto) | |||
657 | } | 578 | } |
658 | /* if fw is already downloaded & new stack registers protocol */ | 579 | /* if fw is already downloaded & new stack registers protocol */ |
659 | else { | 580 | else { |
660 | switch (new_proto->type) { | 581 | add_channel_to_table(st_gdata, new_proto); |
661 | case ST_BT: | ||
662 | /* do nothing */ | ||
663 | break; | ||
664 | case ST_FM: | ||
665 | case ST_GPS: | ||
666 | st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); | ||
667 | break; | ||
668 | case ST_MAX: | ||
669 | default: | ||
670 | pr_err("%d protocol not supported", | ||
671 | new_proto->type); | ||
672 | spin_unlock_irqrestore(&st_gdata->lock, flags); | ||
673 | return -EPROTONOSUPPORT; | ||
674 | } | ||
675 | st_gdata->list[new_proto->type] = new_proto; | ||
676 | st_gdata->protos_registered++; | 582 | st_gdata->protos_registered++; |
677 | new_proto->write = st_write; | 583 | new_proto->write = st_write; |
678 | 584 | ||
@@ -680,48 +586,42 @@ long st_register(struct st_proto_s *new_proto) | |||
680 | spin_unlock_irqrestore(&st_gdata->lock, flags); | 586 | spin_unlock_irqrestore(&st_gdata->lock, flags); |
681 | return err; | 587 | return err; |
682 | } | 588 | } |
683 | pr_debug("done %s(%d) ", __func__, new_proto->type); | 589 | pr_debug("done %s(%d) ", __func__, new_proto->chnl_id); |
684 | } | 590 | } |
685 | EXPORT_SYMBOL_GPL(st_register); | 591 | EXPORT_SYMBOL_GPL(st_register); |
686 | 592 | ||
687 | /* to unregister a protocol - | 593 | /* to unregister a protocol - |
688 | * to be called from protocol stack driver | 594 | * to be called from protocol stack driver |
689 | */ | 595 | */ |
690 | long st_unregister(enum proto_type type) | 596 | long st_unregister(struct st_proto_s *proto) |
691 | { | 597 | { |
692 | long err = 0; | 598 | long err = 0; |
693 | unsigned long flags = 0; | 599 | unsigned long flags = 0; |
694 | struct st_data_s *st_gdata; | 600 | struct st_data_s *st_gdata; |
695 | 601 | ||
696 | pr_debug("%s: %d ", __func__, type); | 602 | pr_debug("%s: %d ", __func__, proto->chnl_id); |
697 | 603 | ||
698 | st_kim_ref(&st_gdata, 0); | 604 | st_kim_ref(&st_gdata, 0); |
699 | if (type < ST_BT || type >= ST_MAX) { | 605 | if (proto->chnl_id >= ST_MAX_CHANNELS) { |
700 | pr_err(" protocol %d not supported", type); | 606 | pr_err(" chnl_id %d not supported", proto->chnl_id); |
701 | return -EPROTONOSUPPORT; | 607 | return -EPROTONOSUPPORT; |
702 | } | 608 | } |
703 | 609 | ||
704 | spin_lock_irqsave(&st_gdata->lock, flags); | 610 | spin_lock_irqsave(&st_gdata->lock, flags); |
705 | 611 | ||
706 | if (st_gdata->list[type] == NULL) { | 612 | if (st_gdata->list[proto->chnl_id] == NULL) { |
707 | pr_err(" protocol %d not registered", type); | 613 | pr_err(" chnl_id %d not registered", proto->chnl_id); |
708 | spin_unlock_irqrestore(&st_gdata->lock, flags); | 614 | spin_unlock_irqrestore(&st_gdata->lock, flags); |
709 | return -EPROTONOSUPPORT; | 615 | return -EPROTONOSUPPORT; |
710 | } | 616 | } |
711 | 617 | ||
712 | st_gdata->protos_registered--; | 618 | st_gdata->protos_registered--; |
713 | st_gdata->list[type] = NULL; | 619 | remove_channel_from_table(st_gdata, proto); |
714 | |||
715 | /* kim ignores BT in the below function | ||
716 | * and handles the rest, BT is toggled | ||
717 | * only in kim_start and kim_stop | ||
718 | */ | ||
719 | st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); | ||
720 | spin_unlock_irqrestore(&st_gdata->lock, flags); | 620 | spin_unlock_irqrestore(&st_gdata->lock, flags); |
721 | 621 | ||
722 | if ((st_gdata->protos_registered == ST_EMPTY) && | 622 | if ((st_gdata->protos_registered == ST_EMPTY) && |
723 | (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { | 623 | (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { |
724 | pr_info(" all protocols unregistered "); | 624 | pr_info(" all chnl_ids unregistered "); |
725 | 625 | ||
726 | /* stop traffic on tty */ | 626 | /* stop traffic on tty */ |
727 | if (st_gdata->tty) { | 627 | if (st_gdata->tty) { |
@@ -729,7 +629,7 @@ long st_unregister(enum proto_type type) | |||
729 | stop_tty(st_gdata->tty); | 629 | stop_tty(st_gdata->tty); |
730 | } | 630 | } |
731 | 631 | ||
732 | /* all protocols now unregistered */ | 632 | /* all chnl_ids now unregistered */ |
733 | st_kim_stop(st_gdata->kim_data); | 633 | st_kim_stop(st_gdata->kim_data); |
734 | /* disable ST LL */ | 634 | /* disable ST LL */ |
735 | st_ll_disable(st_gdata); | 635 | st_ll_disable(st_gdata); |
@@ -744,37 +644,15 @@ long st_unregister(enum proto_type type) | |||
744 | long st_write(struct sk_buff *skb) | 644 | long st_write(struct sk_buff *skb) |
745 | { | 645 | { |
746 | struct st_data_s *st_gdata; | 646 | struct st_data_s *st_gdata; |
747 | #ifdef DEBUG | ||
748 | enum proto_type protoid = ST_MAX; | ||
749 | #endif | ||
750 | long len; | 647 | long len; |
751 | 648 | ||
752 | st_kim_ref(&st_gdata, 0); | 649 | st_kim_ref(&st_gdata, 0); |
753 | if (unlikely(skb == NULL || st_gdata == NULL | 650 | if (unlikely(skb == NULL || st_gdata == NULL |
754 | || st_gdata->tty == NULL)) { | 651 | || st_gdata->tty == NULL)) { |
755 | pr_err("data/tty unavailable to perform write"); | 652 | pr_err("data/tty unavailable to perform write"); |
756 | return -1; | 653 | return -EINVAL; |
757 | } | 654 | } |
758 | #ifdef DEBUG /* open-up skb to read the 1st byte */ | 655 | |
759 | switch (skb->data[0]) { | ||
760 | case HCI_COMMAND_PKT: | ||
761 | case HCI_ACLDATA_PKT: | ||
762 | case HCI_SCODATA_PKT: | ||
763 | protoid = ST_BT; | ||
764 | break; | ||
765 | case ST_FM_CH8_PKT: | ||
766 | protoid = ST_FM; | ||
767 | break; | ||
768 | case 0x09: | ||
769 | protoid = ST_GPS; | ||
770 | break; | ||
771 | } | ||
772 | if (unlikely(st_gdata->list[protoid] == NULL)) { | ||
773 | pr_err(" protocol %d not registered, and writing? ", | ||
774 | protoid); | ||
775 | return -1; | ||
776 | } | ||
777 | #endif | ||
778 | pr_debug("%d to be written", skb->len); | 656 | pr_debug("%d to be written", skb->len); |
779 | len = skb->len; | 657 | len = skb->len; |
780 | 658 | ||
@@ -824,7 +702,7 @@ static int st_tty_open(struct tty_struct *tty) | |||
824 | 702 | ||
825 | static void st_tty_close(struct tty_struct *tty) | 703 | static void st_tty_close(struct tty_struct *tty) |
826 | { | 704 | { |
827 | unsigned char i = ST_MAX; | 705 | unsigned char i = ST_MAX_CHANNELS; |
828 | unsigned long flags = 0; | 706 | unsigned long flags = 0; |
829 | struct st_data_s *st_gdata = tty->disc_data; | 707 | struct st_data_s *st_gdata = tty->disc_data; |
830 | 708 | ||
@@ -835,7 +713,7 @@ static void st_tty_close(struct tty_struct *tty) | |||
835 | * un-installed for some reason - what should be done ? | 713 | * un-installed for some reason - what should be done ? |
836 | */ | 714 | */ |
837 | spin_lock_irqsave(&st_gdata->lock, flags); | 715 | spin_lock_irqsave(&st_gdata->lock, flags); |
838 | for (i = ST_BT; i < ST_MAX; i++) { | 716 | for (i = ST_BT; i < ST_MAX_CHANNELS; i++) { |
839 | if (st_gdata->list[i] != NULL) | 717 | if (st_gdata->list[i] != NULL) |
840 | pr_err("%d not un-registered", i); | 718 | pr_err("%d not un-registered", i); |
841 | st_gdata->list[i] = NULL; | 719 | st_gdata->list[i] = NULL; |
@@ -869,7 +747,6 @@ static void st_tty_close(struct tty_struct *tty) | |||
869 | static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, | 747 | static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, |
870 | char *tty_flags, int count) | 748 | char *tty_flags, int count) |
871 | { | 749 | { |
872 | |||
873 | #ifdef VERBOSE | 750 | #ifdef VERBOSE |
874 | print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, | 751 | print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, |
875 | 16, 1, data, count, 0); | 752 | 16, 1, data, count, 0); |
@@ -960,7 +837,7 @@ int st_core_init(struct st_data_s **core_data) | |||
960 | err = tty_unregister_ldisc(N_TI_WL); | 837 | err = tty_unregister_ldisc(N_TI_WL); |
961 | if (err) | 838 | if (err) |
962 | pr_err("unable to un-register ldisc"); | 839 | pr_err("unable to un-register ldisc"); |
963 | return -1; | 840 | return err; |
964 | } | 841 | } |
965 | *core_data = st_gdata; | 842 | *core_data = st_gdata; |
966 | return 0; | 843 | return 0; |
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c index 73b6c8b0e869..9ee4c788aa69 100644 --- a/drivers/misc/ti-st/st_kim.c +++ b/drivers/misc/ti-st/st_kim.c | |||
@@ -30,50 +30,12 @@ | |||
30 | #include <linux/debugfs.h> | 30 | #include <linux/debugfs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
33 | #include <linux/rfkill.h> | 33 | #include <linux/tty.h> |
34 | |||
35 | /* understand BT events for fw response */ | ||
36 | #include <net/bluetooth/bluetooth.h> | ||
37 | #include <net/bluetooth/hci_core.h> | ||
38 | #include <net/bluetooth/hci.h> | ||
39 | 34 | ||
35 | #include <linux/skbuff.h> | ||
40 | #include <linux/ti_wilink_st.h> | 36 | #include <linux/ti_wilink_st.h> |
41 | 37 | ||
42 | 38 | ||
43 | static int kim_probe(struct platform_device *pdev); | ||
44 | static int kim_remove(struct platform_device *pdev); | ||
45 | |||
46 | /* KIM platform device driver structure */ | ||
47 | static struct platform_driver kim_platform_driver = { | ||
48 | .probe = kim_probe, | ||
49 | .remove = kim_remove, | ||
50 | /* TODO: ST driver power management during suspend/resume ? | ||
51 | */ | ||
52 | #if 0 | ||
53 | .suspend = kim_suspend, | ||
54 | .resume = kim_resume, | ||
55 | #endif | ||
56 | .driver = { | ||
57 | .name = "kim", | ||
58 | .owner = THIS_MODULE, | ||
59 | }, | ||
60 | }; | ||
61 | |||
62 | static int kim_toggle_radio(void*, bool); | ||
63 | static const struct rfkill_ops kim_rfkill_ops = { | ||
64 | .set_block = kim_toggle_radio, | ||
65 | }; | ||
66 | |||
67 | /* strings to be used for rfkill entries and by | ||
68 | * ST Core to be used for sysfs debug entry | ||
69 | */ | ||
70 | #define PROTO_ENTRY(type, name) name | ||
71 | const unsigned char *protocol_names[] = { | ||
72 | PROTO_ENTRY(ST_BT, "Bluetooth"), | ||
73 | PROTO_ENTRY(ST_FM, "FM"), | ||
74 | PROTO_ENTRY(ST_GPS, "GPS"), | ||
75 | }; | ||
76 | |||
77 | #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ | 39 | #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ |
78 | static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; | 40 | static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; |
79 | 41 | ||
@@ -134,7 +96,7 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len) | |||
134 | /* Packet header has non-zero payload length and | 96 | /* Packet header has non-zero payload length and |
135 | * we have enough space in created skb. Lets read | 97 | * we have enough space in created skb. Lets read |
136 | * payload data */ | 98 | * payload data */ |
137 | kim_gdata->rx_state = ST_BT_W4_DATA; | 99 | kim_gdata->rx_state = ST_W4_DATA; |
138 | kim_gdata->rx_count = len; | 100 | kim_gdata->rx_count = len; |
139 | return len; | 101 | return len; |
140 | } | 102 | } |
@@ -158,8 +120,8 @@ void kim_int_recv(struct kim_data_s *kim_gdata, | |||
158 | const unsigned char *data, long count) | 120 | const unsigned char *data, long count) |
159 | { | 121 | { |
160 | const unsigned char *ptr; | 122 | const unsigned char *ptr; |
161 | struct hci_event_hdr *eh; | ||
162 | int len = 0, type = 0; | 123 | int len = 0, type = 0; |
124 | unsigned char *plen; | ||
163 | 125 | ||
164 | pr_debug("%s", __func__); | 126 | pr_debug("%s", __func__); |
165 | /* Decode received bytes here */ | 127 | /* Decode received bytes here */ |
@@ -183,29 +145,27 @@ void kim_int_recv(struct kim_data_s *kim_gdata, | |||
183 | /* Check ST RX state machine , where are we? */ | 145 | /* Check ST RX state machine , where are we? */ |
184 | switch (kim_gdata->rx_state) { | 146 | switch (kim_gdata->rx_state) { |
185 | /* Waiting for complete packet ? */ | 147 | /* Waiting for complete packet ? */ |
186 | case ST_BT_W4_DATA: | 148 | case ST_W4_DATA: |
187 | pr_debug("Complete pkt received"); | 149 | pr_debug("Complete pkt received"); |
188 | validate_firmware_response(kim_gdata); | 150 | validate_firmware_response(kim_gdata); |
189 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; | 151 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; |
190 | kim_gdata->rx_skb = NULL; | 152 | kim_gdata->rx_skb = NULL; |
191 | continue; | 153 | continue; |
192 | /* Waiting for Bluetooth event header ? */ | 154 | /* Waiting for Bluetooth event header ? */ |
193 | case ST_BT_W4_EVENT_HDR: | 155 | case ST_W4_HEADER: |
194 | eh = (struct hci_event_hdr *)kim_gdata-> | 156 | plen = |
195 | rx_skb->data; | 157 | (unsigned char *)&kim_gdata->rx_skb->data[1]; |
196 | pr_debug("Event header: evt 0x%2.2x" | 158 | pr_debug("event hdr: plen 0x%02x\n", *plen); |
197 | "plen %d", eh->evt, eh->plen); | 159 | kim_check_data_len(kim_gdata, *plen); |
198 | kim_check_data_len(kim_gdata, eh->plen); | ||
199 | continue; | 160 | continue; |
200 | } /* end of switch */ | 161 | } /* end of switch */ |
201 | } /* end of if rx_state */ | 162 | } /* end of if rx_state */ |
202 | switch (*ptr) { | 163 | switch (*ptr) { |
203 | /* Bluetooth event packet? */ | 164 | /* Bluetooth event packet? */ |
204 | case HCI_EVENT_PKT: | 165 | case 0x04: |
205 | pr_info("Event packet"); | 166 | kim_gdata->rx_state = ST_W4_HEADER; |
206 | kim_gdata->rx_state = ST_BT_W4_EVENT_HDR; | 167 | kim_gdata->rx_count = 2; |
207 | kim_gdata->rx_count = HCI_EVENT_HDR_SIZE; | 168 | type = *ptr; |
208 | type = HCI_EVENT_PKT; | ||
209 | break; | 169 | break; |
210 | default: | 170 | default: |
211 | pr_info("unknown packet"); | 171 | pr_info("unknown packet"); |
@@ -216,16 +176,18 @@ void kim_int_recv(struct kim_data_s *kim_gdata, | |||
216 | ptr++; | 176 | ptr++; |
217 | count--; | 177 | count--; |
218 | kim_gdata->rx_skb = | 178 | kim_gdata->rx_skb = |
219 | bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); | 179 | alloc_skb(1024+8, GFP_ATOMIC); |
220 | if (!kim_gdata->rx_skb) { | 180 | if (!kim_gdata->rx_skb) { |
221 | pr_err("can't allocate mem for new packet"); | 181 | pr_err("can't allocate mem for new packet"); |
222 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; | 182 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; |
223 | kim_gdata->rx_count = 0; | 183 | kim_gdata->rx_count = 0; |
224 | return; | 184 | return; |
225 | } | 185 | } |
226 | bt_cb(kim_gdata->rx_skb)->pkt_type = type; | 186 | skb_reserve(kim_gdata->rx_skb, 8); |
187 | kim_gdata->rx_skb->cb[0] = 4; | ||
188 | kim_gdata->rx_skb->cb[1] = 0; | ||
189 | |||
227 | } | 190 | } |
228 | pr_info("done %s", __func__); | ||
229 | return; | 191 | return; |
230 | } | 192 | } |
231 | 193 | ||
@@ -239,13 +201,13 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name) | |||
239 | INIT_COMPLETION(kim_gdata->kim_rcvd); | 201 | INIT_COMPLETION(kim_gdata->kim_rcvd); |
240 | if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { | 202 | if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { |
241 | pr_err("kim: couldn't write 4 bytes"); | 203 | pr_err("kim: couldn't write 4 bytes"); |
242 | return -1; | 204 | return -EIO; |
243 | } | 205 | } |
244 | 206 | ||
245 | if (!wait_for_completion_timeout | 207 | if (!wait_for_completion_timeout |
246 | (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { | 208 | (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { |
247 | pr_err(" waiting for ver info- timed out "); | 209 | pr_err(" waiting for ver info- timed out "); |
248 | return -1; | 210 | return -ETIMEDOUT; |
249 | } | 211 | } |
250 | 212 | ||
251 | version = | 213 | version = |
@@ -270,6 +232,26 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name) | |||
270 | return 0; | 232 | return 0; |
271 | } | 233 | } |
272 | 234 | ||
235 | void skip_change_remote_baud(unsigned char **ptr, long *len) | ||
236 | { | ||
237 | unsigned char *nxt_action, *cur_action; | ||
238 | cur_action = *ptr; | ||
239 | |||
240 | nxt_action = cur_action + sizeof(struct bts_action) + | ||
241 | ((struct bts_action *) cur_action)->size; | ||
242 | |||
243 | if (((struct bts_action *) nxt_action)->type != ACTION_WAIT_EVENT) { | ||
244 | pr_err("invalid action after change remote baud command"); | ||
245 | } else { | ||
246 | *ptr = *ptr + sizeof(struct bts_action) + | ||
247 | ((struct bts_action *)nxt_action)->size; | ||
248 | *len = *len - (sizeof(struct bts_action) + | ||
249 | ((struct bts_action *)nxt_action)->size); | ||
250 | /* warn user on not commenting these in firmware */ | ||
251 | pr_warn("skipping the wait event of change remote baud"); | ||
252 | } | ||
253 | } | ||
254 | |||
273 | /** | 255 | /** |
274 | * download_firmware - | 256 | * download_firmware - |
275 | * internal function which parses through the .bts firmware | 257 | * internal function which parses through the .bts firmware |
@@ -282,6 +264,9 @@ static long download_firmware(struct kim_data_s *kim_gdata) | |||
282 | unsigned char *ptr = NULL; | 264 | unsigned char *ptr = NULL; |
283 | unsigned char *action_ptr = NULL; | 265 | unsigned char *action_ptr = NULL; |
284 | unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */ | 266 | unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */ |
267 | int wr_room_space; | ||
268 | int cmd_size; | ||
269 | unsigned long timeout; | ||
285 | 270 | ||
286 | err = read_local_version(kim_gdata, bts_scr_name); | 271 | err = read_local_version(kim_gdata, bts_scr_name); |
287 | if (err != 0) { | 272 | if (err != 0) { |
@@ -295,7 +280,7 @@ static long download_firmware(struct kim_data_s *kim_gdata) | |||
295 | (kim_gdata->fw_entry->size == 0))) { | 280 | (kim_gdata->fw_entry->size == 0))) { |
296 | pr_err(" request_firmware failed(errno %ld) for %s", err, | 281 | pr_err(" request_firmware failed(errno %ld) for %s", err, |
297 | bts_scr_name); | 282 | bts_scr_name); |
298 | return -1; | 283 | return -EINVAL; |
299 | } | 284 | } |
300 | ptr = (void *)kim_gdata->fw_entry->data; | 285 | ptr = (void *)kim_gdata->fw_entry->data; |
301 | len = kim_gdata->fw_entry->size; | 286 | len = kim_gdata->fw_entry->size; |
@@ -318,29 +303,72 @@ static long download_firmware(struct kim_data_s *kim_gdata) | |||
318 | 0xFF36)) { | 303 | 0xFF36)) { |
319 | /* ignore remote change | 304 | /* ignore remote change |
320 | * baud rate HCI VS command */ | 305 | * baud rate HCI VS command */ |
321 | pr_err | 306 | pr_warn("change remote baud" |
322 | (" change remote baud" | ||
323 | " rate command in firmware"); | 307 | " rate command in firmware"); |
308 | skip_change_remote_baud(&ptr, &len); | ||
324 | break; | 309 | break; |
325 | } | 310 | } |
311 | /* | ||
312 | * Make sure we have enough free space in uart | ||
313 | * tx buffer to write current firmware command | ||
314 | */ | ||
315 | cmd_size = ((struct bts_action *)ptr)->size; | ||
316 | timeout = jiffies + msecs_to_jiffies(CMD_WR_TIME); | ||
317 | do { | ||
318 | wr_room_space = | ||
319 | st_get_uart_wr_room(kim_gdata->core_data); | ||
320 | if (wr_room_space < 0) { | ||
321 | pr_err("Unable to get free " | ||
322 | "space info from uart tx buffer"); | ||
323 | release_firmware(kim_gdata->fw_entry); | ||
324 | return wr_room_space; | ||
325 | } | ||
326 | mdelay(1); /* wait 1ms before checking room */ | ||
327 | } while ((wr_room_space < cmd_size) && | ||
328 | time_before(jiffies, timeout)); | ||
329 | |||
330 | /* Timeout happened ? */ | ||
331 | if (time_after_eq(jiffies, timeout)) { | ||
332 | pr_err("Timeout while waiting for free " | ||
333 | "free space in uart tx buffer"); | ||
334 | release_firmware(kim_gdata->fw_entry); | ||
335 | return -ETIMEDOUT; | ||
336 | } | ||
326 | 337 | ||
327 | INIT_COMPLETION(kim_gdata->kim_rcvd); | 338 | /* |
339 | * Free space found in uart buffer, call st_int_write | ||
340 | * to send current firmware command to the uart tx | ||
341 | * buffer. | ||
342 | */ | ||
328 | err = st_int_write(kim_gdata->core_data, | 343 | err = st_int_write(kim_gdata->core_data, |
329 | ((struct bts_action_send *)action_ptr)->data, | 344 | ((struct bts_action_send *)action_ptr)->data, |
330 | ((struct bts_action *)ptr)->size); | 345 | ((struct bts_action *)ptr)->size); |
331 | if (unlikely(err < 0)) { | 346 | if (unlikely(err < 0)) { |
332 | release_firmware(kim_gdata->fw_entry); | 347 | release_firmware(kim_gdata->fw_entry); |
333 | return -1; | 348 | return err; |
334 | } | 349 | } |
350 | /* | ||
351 | * Check number of bytes written to the uart tx buffer | ||
352 | * and requested command write size | ||
353 | */ | ||
354 | if (err != cmd_size) { | ||
355 | pr_err("Number of bytes written to uart " | ||
356 | "tx buffer are not matching with " | ||
357 | "requested cmd write size"); | ||
358 | release_firmware(kim_gdata->fw_entry); | ||
359 | return -EIO; | ||
360 | } | ||
361 | break; | ||
362 | case ACTION_WAIT_EVENT: /* wait */ | ||
335 | if (!wait_for_completion_timeout | 363 | if (!wait_for_completion_timeout |
336 | (&kim_gdata->kim_rcvd, | 364 | (&kim_gdata->kim_rcvd, |
337 | msecs_to_jiffies(CMD_RESP_TIME))) { | 365 | msecs_to_jiffies(CMD_RESP_TIME))) { |
338 | pr_err | 366 | pr_err("response timeout during fw download "); |
339 | (" response timeout during fw download "); | ||
340 | /* timed out */ | 367 | /* timed out */ |
341 | release_firmware(kim_gdata->fw_entry); | 368 | release_firmware(kim_gdata->fw_entry); |
342 | return -1; | 369 | return -ETIMEDOUT; |
343 | } | 370 | } |
371 | INIT_COMPLETION(kim_gdata->kim_rcvd); | ||
344 | break; | 372 | break; |
345 | case ACTION_DELAY: /* sleep */ | 373 | case ACTION_DELAY: /* sleep */ |
346 | pr_info("sleep command in scr"); | 374 | pr_info("sleep command in scr"); |
@@ -362,50 +390,6 @@ static long download_firmware(struct kim_data_s *kim_gdata) | |||
362 | 390 | ||
363 | /**********************************************************************/ | 391 | /**********************************************************************/ |
364 | /* functions called from ST core */ | 392 | /* functions called from ST core */ |
365 | /* function to toggle the GPIO | ||
366 | * needs to know whether the GPIO is active high or active low | ||
367 | */ | ||
368 | void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state) | ||
369 | { | ||
370 | struct platform_device *kim_pdev; | ||
371 | struct kim_data_s *kim_gdata; | ||
372 | pr_info(" %s ", __func__); | ||
373 | |||
374 | kim_pdev = st_get_plat_device(0); | ||
375 | kim_gdata = dev_get_drvdata(&kim_pdev->dev); | ||
376 | |||
377 | if (kim_gdata->gpios[type] == -1) { | ||
378 | pr_info(" gpio not requested for protocol %s", | ||
379 | protocol_names[type]); | ||
380 | return; | ||
381 | } | ||
382 | switch (type) { | ||
383 | case ST_BT: | ||
384 | /*Do Nothing */ | ||
385 | break; | ||
386 | |||
387 | case ST_FM: | ||
388 | if (state == KIM_GPIO_ACTIVE) | ||
389 | gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW); | ||
390 | else | ||
391 | gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH); | ||
392 | break; | ||
393 | |||
394 | case ST_GPS: | ||
395 | if (state == KIM_GPIO_ACTIVE) | ||
396 | gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH); | ||
397 | else | ||
398 | gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW); | ||
399 | break; | ||
400 | |||
401 | case ST_MAX: | ||
402 | default: | ||
403 | break; | ||
404 | } | ||
405 | |||
406 | return; | ||
407 | } | ||
408 | |||
409 | /* called from ST Core, when REG_IN_PROGRESS (registration in progress) | 393 | /* called from ST Core, when REG_IN_PROGRESS (registration in progress) |
410 | * can be because of | 394 | * can be because of |
411 | * 1. response to read local version | 395 | * 1. response to read local version |
@@ -416,7 +400,6 @@ void st_kim_recv(void *disc_data, const unsigned char *data, long count) | |||
416 | struct st_data_s *st_gdata = (struct st_data_s *)disc_data; | 400 | struct st_data_s *st_gdata = (struct st_data_s *)disc_data; |
417 | struct kim_data_s *kim_gdata = st_gdata->kim_data; | 401 | struct kim_data_s *kim_gdata = st_gdata->kim_data; |
418 | 402 | ||
419 | pr_info(" %s ", __func__); | ||
420 | /* copy to local buffer */ | 403 | /* copy to local buffer */ |
421 | if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { | 404 | if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { |
422 | /* must be the read_ver_cmd */ | 405 | /* must be the read_ver_cmd */ |
@@ -455,35 +438,28 @@ long st_kim_start(void *kim_data) | |||
455 | pr_info(" %s", __func__); | 438 | pr_info(" %s", __func__); |
456 | 439 | ||
457 | do { | 440 | do { |
458 | /* TODO: this is only because rfkill sub-system | ||
459 | * doesn't send events to user-space if the state | ||
460 | * isn't changed | ||
461 | */ | ||
462 | rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); | ||
463 | /* Configure BT nShutdown to HIGH state */ | 441 | /* Configure BT nShutdown to HIGH state */ |
464 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); | 442 | gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); |
465 | mdelay(5); /* FIXME: a proper toggle */ | 443 | mdelay(5); /* FIXME: a proper toggle */ |
466 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); | 444 | gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH); |
467 | mdelay(100); | 445 | mdelay(100); |
468 | /* re-initialize the completion */ | 446 | /* re-initialize the completion */ |
469 | INIT_COMPLETION(kim_gdata->ldisc_installed); | 447 | INIT_COMPLETION(kim_gdata->ldisc_installed); |
470 | #if 0 /* older way of signalling user-space UIM */ | 448 | /* send notification to UIM */ |
471 | /* send signal to UIM */ | 449 | kim_gdata->ldisc_install = 1; |
472 | err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0); | 450 | pr_info("ldisc_install = 1"); |
473 | if (err != 0) { | 451 | sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, |
474 | pr_info(" sending SIGUSR2 to uim failed %ld", err); | 452 | NULL, "install"); |
475 | err = -1; | ||
476 | continue; | ||
477 | } | ||
478 | #endif | ||
479 | /* unblock and send event to UIM via /dev/rfkill */ | ||
480 | rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0); | ||
481 | /* wait for ldisc to be installed */ | 453 | /* wait for ldisc to be installed */ |
482 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, | 454 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, |
483 | msecs_to_jiffies(LDISC_TIME)); | 455 | msecs_to_jiffies(LDISC_TIME)); |
484 | if (!err) { /* timeout */ | 456 | if (!err) { /* timeout */ |
485 | pr_err("line disc installation timed out "); | 457 | pr_err("line disc installation timed out "); |
486 | err = -1; | 458 | kim_gdata->ldisc_install = 0; |
459 | pr_info("ldisc_install = 0"); | ||
460 | sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, | ||
461 | NULL, "install"); | ||
462 | err = -ETIMEDOUT; | ||
487 | continue; | 463 | continue; |
488 | } else { | 464 | } else { |
489 | /* ldisc installed now */ | 465 | /* ldisc installed now */ |
@@ -491,6 +467,10 @@ long st_kim_start(void *kim_data) | |||
491 | err = download_firmware(kim_gdata); | 467 | err = download_firmware(kim_gdata); |
492 | if (err != 0) { | 468 | if (err != 0) { |
493 | pr_err("download firmware failed"); | 469 | pr_err("download firmware failed"); |
470 | kim_gdata->ldisc_install = 0; | ||
471 | pr_info("ldisc_install = 0"); | ||
472 | sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, | ||
473 | NULL, "install"); | ||
494 | continue; | 474 | continue; |
495 | } else { /* on success don't retry */ | 475 | } else { /* on success don't retry */ |
496 | break; | 476 | break; |
@@ -510,31 +490,30 @@ long st_kim_stop(void *kim_data) | |||
510 | struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; | 490 | struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; |
511 | 491 | ||
512 | INIT_COMPLETION(kim_gdata->ldisc_installed); | 492 | INIT_COMPLETION(kim_gdata->ldisc_installed); |
513 | #if 0 /* older way of signalling user-space UIM */ | 493 | |
514 | /* send signal to UIM */ | 494 | /* Flush any pending characters in the driver and discipline. */ |
515 | err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1); | 495 | tty_ldisc_flush(kim_gdata->core_data->tty); |
516 | if (err != 0) { | 496 | tty_driver_flush_buffer(kim_gdata->core_data->tty); |
517 | pr_err("sending SIGUSR2 to uim failed %ld", err); | 497 | |
518 | return -1; | 498 | /* send uninstall notification to UIM */ |
519 | } | 499 | pr_info("ldisc_install = 0"); |
520 | #endif | 500 | kim_gdata->ldisc_install = 0; |
521 | /* set BT rfkill to be blocked */ | 501 | sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install"); |
522 | err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); | ||
523 | 502 | ||
524 | /* wait for ldisc to be un-installed */ | 503 | /* wait for ldisc to be un-installed */ |
525 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, | 504 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, |
526 | msecs_to_jiffies(LDISC_TIME)); | 505 | msecs_to_jiffies(LDISC_TIME)); |
527 | if (!err) { /* timeout */ | 506 | if (!err) { /* timeout */ |
528 | pr_err(" timed out waiting for ldisc to be un-installed"); | 507 | pr_err(" timed out waiting for ldisc to be un-installed"); |
529 | return -1; | 508 | return -ETIMEDOUT; |
530 | } | 509 | } |
531 | 510 | ||
532 | /* By default configure BT nShutdown to LOW state */ | 511 | /* By default configure BT nShutdown to LOW state */ |
533 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); | 512 | gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); |
534 | mdelay(1); | 513 | mdelay(1); |
535 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); | 514 | gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH); |
536 | mdelay(1); | 515 | mdelay(1); |
537 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); | 516 | gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); |
538 | return err; | 517 | return err; |
539 | } | 518 | } |
540 | 519 | ||
@@ -558,33 +537,59 @@ static int show_list(struct seq_file *s, void *unused) | |||
558 | return 0; | 537 | return 0; |
559 | } | 538 | } |
560 | 539 | ||
561 | /* function called from rfkill subsystem, when someone from | 540 | static ssize_t show_install(struct device *dev, |
562 | * user space would write 0/1 on the sysfs entry | 541 | struct device_attribute *attr, char *buf) |
563 | * /sys/class/rfkill/rfkill0,1,3/state | ||
564 | */ | ||
565 | static int kim_toggle_radio(void *data, bool blocked) | ||
566 | { | 542 | { |
567 | enum proto_type type = *((enum proto_type *)data); | 543 | struct kim_data_s *kim_data = dev_get_drvdata(dev); |
568 | pr_debug(" %s: %d ", __func__, type); | 544 | return sprintf(buf, "%d\n", kim_data->ldisc_install); |
569 | |||
570 | switch (type) { | ||
571 | case ST_BT: | ||
572 | /* do nothing */ | ||
573 | break; | ||
574 | case ST_FM: | ||
575 | case ST_GPS: | ||
576 | if (blocked) | ||
577 | st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); | ||
578 | else | ||
579 | st_kim_chip_toggle(type, KIM_GPIO_ACTIVE); | ||
580 | break; | ||
581 | case ST_MAX: | ||
582 | pr_err(" wrong proto type "); | ||
583 | break; | ||
584 | } | ||
585 | return 0; | ||
586 | } | 545 | } |
587 | 546 | ||
547 | static ssize_t show_dev_name(struct device *dev, | ||
548 | struct device_attribute *attr, char *buf) | ||
549 | { | ||
550 | struct kim_data_s *kim_data = dev_get_drvdata(dev); | ||
551 | return sprintf(buf, "%s\n", kim_data->dev_name); | ||
552 | } | ||
553 | |||
554 | static ssize_t show_baud_rate(struct device *dev, | ||
555 | struct device_attribute *attr, char *buf) | ||
556 | { | ||
557 | struct kim_data_s *kim_data = dev_get_drvdata(dev); | ||
558 | return sprintf(buf, "%ld\n", kim_data->baud_rate); | ||
559 | } | ||
560 | |||
561 | static ssize_t show_flow_cntrl(struct device *dev, | ||
562 | struct device_attribute *attr, char *buf) | ||
563 | { | ||
564 | struct kim_data_s *kim_data = dev_get_drvdata(dev); | ||
565 | return sprintf(buf, "%d\n", kim_data->flow_cntrl); | ||
566 | } | ||
567 | |||
568 | /* structures specific for sysfs entries */ | ||
569 | static struct kobj_attribute ldisc_install = | ||
570 | __ATTR(install, 0444, (void *)show_install, NULL); | ||
571 | |||
572 | static struct kobj_attribute uart_dev_name = | ||
573 | __ATTR(dev_name, 0444, (void *)show_dev_name, NULL); | ||
574 | |||
575 | static struct kobj_attribute uart_baud_rate = | ||
576 | __ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL); | ||
577 | |||
578 | static struct kobj_attribute uart_flow_cntrl = | ||
579 | __ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL); | ||
580 | |||
581 | static struct attribute *uim_attrs[] = { | ||
582 | &ldisc_install.attr, | ||
583 | &uart_dev_name.attr, | ||
584 | &uart_baud_rate.attr, | ||
585 | &uart_flow_cntrl.attr, | ||
586 | NULL, | ||
587 | }; | ||
588 | |||
589 | static struct attribute_group uim_attr_grp = { | ||
590 | .attrs = uim_attrs, | ||
591 | }; | ||
592 | |||
588 | /** | 593 | /** |
589 | * st_kim_ref - reference the core's data | 594 | * st_kim_ref - reference the core's data |
590 | * This references the per-ST platform device in the arch/xx/ | 595 | * This references the per-ST platform device in the arch/xx/ |
@@ -637,9 +642,8 @@ struct dentry *kim_debugfs_dir; | |||
637 | static int kim_probe(struct platform_device *pdev) | 642 | static int kim_probe(struct platform_device *pdev) |
638 | { | 643 | { |
639 | long status; | 644 | long status; |
640 | long proto; | ||
641 | long *gpios = pdev->dev.platform_data; | ||
642 | struct kim_data_s *kim_gdata; | 645 | struct kim_data_s *kim_gdata; |
646 | struct ti_st_plat_data *pdata = pdev->dev.platform_data; | ||
643 | 647 | ||
644 | if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { | 648 | if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { |
645 | /* multiple devices could exist */ | 649 | /* multiple devices could exist */ |
@@ -659,44 +663,24 @@ static int kim_probe(struct platform_device *pdev) | |||
659 | status = st_core_init(&kim_gdata->core_data); | 663 | status = st_core_init(&kim_gdata->core_data); |
660 | if (status != 0) { | 664 | if (status != 0) { |
661 | pr_err(" ST core init failed"); | 665 | pr_err(" ST core init failed"); |
662 | return -1; | 666 | return -EIO; |
663 | } | 667 | } |
664 | /* refer to itself */ | 668 | /* refer to itself */ |
665 | kim_gdata->core_data->kim_data = kim_gdata; | 669 | kim_gdata->core_data->kim_data = kim_gdata; |
666 | 670 | ||
667 | for (proto = 0; proto < ST_MAX; proto++) { | 671 | /* Claim the chip enable nShutdown gpio from the system */ |
668 | kim_gdata->gpios[proto] = gpios[proto]; | 672 | kim_gdata->nshutdown = pdata->nshutdown_gpio; |
669 | pr_info(" %ld gpio to be requested", gpios[proto]); | 673 | status = gpio_request(kim_gdata->nshutdown, "kim"); |
674 | if (unlikely(status)) { | ||
675 | pr_err(" gpio %ld request failed ", kim_gdata->nshutdown); | ||
676 | return status; | ||
670 | } | 677 | } |
671 | 678 | ||
672 | for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { | 679 | /* Configure nShutdown GPIO as output=0 */ |
673 | /* Claim the Bluetooth/FM/GPIO | 680 | status = gpio_direction_output(kim_gdata->nshutdown, 0); |
674 | * nShutdown gpio from the system | 681 | if (unlikely(status)) { |
675 | */ | 682 | pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown); |
676 | status = gpio_request(gpios[proto], "kim"); | 683 | return status; |
677 | if (unlikely(status)) { | ||
678 | pr_err(" gpio %ld request failed ", gpios[proto]); | ||
679 | proto -= 1; | ||
680 | while (proto >= 0) { | ||
681 | if (gpios[proto] != -1) | ||
682 | gpio_free(gpios[proto]); | ||
683 | } | ||
684 | return status; | ||
685 | } | ||
686 | |||
687 | /* Configure nShutdown GPIO as output=0 */ | ||
688 | status = | ||
689 | gpio_direction_output(gpios[proto], 0); | ||
690 | if (unlikely(status)) { | ||
691 | pr_err(" unable to configure gpio %ld", | ||
692 | gpios[proto]); | ||
693 | proto -= 1; | ||
694 | while (proto >= 0) { | ||
695 | if (gpios[proto] != -1) | ||
696 | gpio_free(gpios[proto]); | ||
697 | } | ||
698 | return status; | ||
699 | } | ||
700 | } | 684 | } |
701 | /* get reference of pdev for request_firmware | 685 | /* get reference of pdev for request_firmware |
702 | */ | 686 | */ |
@@ -704,34 +688,23 @@ static int kim_probe(struct platform_device *pdev) | |||
704 | init_completion(&kim_gdata->kim_rcvd); | 688 | init_completion(&kim_gdata->kim_rcvd); |
705 | init_completion(&kim_gdata->ldisc_installed); | 689 | init_completion(&kim_gdata->ldisc_installed); |
706 | 690 | ||
707 | for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { | 691 | status = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp); |
708 | /* TODO: should all types be rfkill_type_bt ? */ | 692 | if (status) { |
709 | kim_gdata->rf_protos[proto] = proto; | 693 | pr_err("failed to create sysfs entries"); |
710 | kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto], | 694 | return status; |
711 | &pdev->dev, RFKILL_TYPE_BLUETOOTH, | ||
712 | &kim_rfkill_ops, &kim_gdata->rf_protos[proto]); | ||
713 | if (kim_gdata->rfkill[proto] == NULL) { | ||
714 | pr_err("cannot create rfkill entry for gpio %ld", | ||
715 | gpios[proto]); | ||
716 | continue; | ||
717 | } | ||
718 | /* block upon creation */ | ||
719 | rfkill_init_sw_state(kim_gdata->rfkill[proto], 1); | ||
720 | status = rfkill_register(kim_gdata->rfkill[proto]); | ||
721 | if (unlikely(status)) { | ||
722 | pr_err("rfkill registration failed for gpio %ld", | ||
723 | gpios[proto]); | ||
724 | rfkill_unregister(kim_gdata->rfkill[proto]); | ||
725 | continue; | ||
726 | } | ||
727 | pr_info("rfkill entry created for %ld", gpios[proto]); | ||
728 | } | 695 | } |
729 | 696 | ||
697 | /* copying platform data */ | ||
698 | strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN); | ||
699 | kim_gdata->flow_cntrl = pdata->flow_cntrl; | ||
700 | kim_gdata->baud_rate = pdata->baud_rate; | ||
701 | pr_info("sysfs entries created\n"); | ||
702 | |||
730 | kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); | 703 | kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); |
731 | if (IS_ERR(kim_debugfs_dir)) { | 704 | if (IS_ERR(kim_debugfs_dir)) { |
732 | pr_err(" debugfs entries creation failed "); | 705 | pr_err(" debugfs entries creation failed "); |
733 | kim_debugfs_dir = NULL; | 706 | kim_debugfs_dir = NULL; |
734 | return -1; | 707 | return -EIO; |
735 | } | 708 | } |
736 | 709 | ||
737 | debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, | 710 | debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, |
@@ -744,25 +717,22 @@ static int kim_probe(struct platform_device *pdev) | |||
744 | 717 | ||
745 | static int kim_remove(struct platform_device *pdev) | 718 | static int kim_remove(struct platform_device *pdev) |
746 | { | 719 | { |
747 | /* free the GPIOs requested | 720 | /* free the GPIOs requested */ |
748 | */ | 721 | struct ti_st_plat_data *pdata = pdev->dev.platform_data; |
749 | long *gpios = pdev->dev.platform_data; | ||
750 | long proto; | ||
751 | struct kim_data_s *kim_gdata; | 722 | struct kim_data_s *kim_gdata; |
752 | 723 | ||
753 | kim_gdata = dev_get_drvdata(&pdev->dev); | 724 | kim_gdata = dev_get_drvdata(&pdev->dev); |
754 | 725 | ||
755 | for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { | 726 | /* Free the Bluetooth/FM/GPIO |
756 | /* Claim the Bluetooth/FM/GPIO | 727 | * nShutdown gpio from the system |
757 | * nShutdown gpio from the system | 728 | */ |
758 | */ | 729 | gpio_free(pdata->nshutdown_gpio); |
759 | gpio_free(gpios[proto]); | 730 | pr_info("nshutdown GPIO Freed"); |
760 | rfkill_unregister(kim_gdata->rfkill[proto]); | 731 | |
761 | rfkill_destroy(kim_gdata->rfkill[proto]); | ||
762 | kim_gdata->rfkill[proto] = NULL; | ||
763 | } | ||
764 | pr_info("kim: GPIO Freed"); | ||
765 | debugfs_remove_recursive(kim_debugfs_dir); | 732 | debugfs_remove_recursive(kim_debugfs_dir); |
733 | sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp); | ||
734 | pr_info("sysfs entries removed"); | ||
735 | |||
766 | kim_gdata->kim_pdev = NULL; | 736 | kim_gdata->kim_pdev = NULL; |
767 | st_core_exit(kim_gdata->core_data); | 737 | st_core_exit(kim_gdata->core_data); |
768 | 738 | ||
@@ -771,23 +741,46 @@ static int kim_remove(struct platform_device *pdev) | |||
771 | return 0; | 741 | return 0; |
772 | } | 742 | } |
773 | 743 | ||
744 | int kim_suspend(struct platform_device *pdev, pm_message_t state) | ||
745 | { | ||
746 | struct ti_st_plat_data *pdata = pdev->dev.platform_data; | ||
747 | |||
748 | if (pdata->suspend) | ||
749 | return pdata->suspend(pdev, state); | ||
750 | |||
751 | return -EOPNOTSUPP; | ||
752 | } | ||
753 | |||
754 | int kim_resume(struct platform_device *pdev) | ||
755 | { | ||
756 | struct ti_st_plat_data *pdata = pdev->dev.platform_data; | ||
757 | |||
758 | if (pdata->resume) | ||
759 | return pdata->resume(pdev); | ||
760 | |||
761 | return -EOPNOTSUPP; | ||
762 | } | ||
763 | |||
774 | /**********************************************************************/ | 764 | /**********************************************************************/ |
775 | /* entry point for ST KIM module, called in from ST Core */ | 765 | /* entry point for ST KIM module, called in from ST Core */ |
766 | static struct platform_driver kim_platform_driver = { | ||
767 | .probe = kim_probe, | ||
768 | .remove = kim_remove, | ||
769 | .suspend = kim_suspend, | ||
770 | .resume = kim_resume, | ||
771 | .driver = { | ||
772 | .name = "kim", | ||
773 | .owner = THIS_MODULE, | ||
774 | }, | ||
775 | }; | ||
776 | 776 | ||
777 | static int __init st_kim_init(void) | 777 | static int __init st_kim_init(void) |
778 | { | 778 | { |
779 | long ret = 0; | 779 | return platform_driver_register(&kim_platform_driver); |
780 | ret = platform_driver_register(&kim_platform_driver); | ||
781 | if (ret != 0) { | ||
782 | pr_err("platform drv registration failed"); | ||
783 | return -1; | ||
784 | } | ||
785 | return 0; | ||
786 | } | 780 | } |
787 | 781 | ||
788 | static void __exit st_kim_deinit(void) | 782 | static void __exit st_kim_deinit(void) |
789 | { | 783 | { |
790 | /* the following returns void */ | ||
791 | platform_driver_unregister(&kim_platform_driver); | 784 | platform_driver_unregister(&kim_platform_driver); |
792 | } | 785 | } |
793 | 786 | ||
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c index 2bda8dea15b0..3f2495138855 100644 --- a/drivers/misc/ti-st/st_ll.c +++ b/drivers/misc/ti-st/st_ll.c | |||
@@ -30,7 +30,7 @@ static void send_ll_cmd(struct st_data_s *st_data, | |||
30 | unsigned char cmd) | 30 | unsigned char cmd) |
31 | { | 31 | { |
32 | 32 | ||
33 | pr_info("%s: writing %x", __func__, cmd); | 33 | pr_debug("%s: writing %x", __func__, cmd); |
34 | st_int_write(st_data, &cmd, 1); | 34 | st_int_write(st_data, &cmd, 1); |
35 | return; | 35 | return; |
36 | } | 36 | } |
@@ -114,23 +114,23 @@ unsigned long st_ll_sleep_state(struct st_data_s *st_data, | |||
114 | { | 114 | { |
115 | switch (cmd) { | 115 | switch (cmd) { |
116 | case LL_SLEEP_IND: /* sleep ind */ | 116 | case LL_SLEEP_IND: /* sleep ind */ |
117 | pr_info("sleep indication recvd"); | 117 | pr_debug("sleep indication recvd"); |
118 | ll_device_want_to_sleep(st_data); | 118 | ll_device_want_to_sleep(st_data); |
119 | break; | 119 | break; |
120 | case LL_SLEEP_ACK: /* sleep ack */ | 120 | case LL_SLEEP_ACK: /* sleep ack */ |
121 | pr_err("sleep ack rcvd: host shouldn't"); | 121 | pr_err("sleep ack rcvd: host shouldn't"); |
122 | break; | 122 | break; |
123 | case LL_WAKE_UP_IND: /* wake ind */ | 123 | case LL_WAKE_UP_IND: /* wake ind */ |
124 | pr_info("wake indication recvd"); | 124 | pr_debug("wake indication recvd"); |
125 | ll_device_want_to_wakeup(st_data); | 125 | ll_device_want_to_wakeup(st_data); |
126 | break; | 126 | break; |
127 | case LL_WAKE_UP_ACK: /* wake ack */ | 127 | case LL_WAKE_UP_ACK: /* wake ack */ |
128 | pr_info("wake ack rcvd"); | 128 | pr_debug("wake ack rcvd"); |
129 | st_data->ll_state = ST_LL_AWAKE; | 129 | st_data->ll_state = ST_LL_AWAKE; |
130 | break; | 130 | break; |
131 | default: | 131 | default: |
132 | pr_err(" unknown input/state "); | 132 | pr_err(" unknown input/state "); |
133 | return -1; | 133 | return -EINVAL; |
134 | } | 134 | } |
135 | return 0; | 135 | return 0; |
136 | } | 136 | } |
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index bb440792a1b7..6f3ea9bbc818 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig | |||
@@ -94,4 +94,21 @@ config UIO_NETX | |||
94 | To compile this driver as a module, choose M here; the module | 94 | To compile this driver as a module, choose M here; the module |
95 | will be called uio_netx. | 95 | will be called uio_netx. |
96 | 96 | ||
97 | config UIO_PRUSS | ||
98 | tristate "Texas Instruments PRUSS driver" | ||
99 | depends on ARCH_DAVINCI_DA850 | ||
100 | help | ||
101 | PRUSS driver for OMAPL138/DA850/AM18XX devices | ||
102 | PRUSS driver requires user space components, examples and user space | ||
103 | driver is available from below SVN repo - you may use anonymous login | ||
104 | |||
105 | https://gforge.ti.com/gf/project/pru_sw/ | ||
106 | |||
107 | More info on API is available at below wiki | ||
108 | |||
109 | http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader | ||
110 | |||
111 | To compile this driver as a module, choose M here: the module | ||
112 | will be called uio_pruss. | ||
113 | |||
97 | endif | 114 | endif |
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile index 18fd818c5b97..d4dd9a5552f8 100644 --- a/drivers/uio/Makefile +++ b/drivers/uio/Makefile | |||
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC) += uio_aec.o | |||
6 | obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o | 6 | obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o |
7 | obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o | 7 | obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o |
8 | obj-$(CONFIG_UIO_NETX) += uio_netx.o | 8 | obj-$(CONFIG_UIO_NETX) += uio_netx.o |
9 | obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o | ||
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c new file mode 100644 index 000000000000..daf6e77de2b1 --- /dev/null +++ b/drivers/uio/uio_pruss.c | |||
@@ -0,0 +1,247 @@ | |||
1 | /* | ||
2 | * Programmable Real-Time Unit Sub System (PRUSS) UIO driver (uio_pruss) | ||
3 | * | ||
4 | * This driver exports PRUSS host event out interrupts and PRUSS, L3 RAM, | ||
5 | * and DDR RAM to user space for applications interacting with PRUSS firmware | ||
6 | * | ||
7 | * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/ | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License as | ||
11 | * published by the Free Software Foundation version 2. | ||
12 | * | ||
13 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
14 | * kind, whether express or implied; without even the implied warranty | ||
15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | */ | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/moduleparam.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/uio_driver.h> | ||
23 | #include <linux/platform_data/uio_pruss.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/clk.h> | ||
26 | #include <linux/dma-mapping.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <mach/sram.h> | ||
29 | |||
30 | #define DRV_NAME "pruss_uio" | ||
31 | #define DRV_VERSION "1.0" | ||
32 | |||
33 | static int sram_pool_sz = SZ_16K; | ||
34 | module_param(sram_pool_sz, int, 0); | ||
35 | MODULE_PARM_DESC(sram_pool_sz, "sram pool size to allocate "); | ||
36 | |||
37 | static int extram_pool_sz = SZ_256K; | ||
38 | module_param(extram_pool_sz, int, 0); | ||
39 | MODULE_PARM_DESC(extram_pool_sz, "external ram pool size to allocate"); | ||
40 | |||
41 | /* | ||
42 | * Host event IRQ numbers from PRUSS - PRUSS can generate upto 8 interrupt | ||
43 | * events to AINTC of ARM host processor - which can be used for IPC b/w PRUSS | ||
44 | * firmware and user space application, async notification from PRU firmware | ||
45 | * to user space application | ||
46 | * 3 PRU_EVTOUT0 | ||
47 | * 4 PRU_EVTOUT1 | ||
48 | * 5 PRU_EVTOUT2 | ||
49 | * 6 PRU_EVTOUT3 | ||
50 | * 7 PRU_EVTOUT4 | ||
51 | * 8 PRU_EVTOUT5 | ||
52 | * 9 PRU_EVTOUT6 | ||
53 | * 10 PRU_EVTOUT7 | ||
54 | */ | ||
55 | #define MAX_PRUSS_EVT 8 | ||
56 | |||
57 | #define PINTC_HIDISR 0x0038 | ||
58 | #define PINTC_HIPIR 0x0900 | ||
59 | #define HIPIR_NOPEND 0x80000000 | ||
60 | #define PINTC_HIER 0x1500 | ||
61 | |||
62 | struct uio_pruss_dev { | ||
63 | struct uio_info *info; | ||
64 | struct clk *pruss_clk; | ||
65 | dma_addr_t sram_paddr; | ||
66 | dma_addr_t ddr_paddr; | ||
67 | void __iomem *prussio_vaddr; | ||
68 | void *sram_vaddr; | ||
69 | void *ddr_vaddr; | ||
70 | unsigned int hostirq_start; | ||
71 | unsigned int pintc_base; | ||
72 | }; | ||
73 | |||
74 | static irqreturn_t pruss_handler(int irq, struct uio_info *info) | ||
75 | { | ||
76 | struct uio_pruss_dev *gdev = info->priv; | ||
77 | int intr_bit = (irq - gdev->hostirq_start + 2); | ||
78 | int val, intr_mask = (1 << intr_bit); | ||
79 | void __iomem *base = gdev->prussio_vaddr + gdev->pintc_base; | ||
80 | void __iomem *intren_reg = base + PINTC_HIER; | ||
81 | void __iomem *intrdis_reg = base + PINTC_HIDISR; | ||
82 | void __iomem *intrstat_reg = base + PINTC_HIPIR + (intr_bit << 2); | ||
83 | |||
84 | val = ioread32(intren_reg); | ||
85 | /* Is interrupt enabled and active ? */ | ||
86 | if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND)) | ||
87 | return IRQ_NONE; | ||
88 | /* Disable interrupt */ | ||
89 | iowrite32(intr_bit, intrdis_reg); | ||
90 | return IRQ_HANDLED; | ||
91 | } | ||
92 | |||
93 | static void pruss_cleanup(struct platform_device *dev, | ||
94 | struct uio_pruss_dev *gdev) | ||
95 | { | ||
96 | int cnt; | ||
97 | struct uio_info *p = gdev->info; | ||
98 | |||
99 | for (cnt = 0; cnt < MAX_PRUSS_EVT; cnt++, p++) { | ||
100 | uio_unregister_device(p); | ||
101 | kfree(p->name); | ||
102 | } | ||
103 | iounmap(gdev->prussio_vaddr); | ||
104 | if (gdev->ddr_vaddr) { | ||
105 | dma_free_coherent(&dev->dev, extram_pool_sz, gdev->ddr_vaddr, | ||
106 | gdev->ddr_paddr); | ||
107 | } | ||
108 | if (gdev->sram_vaddr) | ||
109 | sram_free(gdev->sram_vaddr, sram_pool_sz); | ||
110 | kfree(gdev->info); | ||
111 | clk_put(gdev->pruss_clk); | ||
112 | kfree(gdev); | ||
113 | } | ||
114 | |||
115 | static int __devinit pruss_probe(struct platform_device *dev) | ||
116 | { | ||
117 | struct uio_info *p; | ||
118 | struct uio_pruss_dev *gdev; | ||
119 | struct resource *regs_prussio; | ||
120 | int ret = -ENODEV, cnt = 0, len; | ||
121 | struct uio_pruss_pdata *pdata = dev->dev.platform_data; | ||
122 | |||
123 | gdev = kzalloc(sizeof(struct uio_pruss_dev), GFP_KERNEL); | ||
124 | if (!gdev) | ||
125 | return -ENOMEM; | ||
126 | |||
127 | gdev->info = kzalloc(sizeof(*p) * MAX_PRUSS_EVT, GFP_KERNEL); | ||
128 | if (!gdev->info) { | ||
129 | kfree(gdev); | ||
130 | return -ENOMEM; | ||
131 | } | ||
132 | /* Power on PRU in case its not done as part of boot-loader */ | ||
133 | gdev->pruss_clk = clk_get(&dev->dev, "pruss"); | ||
134 | if (IS_ERR(gdev->pruss_clk)) { | ||
135 | dev_err(&dev->dev, "Failed to get clock\n"); | ||
136 | kfree(gdev->info); | ||
137 | kfree(gdev); | ||
138 | ret = PTR_ERR(gdev->pruss_clk); | ||
139 | return ret; | ||
140 | } else { | ||
141 | clk_enable(gdev->pruss_clk); | ||
142 | } | ||
143 | |||
144 | regs_prussio = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
145 | if (!regs_prussio) { | ||
146 | dev_err(&dev->dev, "No PRUSS I/O resource specified\n"); | ||
147 | goto out_free; | ||
148 | } | ||
149 | |||
150 | if (!regs_prussio->start) { | ||
151 | dev_err(&dev->dev, "Invalid memory resource\n"); | ||
152 | goto out_free; | ||
153 | } | ||
154 | |||
155 | gdev->sram_vaddr = sram_alloc(sram_pool_sz, &(gdev->sram_paddr)); | ||
156 | if (!gdev->sram_vaddr) { | ||
157 | dev_err(&dev->dev, "Could not allocate SRAM pool\n"); | ||
158 | goto out_free; | ||
159 | } | ||
160 | |||
161 | gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz, | ||
162 | &(gdev->ddr_paddr), GFP_KERNEL | GFP_DMA); | ||
163 | if (!gdev->ddr_vaddr) { | ||
164 | dev_err(&dev->dev, "Could not allocate external memory\n"); | ||
165 | goto out_free; | ||
166 | } | ||
167 | |||
168 | len = resource_size(regs_prussio); | ||
169 | gdev->prussio_vaddr = ioremap(regs_prussio->start, len); | ||
170 | if (!gdev->prussio_vaddr) { | ||
171 | dev_err(&dev->dev, "Can't remap PRUSS I/O address range\n"); | ||
172 | goto out_free; | ||
173 | } | ||
174 | |||
175 | gdev->pintc_base = pdata->pintc_base; | ||
176 | gdev->hostirq_start = platform_get_irq(dev, 0); | ||
177 | |||
178 | for (cnt = 0, p = gdev->info; cnt < MAX_PRUSS_EVT; cnt++, p++) { | ||
179 | p->mem[0].addr = regs_prussio->start; | ||
180 | p->mem[0].size = resource_size(regs_prussio); | ||
181 | p->mem[0].memtype = UIO_MEM_PHYS; | ||
182 | |||
183 | p->mem[1].addr = gdev->sram_paddr; | ||
184 | p->mem[1].size = sram_pool_sz; | ||
185 | p->mem[1].memtype = UIO_MEM_PHYS; | ||
186 | |||
187 | p->mem[2].addr = gdev->ddr_paddr; | ||
188 | p->mem[2].size = extram_pool_sz; | ||
189 | p->mem[2].memtype = UIO_MEM_PHYS; | ||
190 | |||
191 | p->name = kasprintf(GFP_KERNEL, "pruss_evt%d", cnt); | ||
192 | p->version = DRV_VERSION; | ||
193 | |||
194 | /* Register PRUSS IRQ lines */ | ||
195 | p->irq = gdev->hostirq_start + cnt; | ||
196 | p->handler = pruss_handler; | ||
197 | p->priv = gdev; | ||
198 | |||
199 | ret = uio_register_device(&dev->dev, p); | ||
200 | if (ret < 0) | ||
201 | goto out_free; | ||
202 | } | ||
203 | |||
204 | platform_set_drvdata(dev, gdev); | ||
205 | return 0; | ||
206 | |||
207 | out_free: | ||
208 | pruss_cleanup(dev, gdev); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | static int __devexit pruss_remove(struct platform_device *dev) | ||
213 | { | ||
214 | struct uio_pruss_dev *gdev = platform_get_drvdata(dev); | ||
215 | |||
216 | pruss_cleanup(dev, gdev); | ||
217 | platform_set_drvdata(dev, NULL); | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static struct platform_driver pruss_driver = { | ||
222 | .probe = pruss_probe, | ||
223 | .remove = __devexit_p(pruss_remove), | ||
224 | .driver = { | ||
225 | .name = DRV_NAME, | ||
226 | .owner = THIS_MODULE, | ||
227 | }, | ||
228 | }; | ||
229 | |||
230 | static int __init pruss_init_module(void) | ||
231 | { | ||
232 | return platform_driver_register(&pruss_driver); | ||
233 | } | ||
234 | |||
235 | module_init(pruss_init_module); | ||
236 | |||
237 | static void __exit pruss_exit_module(void) | ||
238 | { | ||
239 | platform_driver_unregister(&pruss_driver); | ||
240 | } | ||
241 | |||
242 | module_exit(pruss_exit_module); | ||
243 | |||
244 | MODULE_LICENSE("GPL v2"); | ||
245 | MODULE_VERSION(DRV_VERSION); | ||
246 | MODULE_AUTHOR("Amit Chatterjee <amit.chatterjee@ti.com>"); | ||
247 | MODULE_AUTHOR("Pratheesh Gangadhar <pratheesh@ti.com>"); | ||