aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/Kconfig1
-rw-r--r--drivers/base/Makefile4
-rw-r--r--drivers/base/bus.c22
-rw-r--r--drivers/base/class.c23
-rw-r--r--drivers/base/core.c208
-rw-r--r--drivers/base/memory.c94
-rw-r--r--drivers/base/node.c8
-rw-r--r--drivers/base/platform.c80
-rw-r--r--drivers/base/sys.c8
-rw-r--r--drivers/misc/Kconfig22
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/hpilo.c2
-rw-r--r--drivers/misc/pch_phub.c717
-rw-r--r--drivers/scsi/hosts.c2
-rw-r--r--drivers/scsi/scsi_scan.c2
-rw-r--r--drivers/uio/uio.c163
-rw-r--r--drivers/uio/uio_pci_generic.c13
17 files changed, 977 insertions, 393 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index ef38aff737eb..fd96345bc35c 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -71,7 +71,6 @@ config PREVENT_FIRMWARE_BUILD
71 71
72config FW_LOADER 72config FW_LOADER
73 tristate "Userspace firmware loading support" if EMBEDDED 73 tristate "Userspace firmware loading support" if EMBEDDED
74 depends on HOTPLUG
75 default y 74 default y
76 ---help--- 75 ---help---
77 This option is provided for the case where no in-kernel-tree modules 76 This option is provided for the case where no in-kernel-tree modules
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index c12c7f2f2a6f..5f51c3b4451e 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -19,7 +19,5 @@ obj-$(CONFIG_MODULES) += module.o
19endif 19endif
20obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o 20obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
21 21
22ifeq ($(CONFIG_DEBUG_DRIVER),y) 22ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
23EXTRA_CFLAGS += -DDEBUG
24endif
25 23
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index eb1b7fa20dce..33c270a64db7 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -440,22 +440,6 @@ static void device_remove_attrs(struct bus_type *bus, struct device *dev)
440 } 440 }
441} 441}
442 442
443#ifdef CONFIG_SYSFS_DEPRECATED
444static int make_deprecated_bus_links(struct device *dev)
445{
446 return sysfs_create_link(&dev->kobj,
447 &dev->bus->p->subsys.kobj, "bus");
448}
449
450static void remove_deprecated_bus_links(struct device *dev)
451{
452 sysfs_remove_link(&dev->kobj, "bus");
453}
454#else
455static inline int make_deprecated_bus_links(struct device *dev) { return 0; }
456static inline void remove_deprecated_bus_links(struct device *dev) { }
457#endif
458
459/** 443/**
460 * bus_add_device - add device to bus 444 * bus_add_device - add device to bus
461 * @dev: device being added 445 * @dev: device being added
@@ -482,15 +466,10 @@ int bus_add_device(struct device *dev)
482 &dev->bus->p->subsys.kobj, "subsystem"); 466 &dev->bus->p->subsys.kobj, "subsystem");
483 if (error) 467 if (error)
484 goto out_subsys; 468 goto out_subsys;
485 error = make_deprecated_bus_links(dev);
486 if (error)
487 goto out_deprecated;
488 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); 469 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices);
489 } 470 }
490 return 0; 471 return 0;
491 472
492out_deprecated:
493 sysfs_remove_link(&dev->kobj, "subsystem");
494out_subsys: 473out_subsys:
495 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); 474 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev));
496out_id: 475out_id:
@@ -530,7 +509,6 @@ void bus_remove_device(struct device *dev)
530{ 509{
531 if (dev->bus) { 510 if (dev->bus) {
532 sysfs_remove_link(&dev->kobj, "subsystem"); 511 sysfs_remove_link(&dev->kobj, "subsystem");
533 remove_deprecated_bus_links(dev);
534 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 512 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
535 dev_name(dev)); 513 dev_name(dev));
536 device_remove_attrs(dev->bus, dev); 514 device_remove_attrs(dev->bus, dev);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8e231d05b400..9c63a5687d69 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -184,9 +184,9 @@ int __class_register(struct class *cls, struct lock_class_key *key)
184 if (!cls->dev_kobj) 184 if (!cls->dev_kobj)
185 cls->dev_kobj = sysfs_dev_char_kobj; 185 cls->dev_kobj = sysfs_dev_char_kobj;
186 186
187#if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK) 187#if defined(CONFIG_BLOCK)
188 /* let the block class directory show up in the root of sysfs */ 188 /* let the block class directory show up in the root of sysfs */
189 if (cls != &block_class) 189 if (!sysfs_deprecated || cls != &block_class)
190 cp->class_subsys.kobj.kset = class_kset; 190 cp->class_subsys.kobj.kset = class_kset;
191#else 191#else
192 cp->class_subsys.kobj.kset = class_kset; 192 cp->class_subsys.kobj.kset = class_kset;
@@ -276,25 +276,6 @@ void class_destroy(struct class *cls)
276 class_unregister(cls); 276 class_unregister(cls);
277} 277}
278 278
279#ifdef CONFIG_SYSFS_DEPRECATED
280char *make_class_name(const char *name, struct kobject *kobj)
281{
282 char *class_name;
283 int size;
284
285 size = strlen(name) + strlen(kobject_name(kobj)) + 2;
286
287 class_name = kmalloc(size, GFP_KERNEL);
288 if (!class_name)
289 return NULL;
290
291 strcpy(class_name, name);
292 strcat(class_name, ":");
293 strcat(class_name, kobject_name(kobj));
294 return class_name;
295}
296#endif
297
298/** 279/**
299 * class_dev_iter_init - initialize class device iterator 280 * class_dev_iter_init - initialize class device iterator
300 * @iter: class iterator to initialize 281 * @iter: class iterator to initialize
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d1b2c9adc271..2cb49a93b1e6 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -26,6 +26,19 @@
26#include "base.h" 26#include "base.h"
27#include "power/power.h" 27#include "power/power.h"
28 28
29#ifdef CONFIG_SYSFS_DEPRECATED
30#ifdef CONFIG_SYSFS_DEPRECATED_V2
31long sysfs_deprecated = 1;
32#else
33long sysfs_deprecated = 0;
34#endif
35static __init int sysfs_deprecated_setup(char *arg)
36{
37 return strict_strtol(arg, 10, &sysfs_deprecated);
38}
39early_param("sysfs.deprecated", sysfs_deprecated_setup);
40#endif
41
29int (*platform_notify)(struct device *dev) = NULL; 42int (*platform_notify)(struct device *dev) = NULL;
30int (*platform_notify_remove)(struct device *dev) = NULL; 43int (*platform_notify_remove)(struct device *dev) = NULL;
31static struct kobject *dev_kobj; 44static struct kobject *dev_kobj;
@@ -203,37 +216,6 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
203 if (dev->driver) 216 if (dev->driver)
204 add_uevent_var(env, "DRIVER=%s", dev->driver->name); 217 add_uevent_var(env, "DRIVER=%s", dev->driver->name);
205 218
206#ifdef CONFIG_SYSFS_DEPRECATED
207 if (dev->class) {
208 struct device *parent = dev->parent;
209
210 /* find first bus device in parent chain */
211 while (parent && !parent->bus)
212 parent = parent->parent;
213 if (parent && parent->bus) {
214 const char *path;
215
216 path = kobject_get_path(&parent->kobj, GFP_KERNEL);
217 if (path) {
218 add_uevent_var(env, "PHYSDEVPATH=%s", path);
219 kfree(path);
220 }
221
222 add_uevent_var(env, "PHYSDEVBUS=%s", parent->bus->name);
223
224 if (parent->driver)
225 add_uevent_var(env, "PHYSDEVDRIVER=%s",
226 parent->driver->name);
227 }
228 } else if (dev->bus) {
229 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
230
231 if (dev->driver)
232 add_uevent_var(env, "PHYSDEVDRIVER=%s",
233 dev->driver->name);
234 }
235#endif
236
237 /* have the bus specific function add its stuff */ 219 /* have the bus specific function add its stuff */
238 if (dev->bus && dev->bus->uevent) { 220 if (dev->bus && dev->bus->uevent) {
239 retval = dev->bus->uevent(dev, env); 221 retval = dev->bus->uevent(dev, env);
@@ -578,24 +560,6 @@ void device_initialize(struct device *dev)
578 set_dev_node(dev, -1); 560 set_dev_node(dev, -1);
579} 561}
580 562
581#ifdef CONFIG_SYSFS_DEPRECATED
582static struct kobject *get_device_parent(struct device *dev,
583 struct device *parent)
584{
585 /* class devices without a parent live in /sys/class/<classname>/ */
586 if (dev->class && (!parent || parent->class != dev->class))
587 return &dev->class->p->class_subsys.kobj;
588 /* all other devices keep their parent */
589 else if (parent)
590 return &parent->kobj;
591
592 return NULL;
593}
594
595static inline void cleanup_device_parent(struct device *dev) {}
596static inline void cleanup_glue_dir(struct device *dev,
597 struct kobject *glue_dir) {}
598#else
599static struct kobject *virtual_device_parent(struct device *dev) 563static struct kobject *virtual_device_parent(struct device *dev)
600{ 564{
601 static struct kobject *virtual_dir = NULL; 565 static struct kobject *virtual_dir = NULL;
@@ -666,6 +630,15 @@ static struct kobject *get_device_parent(struct device *dev,
666 struct kobject *parent_kobj; 630 struct kobject *parent_kobj;
667 struct kobject *k; 631 struct kobject *k;
668 632
633#ifdef CONFIG_BLOCK
634 /* block disks show up in /sys/block */
635 if (sysfs_deprecated && dev->class == &block_class) {
636 if (parent && parent->class == &block_class)
637 return &parent->kobj;
638 return &block_class.p->class_subsys.kobj;
639 }
640#endif
641
669 /* 642 /*
670 * If we have no parent, we live in "virtual". 643 * If we have no parent, we live in "virtual".
671 * Class-devices with a non class-device as parent, live 644 * Class-devices with a non class-device as parent, live
@@ -719,7 +692,6 @@ static void cleanup_device_parent(struct device *dev)
719{ 692{
720 cleanup_glue_dir(dev, dev->kobj.parent); 693 cleanup_glue_dir(dev, dev->kobj.parent);
721} 694}
722#endif
723 695
724static void setup_parent(struct device *dev, struct device *parent) 696static void setup_parent(struct device *dev, struct device *parent)
725{ 697{
@@ -742,70 +714,29 @@ static int device_add_class_symlinks(struct device *dev)
742 if (error) 714 if (error)
743 goto out; 715 goto out;
744 716
745#ifdef CONFIG_SYSFS_DEPRECATED
746 /* stacked class devices need a symlink in the class directory */
747 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
748 device_is_not_partition(dev)) {
749 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
750 &dev->kobj, dev_name(dev));
751 if (error)
752 goto out_subsys;
753 }
754
755 if (dev->parent && device_is_not_partition(dev)) { 717 if (dev->parent && device_is_not_partition(dev)) {
756 struct device *parent = dev->parent; 718 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
757 char *class_name;
758
759 /*
760 * stacked class devices have the 'device' link
761 * pointing to the bus device instead of the parent
762 */
763 while (parent->class && !parent->bus && parent->parent)
764 parent = parent->parent;
765
766 error = sysfs_create_link(&dev->kobj,
767 &parent->kobj,
768 "device"); 719 "device");
769 if (error) 720 if (error)
770 goto out_busid; 721 goto out_subsys;
771
772 class_name = make_class_name(dev->class->name,
773 &dev->kobj);
774 if (class_name)
775 error = sysfs_create_link(&dev->parent->kobj,
776 &dev->kobj, class_name);
777 kfree(class_name);
778 if (error)
779 goto out_device;
780 } 722 }
781 return 0;
782 723
783out_device: 724#ifdef CONFIG_BLOCK
784 if (dev->parent && device_is_not_partition(dev)) 725 /* /sys/block has directories and does not need symlinks */
785 sysfs_remove_link(&dev->kobj, "device"); 726 if (sysfs_deprecated && dev->class == &block_class)
786out_busid: 727 return 0;
787 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 728#endif
788 device_is_not_partition(dev)) 729
789 sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj,
790 dev_name(dev));
791#else
792 /* link in the class directory pointing to the device */ 730 /* link in the class directory pointing to the device */
793 error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 731 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
794 &dev->kobj, dev_name(dev)); 732 &dev->kobj, dev_name(dev));
795 if (error) 733 if (error)
796 goto out_subsys; 734 goto out_device;
797 735
798 if (dev->parent && device_is_not_partition(dev)) {
799 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
800 "device");
801 if (error)
802 goto out_busid;
803 }
804 return 0; 736 return 0;
805 737
806out_busid: 738out_device:
807 sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); 739 sysfs_remove_link(&dev->kobj, "device");
808#endif
809 740
810out_subsys: 741out_subsys:
811 sysfs_remove_link(&dev->kobj, "subsystem"); 742 sysfs_remove_link(&dev->kobj, "subsystem");
@@ -818,30 +749,14 @@ static void device_remove_class_symlinks(struct device *dev)
818 if (!dev->class) 749 if (!dev->class)
819 return; 750 return;
820 751
821#ifdef CONFIG_SYSFS_DEPRECATED
822 if (dev->parent && device_is_not_partition(dev)) {
823 char *class_name;
824
825 class_name = make_class_name(dev->class->name, &dev->kobj);
826 if (class_name) {
827 sysfs_remove_link(&dev->parent->kobj, class_name);
828 kfree(class_name);
829 }
830 sysfs_remove_link(&dev->kobj, "device");
831 }
832
833 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
834 device_is_not_partition(dev))
835 sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj,
836 dev_name(dev));
837#else
838 if (dev->parent && device_is_not_partition(dev)) 752 if (dev->parent && device_is_not_partition(dev))
839 sysfs_remove_link(&dev->kobj, "device"); 753 sysfs_remove_link(&dev->kobj, "device");
840
841 sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev));
842#endif
843
844 sysfs_remove_link(&dev->kobj, "subsystem"); 754 sysfs_remove_link(&dev->kobj, "subsystem");
755#ifdef CONFIG_BLOCK
756 if (sysfs_deprecated && dev->class == &block_class)
757 return;
758#endif
759 sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev));
845} 760}
846 761
847/** 762/**
@@ -1613,41 +1528,23 @@ int device_rename(struct device *dev, const char *new_name)
1613 pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev), 1528 pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev),
1614 __func__, new_name); 1529 __func__, new_name);
1615 1530
1616#ifdef CONFIG_SYSFS_DEPRECATED
1617 if ((dev->class) && (dev->parent))
1618 old_class_name = make_class_name(dev->class->name, &dev->kobj);
1619#endif
1620
1621 old_device_name = kstrdup(dev_name(dev), GFP_KERNEL); 1531 old_device_name = kstrdup(dev_name(dev), GFP_KERNEL);
1622 if (!old_device_name) { 1532 if (!old_device_name) {
1623 error = -ENOMEM; 1533 error = -ENOMEM;
1624 goto out; 1534 goto out;
1625 } 1535 }
1626 1536
1627#ifndef CONFIG_SYSFS_DEPRECATED
1628 if (dev->class) { 1537 if (dev->class) {
1629 error = sysfs_rename_link(&dev->class->p->class_subsys.kobj, 1538 error = sysfs_rename_link(&dev->class->p->class_subsys.kobj,
1630 &dev->kobj, old_device_name, new_name); 1539 &dev->kobj, old_device_name, new_name);
1631 if (error) 1540 if (error)
1632 goto out; 1541 goto out;
1633 } 1542 }
1634#endif 1543
1635 error = kobject_rename(&dev->kobj, new_name); 1544 error = kobject_rename(&dev->kobj, new_name);
1636 if (error) 1545 if (error)
1637 goto out; 1546 goto out;
1638 1547
1639#ifdef CONFIG_SYSFS_DEPRECATED
1640 if (old_class_name) {
1641 new_class_name = make_class_name(dev->class->name, &dev->kobj);
1642 if (new_class_name) {
1643 error = sysfs_rename_link(&dev->parent->kobj,
1644 &dev->kobj,
1645 old_class_name,
1646 new_class_name);
1647 }
1648 }
1649#endif
1650
1651out: 1548out:
1652 put_device(dev); 1549 put_device(dev);
1653 1550
@@ -1664,40 +1561,13 @@ static int device_move_class_links(struct device *dev,
1664 struct device *new_parent) 1561 struct device *new_parent)
1665{ 1562{
1666 int error = 0; 1563 int error = 0;
1667#ifdef CONFIG_SYSFS_DEPRECATED
1668 char *class_name;
1669 1564
1670 class_name = make_class_name(dev->class->name, &dev->kobj);
1671 if (!class_name) {
1672 error = -ENOMEM;
1673 goto out;
1674 }
1675 if (old_parent) {
1676 sysfs_remove_link(&dev->kobj, "device");
1677 sysfs_remove_link(&old_parent->kobj, class_name);
1678 }
1679 if (new_parent) {
1680 error = sysfs_create_link(&dev->kobj, &new_parent->kobj,
1681 "device");
1682 if (error)
1683 goto out;
1684 error = sysfs_create_link(&new_parent->kobj, &dev->kobj,
1685 class_name);
1686 if (error)
1687 sysfs_remove_link(&dev->kobj, "device");
1688 } else
1689 error = 0;
1690out:
1691 kfree(class_name);
1692 return error;
1693#else
1694 if (old_parent) 1565 if (old_parent)
1695 sysfs_remove_link(&dev->kobj, "device"); 1566 sysfs_remove_link(&dev->kobj, "device");
1696 if (new_parent) 1567 if (new_parent)
1697 error = sysfs_create_link(&dev->kobj, &new_parent->kobj, 1568 error = sysfs_create_link(&dev->kobj, &new_parent->kobj,
1698 "device"); 1569 "device");
1699 return error; 1570 return error;
1700#endif
1701} 1571}
1702 1572
1703/** 1573/**
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 933442f40321..cafeaaf0428f 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -27,6 +27,8 @@
27#include <asm/atomic.h> 27#include <asm/atomic.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29 29
30static DEFINE_MUTEX(mem_sysfs_mutex);
31
30#define MEMORY_CLASS_NAME "memory" 32#define MEMORY_CLASS_NAME "memory"
31 33
32static struct sysdev_class memory_sysdev_class = { 34static struct sysdev_class memory_sysdev_class = {
@@ -435,6 +437,45 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn)
435 return 0; 437 return 0;
436} 438}
437 439
440struct memory_block *find_memory_block_hinted(struct mem_section *section,
441 struct memory_block *hint)
442{
443 struct kobject *kobj;
444 struct sys_device *sysdev;
445 struct memory_block *mem;
446 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
447
448 kobj = hint ? &hint->sysdev.kobj : NULL;
449
450 /*
451 * This only works because we know that section == sysdev->id
452 * slightly redundant with sysdev_register()
453 */
454 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section));
455
456 kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj);
457 if (!kobj)
458 return NULL;
459
460 sysdev = container_of(kobj, struct sys_device, kobj);
461 mem = container_of(sysdev, struct memory_block, sysdev);
462
463 return mem;
464}
465
466/*
467 * For now, we have a linear search to go find the appropriate
468 * memory_block corresponding to a particular phys_index. If
469 * this gets to be a real problem, we can always use a radix
470 * tree or something here.
471 *
472 * This could be made generic for all sysdev classes.
473 */
474struct memory_block *find_memory_block(struct mem_section *section)
475{
476 return find_memory_block_hinted(section, NULL);
477}
478
438static int add_memory_block(int nid, struct mem_section *section, 479static int add_memory_block(int nid, struct mem_section *section,
439 unsigned long state, enum mem_add_context context) 480 unsigned long state, enum mem_add_context context)
440{ 481{
@@ -445,8 +486,11 @@ static int add_memory_block(int nid, struct mem_section *section,
445 if (!mem) 486 if (!mem)
446 return -ENOMEM; 487 return -ENOMEM;
447 488
489 mutex_lock(&mem_sysfs_mutex);
490
448 mem->phys_index = __section_nr(section); 491 mem->phys_index = __section_nr(section);
449 mem->state = state; 492 mem->state = state;
493 mem->section_count++;
450 mutex_init(&mem->state_mutex); 494 mutex_init(&mem->state_mutex);
451 start_pfn = section_nr_to_pfn(mem->phys_index); 495 start_pfn = section_nr_to_pfn(mem->phys_index);
452 mem->phys_device = arch_get_memory_phys_device(start_pfn); 496 mem->phys_device = arch_get_memory_phys_device(start_pfn);
@@ -465,53 +509,29 @@ static int add_memory_block(int nid, struct mem_section *section,
465 ret = register_mem_sect_under_node(mem, nid); 509 ret = register_mem_sect_under_node(mem, nid);
466 } 510 }
467 511
512 mutex_unlock(&mem_sysfs_mutex);
468 return ret; 513 return ret;
469} 514}
470 515
471/*
472 * For now, we have a linear search to go find the appropriate
473 * memory_block corresponding to a particular phys_index. If
474 * this gets to be a real problem, we can always use a radix
475 * tree or something here.
476 *
477 * This could be made generic for all sysdev classes.
478 */
479struct memory_block *find_memory_block(struct mem_section *section)
480{
481 struct kobject *kobj;
482 struct sys_device *sysdev;
483 struct memory_block *mem;
484 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
485
486 /*
487 * This only works because we know that section == sysdev->id
488 * slightly redundant with sysdev_register()
489 */
490 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section));
491
492 kobj = kset_find_obj(&memory_sysdev_class.kset, name);
493 if (!kobj)
494 return NULL;
495
496 sysdev = container_of(kobj, struct sys_device, kobj);
497 mem = container_of(sysdev, struct memory_block, sysdev);
498
499 return mem;
500}
501
502int remove_memory_block(unsigned long node_id, struct mem_section *section, 516int remove_memory_block(unsigned long node_id, struct mem_section *section,
503 int phys_device) 517 int phys_device)
504{ 518{
505 struct memory_block *mem; 519 struct memory_block *mem;
506 520
521 mutex_lock(&mem_sysfs_mutex);
507 mem = find_memory_block(section); 522 mem = find_memory_block(section);
508 unregister_mem_sect_under_nodes(mem);
509 mem_remove_simple_file(mem, phys_index);
510 mem_remove_simple_file(mem, state);
511 mem_remove_simple_file(mem, phys_device);
512 mem_remove_simple_file(mem, removable);
513 unregister_memory(mem, section);
514 523
524 mem->section_count--;
525 if (mem->section_count == 0) {
526 unregister_mem_sect_under_nodes(mem);
527 mem_remove_simple_file(mem, phys_index);
528 mem_remove_simple_file(mem, state);
529 mem_remove_simple_file(mem, phys_device);
530 mem_remove_simple_file(mem, removable);
531 unregister_memory(mem, section);
532 }
533
534 mutex_unlock(&mem_sysfs_mutex);
515 return 0; 535 return 0;
516} 536}
517 537
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 2872e86837b2..ee53558b452f 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -409,25 +409,27 @@ static int link_mem_sections(int nid)
409 unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn; 409 unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
410 unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages; 410 unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
411 unsigned long pfn; 411 unsigned long pfn;
412 struct memory_block *mem_blk = NULL;
412 int err = 0; 413 int err = 0;
413 414
414 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { 415 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
415 unsigned long section_nr = pfn_to_section_nr(pfn); 416 unsigned long section_nr = pfn_to_section_nr(pfn);
416 struct mem_section *mem_sect; 417 struct mem_section *mem_sect;
417 struct memory_block *mem_blk;
418 int ret; 418 int ret;
419 419
420 if (!present_section_nr(section_nr)) 420 if (!present_section_nr(section_nr))
421 continue; 421 continue;
422 mem_sect = __nr_to_section(section_nr); 422 mem_sect = __nr_to_section(section_nr);
423 mem_blk = find_memory_block(mem_sect); 423 mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
424 ret = register_mem_sect_under_node(mem_blk, nid); 424 ret = register_mem_sect_under_node(mem_blk, nid);
425 if (!err) 425 if (!err)
426 err = ret; 426 err = ret;
427 427
428 /* discard ref obtained in find_memory_block() */ 428 /* discard ref obtained in find_memory_block() */
429 kobject_put(&mem_blk->sysdev.kobj);
430 } 429 }
430
431 if (mem_blk)
432 kobject_put(&mem_blk->sysdev.kobj);
431 return err; 433 return err;
432} 434}
433 435
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c6c933f58102..3966e62ad019 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -192,6 +192,9 @@ int platform_device_add_resources(struct platform_device *pdev,
192{ 192{
193 struct resource *r; 193 struct resource *r;
194 194
195 if (!res)
196 return 0;
197
195 r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); 198 r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
196 if (r) { 199 if (r) {
197 pdev->resource = r; 200 pdev->resource = r;
@@ -215,8 +218,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources);
215int platform_device_add_data(struct platform_device *pdev, const void *data, 218int platform_device_add_data(struct platform_device *pdev, const void *data,
216 size_t size) 219 size_t size)
217{ 220{
218 void *d = kmemdup(data, size, GFP_KERNEL); 221 void *d;
222
223 if (!data)
224 return 0;
219 225
226 d = kmemdup(data, size, GFP_KERNEL);
220 if (d) { 227 if (d) {
221 pdev->dev.platform_data = d; 228 pdev->dev.platform_data = d;
222 return 0; 229 return 0;
@@ -373,17 +380,13 @@ struct platform_device *__init_or_module platform_device_register_resndata(
373 380
374 pdev->dev.parent = parent; 381 pdev->dev.parent = parent;
375 382
376 if (res) { 383 ret = platform_device_add_resources(pdev, res, num);
377 ret = platform_device_add_resources(pdev, res, num); 384 if (ret)
378 if (ret) 385 goto err;
379 goto err;
380 }
381 386
382 if (data) { 387 ret = platform_device_add_data(pdev, data, size);
383 ret = platform_device_add_data(pdev, data, size); 388 if (ret)
384 if (ret) 389 goto err;
385 goto err;
386 }
387 390
388 ret = platform_device_add(pdev); 391 ret = platform_device_add(pdev);
389 if (ret) { 392 if (ret) {
@@ -488,12 +491,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
488 * if the probe was successful, and make sure any forced probes of 491 * if the probe was successful, and make sure any forced probes of
489 * new devices fail. 492 * new devices fail.
490 */ 493 */
491 spin_lock(&platform_bus_type.p->klist_drivers.k_lock); 494 spin_lock(&drv->driver.bus->p->klist_drivers.k_lock);
492 drv->probe = NULL; 495 drv->probe = NULL;
493 if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list)) 496 if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
494 retval = -ENODEV; 497 retval = -ENODEV;
495 drv->driver.probe = platform_drv_probe_fail; 498 drv->driver.probe = platform_drv_probe_fail;
496 spin_unlock(&platform_bus_type.p->klist_drivers.k_lock); 499 spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock);
497 500
498 if (code != retval) 501 if (code != retval)
499 platform_driver_unregister(drv); 502 platform_driver_unregister(drv);
@@ -530,17 +533,13 @@ struct platform_device * __init_or_module platform_create_bundle(
530 goto err_out; 533 goto err_out;
531 } 534 }
532 535
533 if (res) { 536 error = platform_device_add_resources(pdev, res, n_res);
534 error = platform_device_add_resources(pdev, res, n_res); 537 if (error)
535 if (error) 538 goto err_pdev_put;
536 goto err_pdev_put;
537 }
538 539
539 if (data) { 540 error = platform_device_add_data(pdev, data, size);
540 error = platform_device_add_data(pdev, data, size); 541 if (error)
541 if (error) 542 goto err_pdev_put;
542 goto err_pdev_put;
543 }
544 543
545 error = platform_device_add(pdev); 544 error = platform_device_add(pdev);
546 if (error) 545 if (error)
@@ -976,6 +975,41 @@ struct bus_type platform_bus_type = {
976}; 975};
977EXPORT_SYMBOL_GPL(platform_bus_type); 976EXPORT_SYMBOL_GPL(platform_bus_type);
978 977
978/**
979 * platform_bus_get_pm_ops() - return pointer to busses dev_pm_ops
980 *
981 * This function can be used by platform code to get the current
982 * set of dev_pm_ops functions used by the platform_bus_type.
983 */
984const struct dev_pm_ops * __init platform_bus_get_pm_ops(void)
985{
986 return platform_bus_type.pm;
987}
988
989/**
990 * platform_bus_set_pm_ops() - update dev_pm_ops for the platform_bus_type
991 *
992 * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type
993 *
994 * Platform code can override the dev_pm_ops methods of
995 * platform_bus_type by using this function. It is expected that
996 * platform code will first do a platform_bus_get_pm_ops(), then
997 * kmemdup it, then customize selected methods and pass a pointer to
998 * the new struct dev_pm_ops to this function.
999 *
1000 * Since platform-specific code is customizing methods for *all*
1001 * devices (not just platform-specific devices) it is expected that
1002 * any custom overrides of these functions will keep existing behavior
1003 * and simply extend it. For example, any customization of the
1004 * runtime PM methods should continue to call the pm_generic_*
1005 * functions as the default ones do in addition to the
1006 * platform-specific behavior.
1007 */
1008void __init platform_bus_set_pm_ops(const struct dev_pm_ops *pm)
1009{
1010 platform_bus_type.pm = pm;
1011}
1012
979int __init platform_bus_init(void) 1013int __init platform_bus_init(void)
980{ 1014{
981 int error; 1015 int error;
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 9354dc10a363..1667aaf4fde6 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -432,13 +432,13 @@ int sysdev_suspend(pm_message_t state)
432 /* resume current sysdev */ 432 /* resume current sysdev */
433cls_driver: 433cls_driver:
434 drv = NULL; 434 drv = NULL;
435 printk(KERN_ERR "Class suspend failed for %s\n", 435 printk(KERN_ERR "Class suspend failed for %s: %d\n",
436 kobject_name(&sysdev->kobj)); 436 kobject_name(&sysdev->kobj), ret);
437 437
438aux_driver: 438aux_driver:
439 if (drv) 439 if (drv)
440 printk(KERN_ERR "Class driver suspend failed for %s\n", 440 printk(KERN_ERR "Class driver suspend failed for %s: %d\n",
441 kobject_name(&sysdev->kobj)); 441 kobject_name(&sysdev->kobj), ret);
442 list_for_each_entry(err_drv, &cls->drivers, entry) { 442 list_for_each_entry(err_drv, &cls->drivers, entry) {
443 if (err_drv == drv) 443 if (err_drv == drv)
444 break; 444 break;
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index b74331260744..db2fbe2d4146 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -248,15 +248,15 @@ config CS5535_CLOCK_EVENT_SRC
248 generic PIT, and are suitable for use as high-res timers. 248 generic PIT, and are suitable for use as high-res timers.
249 249
250config HP_ILO 250config HP_ILO
251 tristate "Channel interface driver for HP iLO/iLO2 processor" 251 tristate "Channel interface driver for the HP iLO processor"
252 depends on PCI 252 depends on PCI
253 default n 253 default n
254 help 254 help
255 The channel interface driver allows applications to communicate 255 The channel interface driver allows applications to communicate
256 with iLO/iLO2 management processors present on HP ProLiant 256 with iLO management processors present on HP ProLiant servers.
257 servers. Upon loading, the driver creates /dev/hpilo/dXccbN files, 257 Upon loading, the driver creates /dev/hpilo/dXccbN files, which
258 which can be used to gather data from the management processor, 258 can be used to gather data from the management processor, via
259 via read and write system calls. 259 read and write system calls.
260 260
261 To compile this driver as a module, choose M here: the 261 To compile this driver as a module, choose M here: the
262 module will be called hpilo. 262 module will be called hpilo.
@@ -390,6 +390,18 @@ config BMP085
390 To compile this driver as a module, choose M here: the 390 To compile this driver as a module, choose M here: the
391 module will be called bmp085. 391 module will be called bmp085.
392 392
393config PCH_PHUB
394 tristate "PCH Packet Hub of Intel Topcliff"
395 depends on PCI
396 help
397 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of
398 Intel Topcliff which is an IOH(Input/Output Hub) for x86 embedded
399 processor. The Topcliff has MAC address and Option ROM data in SROM.
400 This driver can access MAC address and Option ROM data in SROM.
401
402 To compile this driver as a module, choose M here: the module will
403 be called pch_phub.
404
393source "drivers/misc/c2port/Kconfig" 405source "drivers/misc/c2port/Kconfig"
394source "drivers/misc/eeprom/Kconfig" 406source "drivers/misc/eeprom/Kconfig"
395source "drivers/misc/cb710/Kconfig" 407source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 42eab95cde2a..9f2986b4da2f 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -35,3 +35,4 @@ obj-y += eeprom/
35obj-y += cb710/ 35obj-y += cb710/
36obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o 36obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
37obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o 37obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
38obj-$(CONFIG_PCH_PHUB) += pch_phub.o
diff --git a/drivers/misc/hpilo.c b/drivers/misc/hpilo.c
index 69c1f2fca141..fffc227181b0 100644
--- a/drivers/misc/hpilo.c
+++ b/drivers/misc/hpilo.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for HP iLO/iLO2 management processor. 2 * Driver for the HP iLO management processor.
3 * 3 *
4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. 4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * David Altobelli <david.altobelli@hp.com> 5 * David Altobelli <david.altobelli@hp.com>
diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c
new file mode 100644
index 000000000000..744b804aca15
--- /dev/null
+++ b/drivers/misc/pch_phub.c
@@ -0,0 +1,717 @@
1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
3 *
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
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/types.h>
21#include <linux/fs.h>
22#include <linux/uaccess.h>
23#include <linux/string.h>
24#include <linux/pci.h>
25#include <linux/io.h>
26#include <linux/delay.h>
27#include <linux/mutex.h>
28#include <linux/if_ether.h>
29#include <linux/ctype.h>
30
31#define PHUB_STATUS 0x00 /* Status Register offset */
32#define PHUB_CONTROL 0x04 /* Control Register offset */
33#define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */
34#define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling 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 */
37
38/* MAX number of INT_REDUCE_CONTROL registers */
39#define MAX_NUM_INT_REDUCE_CONTROL_REG 128
40#define PCI_DEVICE_ID_PCH1_PHUB 0x8801
41#define PCH_MINOR_NOS 1
42#define CLKCFG_CAN_50MHZ 0x12000000
43#define CLKCFG_CANCLK_MASK 0xFF000000
44
45/* SROM ACCESS Macro */
46#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
47
48/* Registers address offset */
49#define PCH_PHUB_ID_REG 0x0000
50#define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004
51#define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008
52#define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C
53#define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010
54#define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014
55#define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018
56#define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020
57#define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024
58#define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028
59#define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C
60#define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040
61#define CLKCFG_REG_OFFSET 0x500
62
63#define PCH_PHUB_OROM_SIZE 15360
64
65/**
66 * struct pch_phub_reg - PHUB register structure
67 * @phub_id_reg: PHUB_ID register val
68 * @q_pri_val_reg: QUEUE_PRI_VAL register val
69 * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val
70 * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val
71 * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val
72 * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val
73 * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val
74 * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val
75 * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val
76 * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val
77 * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val
78 * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val
79 * @clkcfg_reg: CLK CFG register val
80 * @pch_phub_base_address: Register base address
81 * @pch_phub_extrom_base_address: external rom base address
82 */
83struct pch_phub_reg {
84 u32 phub_id_reg;
85 u32 q_pri_val_reg;
86 u32 rc_q_maxsize_reg;
87 u32 bri_q_maxsize_reg;
88 u32 comp_resp_timeout_reg;
89 u32 bus_slave_control_reg;
90 u32 deadlock_avoid_type_reg;
91 u32 intpin_reg_wpermit_reg0;
92 u32 intpin_reg_wpermit_reg1;
93 u32 intpin_reg_wpermit_reg2;
94 u32 intpin_reg_wpermit_reg3;
95 u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG];
96 u32 clkcfg_reg;
97 void __iomem *pch_phub_base_address;
98 void __iomem *pch_phub_extrom_base_address;
99};
100
101/* SROM SPEC for MAC address assignment offset */
102static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
103
104static DEFINE_MUTEX(pch_phub_mutex);
105
106/**
107 * pch_phub_read_modify_write_reg() - Reading modifying and writing register
108 * @reg_addr_offset: Register offset address value.
109 * @data: Writing value.
110 * @mask: Mask value.
111 */
112static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip,
113 unsigned int reg_addr_offset,
114 unsigned int data, unsigned int mask)
115{
116 void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset;
117 iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr);
118}
119
120/* pch_phub_save_reg_conf - saves register configuration */
121static void pch_phub_save_reg_conf(struct pci_dev *pdev)
122{
123 unsigned int i;
124 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
125
126 void __iomem *p = chip->pch_phub_base_address;
127
128 chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG);
129 chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG);
130 chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
131 chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
132 chip->comp_resp_timeout_reg =
133 ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
134 chip->bus_slave_control_reg =
135 ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
136 chip->deadlock_avoid_type_reg =
137 ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
138 chip->intpin_reg_wpermit_reg0 =
139 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
140 chip->intpin_reg_wpermit_reg1 =
141 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
142 chip->intpin_reg_wpermit_reg2 =
143 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
144 chip->intpin_reg_wpermit_reg3 =
145 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
146 dev_dbg(&pdev->dev, "%s : "
147 "chip->phub_id_reg=%x, "
148 "chip->q_pri_val_reg=%x, "
149 "chip->rc_q_maxsize_reg=%x, "
150 "chip->bri_q_maxsize_reg=%x, "
151 "chip->comp_resp_timeout_reg=%x, "
152 "chip->bus_slave_control_reg=%x, "
153 "chip->deadlock_avoid_type_reg=%x, "
154 "chip->intpin_reg_wpermit_reg0=%x, "
155 "chip->intpin_reg_wpermit_reg1=%x, "
156 "chip->intpin_reg_wpermit_reg2=%x, "
157 "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
158 chip->phub_id_reg,
159 chip->q_pri_val_reg,
160 chip->rc_q_maxsize_reg,
161 chip->bri_q_maxsize_reg,
162 chip->comp_resp_timeout_reg,
163 chip->bus_slave_control_reg,
164 chip->deadlock_avoid_type_reg,
165 chip->intpin_reg_wpermit_reg0,
166 chip->intpin_reg_wpermit_reg1,
167 chip->intpin_reg_wpermit_reg2,
168 chip->intpin_reg_wpermit_reg3);
169 for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
170 chip->int_reduce_control_reg[i] =
171 ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
172 dev_dbg(&pdev->dev, "%s : "
173 "chip->int_reduce_control_reg[%d]=%x\n",
174 __func__, i, chip->int_reduce_control_reg[i]);
175 }
176 chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET);
177}
178
179/* pch_phub_restore_reg_conf - restore register configuration */
180static void pch_phub_restore_reg_conf(struct pci_dev *pdev)
181{
182 unsigned int i;
183 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
184 void __iomem *p;
185 p = chip->pch_phub_base_address;
186
187 iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG);
188 iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG);
189 iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
190 iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
191 iowrite32(chip->comp_resp_timeout_reg,
192 p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
193 iowrite32(chip->bus_slave_control_reg,
194 p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
195 iowrite32(chip->deadlock_avoid_type_reg,
196 p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
197 iowrite32(chip->intpin_reg_wpermit_reg0,
198 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
199 iowrite32(chip->intpin_reg_wpermit_reg1,
200 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
201 iowrite32(chip->intpin_reg_wpermit_reg2,
202 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
203 iowrite32(chip->intpin_reg_wpermit_reg3,
204 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
205 dev_dbg(&pdev->dev, "%s : "
206 "chip->phub_id_reg=%x, "
207 "chip->q_pri_val_reg=%x, "
208 "chip->rc_q_maxsize_reg=%x, "
209 "chip->bri_q_maxsize_reg=%x, "
210 "chip->comp_resp_timeout_reg=%x, "
211 "chip->bus_slave_control_reg=%x, "
212 "chip->deadlock_avoid_type_reg=%x, "
213 "chip->intpin_reg_wpermit_reg0=%x, "
214 "chip->intpin_reg_wpermit_reg1=%x, "
215 "chip->intpin_reg_wpermit_reg2=%x, "
216 "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
217 chip->phub_id_reg,
218 chip->q_pri_val_reg,
219 chip->rc_q_maxsize_reg,
220 chip->bri_q_maxsize_reg,
221 chip->comp_resp_timeout_reg,
222 chip->bus_slave_control_reg,
223 chip->deadlock_avoid_type_reg,
224 chip->intpin_reg_wpermit_reg0,
225 chip->intpin_reg_wpermit_reg1,
226 chip->intpin_reg_wpermit_reg2,
227 chip->intpin_reg_wpermit_reg3);
228 for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
229 iowrite32(chip->int_reduce_control_reg[i],
230 p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
231 dev_dbg(&pdev->dev, "%s : "
232 "chip->int_reduce_control_reg[%d]=%x\n",
233 __func__, i, chip->int_reduce_control_reg[i]);
234 }
235
236 iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET);
237}
238
239/**
240 * pch_phub_read_serial_rom() - Reading Serial ROM
241 * @offset_address: Serial ROM offset address to read.
242 * @data: Read buffer for specified Serial ROM value.
243 */
244static void pch_phub_read_serial_rom(struct pch_phub_reg *chip,
245 unsigned int offset_address, u8 *data)
246{
247 void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
248 offset_address;
249
250 *data = ioread8(mem_addr);
251}
252
253/**
254 * pch_phub_write_serial_rom() - Writing Serial ROM
255 * @offset_address: Serial ROM offset address.
256 * @data: Serial ROM value to write.
257 */
258static int pch_phub_write_serial_rom(struct pch_phub_reg *chip,
259 unsigned int offset_address, u8 data)
260{
261 void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
262 (offset_address & PCH_WORD_ADDR_MASK);
263 int i;
264 unsigned int word_data;
265 unsigned int pos;
266 unsigned int mask;
267 pos = (offset_address % 4) * 8;
268 mask = ~(0xFF << pos);
269
270 iowrite32(PCH_PHUB_ROM_WRITE_ENABLE,
271 chip->pch_phub_extrom_base_address + PHUB_CONTROL);
272
273 word_data = ioread32(mem_addr);
274 iowrite32((word_data & mask) | (u32)data << pos, mem_addr);
275
276 i = 0;
277 while (ioread8(chip->pch_phub_extrom_base_address +
278 PHUB_STATUS) != 0x00) {
279 msleep(1);
280 if (i == PHUB_TIMEOUT)
281 return -ETIMEDOUT;
282 i++;
283 }
284
285 iowrite32(PCH_PHUB_ROM_WRITE_DISABLE,
286 chip->pch_phub_extrom_base_address + PHUB_CONTROL);
287
288 return 0;
289}
290
291/**
292 * pch_phub_read_serial_rom_val() - Read Serial ROM value
293 * @offset_address: Serial ROM address offset value.
294 * @data: Serial ROM value to read.
295 */
296static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip,
297 unsigned int offset_address, u8 *data)
298{
299 unsigned int mem_addr;
300
301 mem_addr = PCH_PHUB_ROM_START_ADDR +
302 pch_phub_mac_offset[offset_address];
303
304 pch_phub_read_serial_rom(chip, mem_addr, data);
305}
306
307/**
308 * pch_phub_write_serial_rom_val() - writing Serial ROM value
309 * @offset_address: Serial ROM address offset value.
310 * @data: Serial ROM value.
311 */
312static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip,
313 unsigned int offset_address, u8 data)
314{
315 int retval;
316 unsigned int mem_addr;
317
318 mem_addr = PCH_PHUB_ROM_START_ADDR +
319 pch_phub_mac_offset[offset_address];
320
321 retval = pch_phub_write_serial_rom(chip, mem_addr, data);
322
323 return retval;
324}
325
326/* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration
327 * for Gigabit Ethernet MAC address
328 */
329static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip)
330{
331 int retval;
332
333 retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc);
334 retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10);
335 retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01);
336 retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02);
337
338 retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00);
339 retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00);
340 retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00);
341 retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80);
342
343 retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc);
344 retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10);
345 retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01);
346 retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18);
347
348 retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc);
349 retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10);
350 retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01);
351 retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19);
352
353 retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc);
354 retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10);
355 retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01);
356 retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a);
357
358 retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01);
359 retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00);
360 retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00);
361 retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00);
362
363 return retval;
364}
365
366/**
367 * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address
368 * @offset_address: Gigabit Ethernet MAC address offset value.
369 * @data: Buffer of the Gigabit Ethernet MAC address value.
370 */
371static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
372{
373 int i;
374 for (i = 0; i < ETH_ALEN; i++)
375 pch_phub_read_serial_rom_val(chip, i, &data[i]);
376}
377
378/**
379 * pch_phub_write_gbe_mac_addr() - Write MAC address
380 * @offset_address: Gigabit Ethernet MAC address offset value.
381 * @data: Gigabit Ethernet MAC address value.
382 */
383static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
384{
385 int retval;
386 int i;
387
388 retval = pch_phub_gbe_serial_rom_conf(chip);
389 if (retval)
390 return retval;
391
392 for (i = 0; i < ETH_ALEN; i++) {
393 retval = pch_phub_write_serial_rom_val(chip, i, data[i]);
394 if (retval)
395 return retval;
396 }
397
398 return retval;
399}
400
401static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
402 struct bin_attribute *attr, char *buf,
403 loff_t off, size_t count)
404{
405 unsigned int rom_signature;
406 unsigned char rom_length;
407 unsigned int tmp;
408 unsigned int addr_offset;
409 unsigned int orom_size;
410 int ret;
411 int err;
412
413 struct pch_phub_reg *chip =
414 dev_get_drvdata(container_of(kobj, struct device, kobj));
415
416 ret = mutex_lock_interruptible(&pch_phub_mutex);
417 if (ret) {
418 err = -ERESTARTSYS;
419 goto return_err_nomutex;
420 }
421
422 /* Get Rom signature */
423 pch_phub_read_serial_rom(chip, 0x80, (unsigned char *)&rom_signature);
424 rom_signature &= 0xff;
425 pch_phub_read_serial_rom(chip, 0x81, (unsigned char *)&tmp);
426 rom_signature |= (tmp & 0xff) << 8;
427 if (rom_signature == 0xAA55) {
428 pch_phub_read_serial_rom(chip, 0x82, &rom_length);
429 orom_size = rom_length * 512;
430 if (orom_size < off) {
431 addr_offset = 0;
432 goto return_ok;
433 }
434 if (orom_size < count) {
435 addr_offset = 0;
436 goto return_ok;
437 }
438
439 for (addr_offset = 0; addr_offset < count; addr_offset++) {
440 pch_phub_read_serial_rom(chip, 0x80 + addr_offset + off,
441 &buf[addr_offset]);
442 }
443 } else {
444 err = -ENODATA;
445 goto return_err;
446 }
447return_ok:
448 mutex_unlock(&pch_phub_mutex);
449 return addr_offset;
450
451return_err:
452 mutex_unlock(&pch_phub_mutex);
453return_err_nomutex:
454 return err;
455}
456
457static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
458 struct bin_attribute *attr,
459 char *buf, loff_t off, size_t count)
460{
461 int err;
462 unsigned int addr_offset;
463 int ret;
464 struct pch_phub_reg *chip =
465 dev_get_drvdata(container_of(kobj, struct device, kobj));
466
467 ret = mutex_lock_interruptible(&pch_phub_mutex);
468 if (ret)
469 return -ERESTARTSYS;
470
471 if (off > PCH_PHUB_OROM_SIZE) {
472 addr_offset = 0;
473 goto return_ok;
474 }
475 if (count > PCH_PHUB_OROM_SIZE) {
476 addr_offset = 0;
477 goto return_ok;
478 }
479
480 for (addr_offset = 0; addr_offset < count; addr_offset++) {
481 if (PCH_PHUB_OROM_SIZE < off + addr_offset)
482 goto return_ok;
483
484 ret = pch_phub_write_serial_rom(chip, 0x80 + addr_offset + off,
485 buf[addr_offset]);
486 if (ret) {
487 err = ret;
488 goto return_err;
489 }
490 }
491
492return_ok:
493 mutex_unlock(&pch_phub_mutex);
494 return addr_offset;
495
496return_err:
497 mutex_unlock(&pch_phub_mutex);
498 return err;
499}
500
501static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
502 char *buf)
503{
504 u8 mac[8];
505 struct pch_phub_reg *chip = dev_get_drvdata(dev);
506
507 pch_phub_read_gbe_mac_addr(chip, mac);
508
509 return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
510 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
511}
512
513static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
514 const char *buf, size_t count)
515{
516 u8 mac[6];
517 struct pch_phub_reg *chip = dev_get_drvdata(dev);
518
519 if (count != 18)
520 return -EINVAL;
521
522 sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
523 (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3],
524 (u32 *)&mac[4], (u32 *)&mac[5]);
525
526 pch_phub_write_gbe_mac_addr(chip, mac);
527
528 return count;
529}
530
531static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac);
532
533static struct bin_attribute pch_bin_attr = {
534 .attr = {
535 .name = "pch_firmware",
536 .mode = S_IRUGO | S_IWUSR,
537 },
538 .size = PCH_PHUB_OROM_SIZE + 1,
539 .read = pch_phub_bin_read,
540 .write = pch_phub_bin_write,
541};
542
543static int __devinit pch_phub_probe(struct pci_dev *pdev,
544 const struct pci_device_id *id)
545{
546 int retval;
547
548 int ret;
549 ssize_t rom_size;
550 struct pch_phub_reg *chip;
551
552 chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL);
553 if (chip == NULL)
554 return -ENOMEM;
555
556 ret = pci_enable_device(pdev);
557 if (ret) {
558 dev_err(&pdev->dev,
559 "%s : pci_enable_device FAILED(ret=%d)", __func__, ret);
560 goto err_pci_enable_dev;
561 }
562 dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__,
563 ret);
564
565 ret = pci_request_regions(pdev, KBUILD_MODNAME);
566 if (ret) {
567 dev_err(&pdev->dev,
568 "%s : pci_request_regions FAILED(ret=%d)", __func__, ret);
569 goto err_req_regions;
570 }
571 dev_dbg(&pdev->dev, "%s : "
572 "pci_request_regions returns %d\n", __func__, ret);
573
574 chip->pch_phub_base_address = pci_iomap(pdev, 1, 0);
575
576
577 if (chip->pch_phub_base_address == 0) {
578 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
579 ret = -ENOMEM;
580 goto err_pci_iomap;
581 }
582 dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value "
583 "in pch_phub_base_address variable is %p\n", __func__,
584 chip->pch_phub_base_address);
585 chip->pch_phub_extrom_base_address = pci_map_rom(pdev, &rom_size);
586
587 if (chip->pch_phub_extrom_base_address == 0) {
588 dev_err(&pdev->dev, "%s : pci_map_rom FAILED", __func__);
589 ret = -ENOMEM;
590 goto err_pci_map;
591 }
592 dev_dbg(&pdev->dev, "%s : "
593 "pci_map_rom SUCCESS and value in "
594 "pch_phub_extrom_base_address variable is %p\n", __func__,
595 chip->pch_phub_extrom_base_address);
596
597 pci_set_drvdata(pdev, chip);
598
599 retval = sysfs_create_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
600 if (retval)
601 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
610 /* set the prefech value */
611 iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
612 /* set the interrupt delay value */
613 iowrite32(0x25, chip->pch_phub_base_address + 0x44);
614
615 return 0;
616exit_bin_attr:
617 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
618
619err_sysfs_create:
620 pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address);
621err_pci_map:
622 pci_iounmap(pdev, chip->pch_phub_base_address);
623err_pci_iomap:
624 pci_release_regions(pdev);
625err_req_regions:
626 pci_disable_device(pdev);
627err_pci_enable_dev:
628 kfree(chip);
629 dev_err(&pdev->dev, "%s returns %d\n", __func__, ret);
630 return ret;
631}
632
633static void __devexit pch_phub_remove(struct pci_dev *pdev)
634{
635 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
636
637 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
638 sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr);
639 pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address);
640 pci_iounmap(pdev, chip->pch_phub_base_address);
641 pci_release_regions(pdev);
642 pci_disable_device(pdev);
643 kfree(chip);
644}
645
646#ifdef CONFIG_PM
647
648static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state)
649{
650 int ret;
651
652 pch_phub_save_reg_conf(pdev);
653 ret = pci_save_state(pdev);
654 if (ret) {
655 dev_err(&pdev->dev,
656 " %s -pci_save_state returns %d\n", __func__, ret);
657 return ret;
658 }
659 pci_enable_wake(pdev, PCI_D3hot, 0);
660 pci_disable_device(pdev);
661 pci_set_power_state(pdev, pci_choose_state(pdev, state));
662
663 return 0;
664}
665
666static int pch_phub_resume(struct pci_dev *pdev)
667{
668 int ret;
669
670 pci_set_power_state(pdev, PCI_D0);
671 pci_restore_state(pdev);
672 ret = pci_enable_device(pdev);
673 if (ret) {
674 dev_err(&pdev->dev,
675 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
676 return ret;
677 }
678
679 pci_enable_wake(pdev, PCI_D3hot, 0);
680 pch_phub_restore_reg_conf(pdev);
681
682 return 0;
683}
684#else
685#define pch_phub_suspend NULL
686#define pch_phub_resume NULL
687#endif /* CONFIG_PM */
688
689static struct pci_device_id pch_phub_pcidev_id[] = {
690 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH1_PHUB)},
691 {0,}
692};
693
694static struct pci_driver pch_phub_driver = {
695 .name = "pch_phub",
696 .id_table = pch_phub_pcidev_id,
697 .probe = pch_phub_probe,
698 .remove = __devexit_p(pch_phub_remove),
699 .suspend = pch_phub_suspend,
700 .resume = pch_phub_resume
701};
702
703static int __init pch_phub_pci_init(void)
704{
705 return pci_register_driver(&pch_phub_driver);
706}
707
708static void __exit pch_phub_pci_exit(void)
709{
710 pci_unregister_driver(&pch_phub_driver);
711}
712
713module_init(pch_phub_pci_init);
714module_exit(pch_phub_pci_exit);
715
716MODULE_DESCRIPTION("PCH Packet Hub PCI Driver");
717MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 10478153641b..4f7a5829ea4c 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -412,9 +412,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
412 412
413 device_initialize(&shost->shost_gendev); 413 device_initialize(&shost->shost_gendev);
414 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); 414 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no);
415#ifndef CONFIG_SYSFS_DEPRECATED
416 shost->shost_gendev.bus = &scsi_bus_type; 415 shost->shost_gendev.bus = &scsi_bus_type;
417#endif
418 shost->shost_gendev.type = &scsi_host_type; 416 shost->shost_gendev.type = &scsi_host_type;
419 417
420 device_initialize(&shost->shost_dev); 418 device_initialize(&shost->shost_dev);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 3d0a1e6e9c48..087821fac8fe 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -417,9 +417,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
417 starget->reap_ref = 1; 417 starget->reap_ref = 1;
418 dev->parent = get_device(parent); 418 dev->parent = get_device(parent);
419 dev_set_name(dev, "target%d:%d:%d", shost->host_no, channel, id); 419 dev_set_name(dev, "target%d:%d:%d", shost->host_no, channel, id);
420#ifndef CONFIG_SYSFS_DEPRECATED
421 dev->bus = &scsi_bus_type; 420 dev->bus = &scsi_bus_type;
422#endif
423 dev->type = &scsi_target_type; 421 dev->type = &scsi_target_type;
424 starget->id = id; 422 starget->id = id;
425 starget->channel = channel; 423 starget->channel = channel;
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 4d3a6fd1a152..a858d2b87b94 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -23,9 +23,10 @@
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/string.h> 24#include <linux/string.h>
25#include <linux/kobject.h> 25#include <linux/kobject.h>
26#include <linux/cdev.h>
26#include <linux/uio_driver.h> 27#include <linux/uio_driver.h>
27 28
28#define UIO_MAX_DEVICES 255 29#define UIO_MAX_DEVICES (1U << MINORBITS)
29 30
30struct uio_device { 31struct uio_device {
31 struct module *owner; 32 struct module *owner;
@@ -41,15 +42,10 @@ struct uio_device {
41}; 42};
42 43
43static int uio_major; 44static int uio_major;
45static struct cdev *uio_cdev;
44static DEFINE_IDR(uio_idr); 46static DEFINE_IDR(uio_idr);
45static const struct file_operations uio_fops; 47static const struct file_operations uio_fops;
46 48
47/* UIO class infrastructure */
48static struct uio_class {
49 struct kref kref;
50 struct class *class;
51} *uio_class;
52
53/* Protect idr accesses */ 49/* Protect idr accesses */
54static DEFINE_MUTEX(minor_lock); 50static DEFINE_MUTEX(minor_lock);
55 51
@@ -232,45 +228,34 @@ static ssize_t show_name(struct device *dev,
232 struct device_attribute *attr, char *buf) 228 struct device_attribute *attr, char *buf)
233{ 229{
234 struct uio_device *idev = dev_get_drvdata(dev); 230 struct uio_device *idev = dev_get_drvdata(dev);
235 if (idev) 231 return sprintf(buf, "%s\n", idev->info->name);
236 return sprintf(buf, "%s\n", idev->info->name);
237 else
238 return -ENODEV;
239} 232}
240static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
241 233
242static ssize_t show_version(struct device *dev, 234static ssize_t show_version(struct device *dev,
243 struct device_attribute *attr, char *buf) 235 struct device_attribute *attr, char *buf)
244{ 236{
245 struct uio_device *idev = dev_get_drvdata(dev); 237 struct uio_device *idev = dev_get_drvdata(dev);
246 if (idev) 238 return sprintf(buf, "%s\n", idev->info->version);
247 return sprintf(buf, "%s\n", idev->info->version);
248 else
249 return -ENODEV;
250} 239}
251static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
252 240
253static ssize_t show_event(struct device *dev, 241static ssize_t show_event(struct device *dev,
254 struct device_attribute *attr, char *buf) 242 struct device_attribute *attr, char *buf)
255{ 243{
256 struct uio_device *idev = dev_get_drvdata(dev); 244 struct uio_device *idev = dev_get_drvdata(dev);
257 if (idev) 245 return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
258 return sprintf(buf, "%u\n",
259 (unsigned int)atomic_read(&idev->event));
260 else
261 return -ENODEV;
262} 246}
263static DEVICE_ATTR(event, S_IRUGO, show_event, NULL);
264 247
265static struct attribute *uio_attrs[] = { 248static struct device_attribute uio_class_attributes[] = {
266 &dev_attr_name.attr, 249 __ATTR(name, S_IRUGO, show_name, NULL),
267 &dev_attr_version.attr, 250 __ATTR(version, S_IRUGO, show_version, NULL),
268 &dev_attr_event.attr, 251 __ATTR(event, S_IRUGO, show_event, NULL),
269 NULL, 252 {}
270}; 253};
271 254
272static struct attribute_group uio_attr_grp = { 255/* UIO class infrastructure */
273 .attrs = uio_attrs, 256static struct class uio_class = {
257 .name = "uio",
258 .dev_attrs = uio_class_attributes,
274}; 259};
275 260
276/* 261/*
@@ -287,10 +272,6 @@ static int uio_dev_add_attributes(struct uio_device *idev)
287 struct uio_port *port; 272 struct uio_port *port;
288 struct uio_portio *portio; 273 struct uio_portio *portio;
289 274
290 ret = sysfs_create_group(&idev->dev->kobj, &uio_attr_grp);
291 if (ret)
292 goto err_group;
293
294 for (mi = 0; mi < MAX_UIO_MAPS; mi++) { 275 for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
295 mem = &idev->info->mem[mi]; 276 mem = &idev->info->mem[mi];
296 if (mem->size == 0) 277 if (mem->size == 0)
@@ -358,8 +339,6 @@ err_map:
358 kobject_put(&map->kobj); 339 kobject_put(&map->kobj);
359 } 340 }
360 kobject_put(idev->map_dir); 341 kobject_put(idev->map_dir);
361 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
362err_group:
363 dev_err(idev->dev, "error creating sysfs files (%d)\n", ret); 342 dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
364 return ret; 343 return ret;
365} 344}
@@ -385,8 +364,6 @@ static void uio_dev_del_attributes(struct uio_device *idev)
385 kobject_put(&port->portio->kobj); 364 kobject_put(&port->portio->kobj);
386 } 365 }
387 kobject_put(idev->portio_dir); 366 kobject_put(idev->portio_dir);
388
389 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
390} 367}
391 368
392static int uio_get_minor(struct uio_device *idev) 369static int uio_get_minor(struct uio_device *idev)
@@ -525,7 +502,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
525 struct uio_listener *listener = filep->private_data; 502 struct uio_listener *listener = filep->private_data;
526 struct uio_device *idev = listener->dev; 503 struct uio_device *idev = listener->dev;
527 504
528 if (idev->info->irq == UIO_IRQ_NONE) 505 if (!idev->info->irq)
529 return -EIO; 506 return -EIO;
530 507
531 poll_wait(filep, &idev->wait, wait); 508 poll_wait(filep, &idev->wait, wait);
@@ -543,7 +520,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
543 ssize_t retval; 520 ssize_t retval;
544 s32 event_count; 521 s32 event_count;
545 522
546 if (idev->info->irq == UIO_IRQ_NONE) 523 if (!idev->info->irq)
547 return -EIO; 524 return -EIO;
548 525
549 if (count != sizeof(s32)) 526 if (count != sizeof(s32))
@@ -591,7 +568,7 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
591 ssize_t retval; 568 ssize_t retval;
592 s32 irq_on; 569 s32 irq_on;
593 570
594 if (idev->info->irq == UIO_IRQ_NONE) 571 if (!idev->info->irq)
595 return -EIO; 572 return -EIO;
596 573
597 if (count != sizeof(s32)) 574 if (count != sizeof(s32))
@@ -745,68 +722,72 @@ static const struct file_operations uio_fops = {
745 722
746static int uio_major_init(void) 723static int uio_major_init(void)
747{ 724{
748 uio_major = register_chrdev(0, "uio", &uio_fops); 725 static const char name[] = "uio";
749 if (uio_major < 0) 726 struct cdev *cdev = NULL;
750 return uio_major; 727 dev_t uio_dev = 0;
751 return 0; 728 int result;
729
730 result = alloc_chrdev_region(&uio_dev, 0, UIO_MAX_DEVICES, name);
731 if (result)
732 goto out;
733
734 result = -ENOMEM;
735 cdev = cdev_alloc();
736 if (!cdev)
737 goto out_unregister;
738
739 cdev->owner = THIS_MODULE;
740 cdev->ops = &uio_fops;
741 kobject_set_name(&cdev->kobj, "%s", name);
742
743 result = cdev_add(cdev, uio_dev, UIO_MAX_DEVICES);
744 if (result)
745 goto out_put;
746
747 uio_major = MAJOR(uio_dev);
748 uio_cdev = cdev;
749 result = 0;
750out:
751 return result;
752out_put:
753 kobject_put(&cdev->kobj);
754out_unregister:
755 unregister_chrdev_region(uio_dev, UIO_MAX_DEVICES);
756 goto out;
752} 757}
753 758
754static void uio_major_cleanup(void) 759static void uio_major_cleanup(void)
755{ 760{
756 unregister_chrdev(uio_major, "uio"); 761 unregister_chrdev_region(MKDEV(uio_major, 0), UIO_MAX_DEVICES);
762 cdev_del(uio_cdev);
757} 763}
758 764
759static int init_uio_class(void) 765static int init_uio_class(void)
760{ 766{
761 int ret = 0; 767 int ret;
762
763 if (uio_class != NULL) {
764 kref_get(&uio_class->kref);
765 goto exit;
766 }
767 768
768 /* This is the first time in here, set everything up properly */ 769 /* This is the first time in here, set everything up properly */
769 ret = uio_major_init(); 770 ret = uio_major_init();
770 if (ret) 771 if (ret)
771 goto exit; 772 goto exit;
772 773
773 uio_class = kzalloc(sizeof(*uio_class), GFP_KERNEL); 774 ret = class_register(&uio_class);
774 if (!uio_class) { 775 if (ret) {
775 ret = -ENOMEM; 776 printk(KERN_ERR "class_register failed for uio\n");
776 goto err_kzalloc; 777 goto err_class_register;
777 }
778
779 kref_init(&uio_class->kref);
780 uio_class->class = class_create(THIS_MODULE, "uio");
781 if (IS_ERR(uio_class->class)) {
782 ret = IS_ERR(uio_class->class);
783 printk(KERN_ERR "class_create failed for uio\n");
784 goto err_class_create;
785 } 778 }
786 return 0; 779 return 0;
787 780
788err_class_create: 781err_class_register:
789 kfree(uio_class);
790 uio_class = NULL;
791err_kzalloc:
792 uio_major_cleanup(); 782 uio_major_cleanup();
793exit: 783exit:
794 return ret; 784 return ret;
795} 785}
796 786
797static void release_uio_class(struct kref *kref) 787static void release_uio_class(void)
798{ 788{
799 /* Ok, we cheat as we know we only have one uio_class */ 789 class_unregister(&uio_class);
800 class_destroy(uio_class->class);
801 kfree(uio_class);
802 uio_major_cleanup(); 790 uio_major_cleanup();
803 uio_class = NULL;
804}
805
806static void uio_class_destroy(void)
807{
808 if (uio_class)
809 kref_put(&uio_class->kref, release_uio_class);
810} 791}
811 792
812/** 793/**
@@ -829,10 +810,6 @@ int __uio_register_device(struct module *owner,
829 810
830 info->uio_dev = NULL; 811 info->uio_dev = NULL;
831 812
832 ret = init_uio_class();
833 if (ret)
834 return ret;
835
836 idev = kzalloc(sizeof(*idev), GFP_KERNEL); 813 idev = kzalloc(sizeof(*idev), GFP_KERNEL);
837 if (!idev) { 814 if (!idev) {
838 ret = -ENOMEM; 815 ret = -ENOMEM;
@@ -848,7 +825,7 @@ int __uio_register_device(struct module *owner,
848 if (ret) 825 if (ret)
849 goto err_get_minor; 826 goto err_get_minor;
850 827
851 idev->dev = device_create(uio_class->class, parent, 828 idev->dev = device_create(&uio_class, parent,
852 MKDEV(uio_major, idev->minor), idev, 829 MKDEV(uio_major, idev->minor), idev,
853 "uio%d", idev->minor); 830 "uio%d", idev->minor);
854 if (IS_ERR(idev->dev)) { 831 if (IS_ERR(idev->dev)) {
@@ -863,9 +840,9 @@ int __uio_register_device(struct module *owner,
863 840
864 info->uio_dev = idev; 841 info->uio_dev = idev;
865 842
866 if (idev->info->irq >= 0) { 843 if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
867 ret = request_irq(idev->info->irq, uio_interrupt, 844 ret = request_irq(info->irq, uio_interrupt,
868 idev->info->irq_flags, idev->info->name, idev); 845 info->irq_flags, info->name, idev);
869 if (ret) 846 if (ret)
870 goto err_request_irq; 847 goto err_request_irq;
871 } 848 }
@@ -875,13 +852,12 @@ int __uio_register_device(struct module *owner,
875err_request_irq: 852err_request_irq:
876 uio_dev_del_attributes(idev); 853 uio_dev_del_attributes(idev);
877err_uio_dev_add_attributes: 854err_uio_dev_add_attributes:
878 device_destroy(uio_class->class, MKDEV(uio_major, idev->minor)); 855 device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
879err_device_create: 856err_device_create:
880 uio_free_minor(idev); 857 uio_free_minor(idev);
881err_get_minor: 858err_get_minor:
882 kfree(idev); 859 kfree(idev);
883err_kzalloc: 860err_kzalloc:
884 uio_class_destroy();
885 return ret; 861 return ret;
886} 862}
887EXPORT_SYMBOL_GPL(__uio_register_device); 863EXPORT_SYMBOL_GPL(__uio_register_device);
@@ -902,15 +878,13 @@ void uio_unregister_device(struct uio_info *info)
902 878
903 uio_free_minor(idev); 879 uio_free_minor(idev);
904 880
905 if (info->irq >= 0) 881 if (info->irq && (info->irq != UIO_IRQ_CUSTOM))
906 free_irq(info->irq, idev); 882 free_irq(info->irq, idev);
907 883
908 uio_dev_del_attributes(idev); 884 uio_dev_del_attributes(idev);
909 885
910 dev_set_drvdata(idev->dev, NULL); 886 device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
911 device_destroy(uio_class->class, MKDEV(uio_major, idev->minor));
912 kfree(idev); 887 kfree(idev);
913 uio_class_destroy();
914 888
915 return; 889 return;
916} 890}
@@ -918,11 +892,12 @@ EXPORT_SYMBOL_GPL(uio_unregister_device);
918 892
919static int __init uio_init(void) 893static int __init uio_init(void)
920{ 894{
921 return 0; 895 return init_uio_class();
922} 896}
923 897
924static void __exit uio_exit(void) 898static void __exit uio_exit(void)
925{ 899{
900 release_uio_class();
926} 901}
927 902
928module_init(uio_init) 903module_init(uio_init)
diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c
index 85c9884a67fd..fc22e1e6f215 100644
--- a/drivers/uio/uio_pci_generic.c
+++ b/drivers/uio/uio_pci_generic.c
@@ -128,12 +128,6 @@ static int __devinit probe(struct pci_dev *pdev,
128 struct uio_pci_generic_dev *gdev; 128 struct uio_pci_generic_dev *gdev;
129 int err; 129 int err;
130 130
131 if (!pdev->irq) {
132 dev_warn(&pdev->dev, "No IRQ assigned to device: "
133 "no support for interrupts?\n");
134 return -ENODEV;
135 }
136
137 err = pci_enable_device(pdev); 131 err = pci_enable_device(pdev);
138 if (err) { 132 if (err) {
139 dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n", 133 dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n",
@@ -141,6 +135,13 @@ static int __devinit probe(struct pci_dev *pdev,
141 return err; 135 return err;
142 } 136 }
143 137
138 if (!pdev->irq) {
139 dev_warn(&pdev->dev, "No IRQ assigned to device: "
140 "no support for interrupts?\n");
141 pci_disable_device(pdev);
142 return -ENODEV;
143 }
144
144 err = verify_pci_2_3(pdev); 145 err = verify_pci_2_3(pdev);
145 if (err) 146 if (err)
146 goto err_verify; 147 goto err_verify;