8 #include <linux/device.h>
9 #include <linux/module.h>
11 #include <linux/slab.h>
17 static struct device *scm_root;
21 #define to_scm_dev(n) container_of(n, struct scm_device, dev)
22 #define to_scm_drv(d) container_of(d, struct scm_driver, drv)
24 static int scmdev_probe(
struct device *
dev)
32 static int scmdev_remove(
struct device *
dev)
45 static struct bus_type scm_bus_type = {
47 .probe = scmdev_probe,
48 .remove = scmdev_remove,
49 .uevent = scmdev_uevent,
60 drv->
bus = &scm_bus_type;
81 if (!eadm_ops || !try_module_get(eadm_ops->
owner))
92 module_put(eadm_ops->
owner);
129 #define scm_attr(name) \
130 static ssize_t show_##name(struct device *dev, \
131 struct device_attribute *attr, char *buf) \
133 struct scm_device *scmdev = to_scm_dev(dev); \
137 ret = sprintf(buf, "%u\n", scmdev->attrs.name); \
138 device_unlock(dev); \
142 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
151 static struct attribute *scmdev_attrs[] = {
152 &dev_attr_persistence.attr,
153 &dev_attr_oper_state.attr,
154 &dev_attr_data_state.attr,
156 &dev_attr_release.attr,
157 &dev_attr_res_id.attr,
162 .attrs = scmdev_attrs,
170 static void scmdev_release(
struct device *dev)
178 unsigned int size,
unsigned int max_blk_count)
185 scmdev->
attrs.persistence = sale->
p;
189 scmdev->
attrs.release = sale->
r;
191 scmdev->
dev.parent = scm_root;
192 scmdev->
dev.bus = &scm_bus_type;
193 scmdev->
dev.release = scmdev_release;
194 scmdev->
dev.groups = scmdev_attr_groups;
205 device_lock(&scmdev->
dev);
206 changed = scmdev->
attrs.rank != sale->
rank ||
210 if (!scmdev->
dev.driver)
213 if (changed && scmdrv->
notify)
216 device_unlock(&scmdev->
dev);
221 static int check_address(
struct device *dev,
void *
data)
224 struct sale *sale =
data;
229 static struct scm_device *scmdev_find(
struct sale *sale)
238 static int scm_add(
struct chsc_scm_info *scm_info,
size_t num)
240 struct sale *sale, *scmal = scm_info->
scmal;
244 for (sale = scmal; sale < scmal + num; sale++) {
245 scmdev = scmdev_find(sale);
247 scmdev_update(scmdev, sale);
252 scmdev = kzalloc(
sizeof(*scmdev),
GFP_KERNEL);
255 scmdev_setup(scmdev, sale, scm_info->
is, scm_info->
mbc);
286 ) /
sizeof(
struct sale);
288 ret = scm_add(scm_info, num);
309 if (IS_ERR(scm_root)) {
311 return PTR_ERR(scm_root);