Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Interface for Dynamic Logical Partitioning of I/O Slots on |
| 3 | * RPA-compliant PPC64 platform. |
| 4 | * |
| 5 | * John Rose <johnrose@austin.ibm.com> |
| 6 | * October 2003 |
| 7 | * |
| 8 | * Copyright (C) 2003 IBM. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ |
| 15 | #include <linux/kobject.h> |
| 16 | #include <linux/string.h> |
Greg Kroah-Hartman | 7a54f25 | 2006-10-13 20:05:19 -0700 | [diff] [blame] | 17 | #include <linux/pci_hotplug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "rpadlpar.h" |
| 19 | |
| 20 | #define DLPAR_KOBJ_NAME "control" |
| 21 | #define ADD_SLOT_ATTR_NAME "add_slot" |
| 22 | #define REMOVE_SLOT_ATTR_NAME "remove_slot" |
| 23 | |
| 24 | #define MAX_DRC_NAME_LEN 64 |
| 25 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 26 | |
| 27 | static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 28 | const char *buf, size_t nbytes) |
| 29 | { |
| 30 | char drc_name[MAX_DRC_NAME_LEN]; |
| 31 | char *end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 34 | if (nbytes >= MAX_DRC_NAME_LEN) |
| 35 | return 0; |
| 36 | |
| 37 | memcpy(drc_name, buf, nbytes); |
| 38 | |
| 39 | end = strchr(drc_name, '\n'); |
| 40 | if (!end) |
| 41 | end = &drc_name[nbytes]; |
| 42 | *end = '\0'; |
| 43 | |
| 44 | rc = dlpar_add_slot(drc_name); |
| 45 | if (rc) |
| 46 | return rc; |
| 47 | |
| 48 | return nbytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 51 | static ssize_t add_slot_show(struct kobject *kobj, |
| 52 | struct kobj_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 54 | return sprintf(buf, "0\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 57 | static ssize_t remove_slot_store(struct kobject *kobj, |
| 58 | struct kobj_attribute *attr, |
| 59 | const char *buf, size_t nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | char drc_name[MAX_DRC_NAME_LEN]; |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 62 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | char *end; |
| 64 | |
Linda Xie | 02fe75a | 2005-09-22 00:48:24 -0700 | [diff] [blame] | 65 | if (nbytes >= MAX_DRC_NAME_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return 0; |
| 67 | |
| 68 | memcpy(drc_name, buf, nbytes); |
| 69 | |
| 70 | end = strchr(drc_name, '\n'); |
| 71 | if (!end) |
| 72 | end = &drc_name[nbytes]; |
| 73 | *end = '\0'; |
| 74 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 75 | rc = dlpar_remove_slot(drc_name); |
| 76 | if (rc) |
| 77 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | return nbytes; |
| 80 | } |
| 81 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 82 | static ssize_t remove_slot_show(struct kobject *kobj, |
| 83 | struct kobj_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 85 | return sprintf(buf, "0\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 88 | static struct kobj_attribute add_slot_attr = |
| 89 | __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 91 | static struct kobj_attribute remove_slot_attr = |
| 92 | __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | static struct attribute *default_attrs[] = { |
| 95 | &add_slot_attr.attr, |
| 96 | &remove_slot_attr.attr, |
| 97 | NULL, |
| 98 | }; |
| 99 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 100 | static struct attribute_group dlpar_attr_group = { |
| 101 | .attrs = default_attrs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 104 | static struct kobject *dlpar_kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | int dlpar_sysfs_init(void) |
| 107 | { |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 108 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 110 | dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME, |
| 111 | &pci_hotplug_slots_kset->kobj); |
| 112 | if (!dlpar_kobj) |
| 113 | return -EINVAL; |
| 114 | |
| 115 | error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group); |
| 116 | if (error) |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 117 | kobject_put(dlpar_kobj); |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 118 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void dlpar_sysfs_exit(void) |
| 122 | { |
Greg Kroah-Hartman | f55842f | 2007-11-06 15:03:30 -0800 | [diff] [blame] | 123 | sysfs_remove_group(dlpar_kobj, &dlpar_attr_group); |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 124 | kobject_put(dlpar_kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |