Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Recognize and maintain s390 storage class memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright IBM Corp. 2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/eadm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "chsc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static struct device *scm_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define to_scm_dev(n) container_of(n, struct scm_device, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define	to_scm_drv(d) container_of(d, struct scm_driver, drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int scmdev_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct scm_device *scmdev = to_scm_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct scm_driver *scmdrv = to_scm_drv(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return scmdrv->probe ? scmdrv->probe(scmdev) : -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int scmdev_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct scm_device *scmdev = to_scm_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct scm_driver *scmdrv = to_scm_drv(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return scmdrv->remove ? scmdrv->remove(scmdev) : -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int scmdev_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return add_uevent_var(env, "MODALIAS=scm:scmdev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static struct bus_type scm_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.name  = "scm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.probe = scmdev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.remove = scmdev_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.uevent = scmdev_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * scm_driver_register() - register a scm driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * @scmdrv: driver to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int scm_driver_register(struct scm_driver *scmdrv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct device_driver *drv = &scmdrv->drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	drv->bus = &scm_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return driver_register(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) EXPORT_SYMBOL_GPL(scm_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * scm_driver_unregister() - deregister a scm driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @scmdrv: driver to be deregistered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) void scm_driver_unregister(struct scm_driver *scmdrv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	driver_unregister(&scmdrv->drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) EXPORT_SYMBOL_GPL(scm_driver_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) void scm_irq_handler(struct aob *aob, blk_status_t error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct aob_rq_header *aobrq = (void *) aob->request.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct scm_device *scmdev = aobrq->scmdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct scm_driver *scmdrv = to_scm_drv(scmdev->dev.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	scmdrv->handler(scmdev, aobrq->data, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) EXPORT_SYMBOL_GPL(scm_irq_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define scm_attr(name)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static ssize_t show_##name(struct device *dev,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	       struct device_attribute *attr, char *buf)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct scm_device *scmdev = to_scm_dev(dev);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int ret;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	device_lock(dev);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ret = sprintf(buf, "%u\n", scmdev->attrs.name);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	device_unlock(dev);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return ret;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) scm_attr(persistence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) scm_attr(oper_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) scm_attr(data_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) scm_attr(rank);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) scm_attr(release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) scm_attr(res_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static struct attribute *scmdev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	&dev_attr_persistence.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	&dev_attr_oper_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	&dev_attr_data_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	&dev_attr_rank.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	&dev_attr_release.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	&dev_attr_res_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static struct attribute_group scmdev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.attrs = scmdev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const struct attribute_group *scmdev_attr_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	&scmdev_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void scmdev_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct scm_device *scmdev = to_scm_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	kfree(scmdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void scmdev_setup(struct scm_device *scmdev, struct sale *sale,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			 unsigned int size, unsigned int max_blk_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	dev_set_name(&scmdev->dev, "%016llx", (unsigned long long) sale->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	scmdev->nr_max_block = max_blk_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	scmdev->address = sale->sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	scmdev->size = 1UL << size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	scmdev->attrs.rank = sale->rank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	scmdev->attrs.persistence = sale->p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	scmdev->attrs.oper_state = sale->op_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	scmdev->attrs.data_state = sale->data_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	scmdev->attrs.rank = sale->rank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	scmdev->attrs.release = sale->r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	scmdev->attrs.res_id = sale->rid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	scmdev->dev.parent = scm_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	scmdev->dev.bus = &scm_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	scmdev->dev.release = scmdev_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	scmdev->dev.groups = scmdev_attr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * Check for state-changes, notify the driver and userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static void scmdev_update(struct scm_device *scmdev, struct sale *sale)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct scm_driver *scmdrv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	device_lock(&scmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	changed = scmdev->attrs.rank != sale->rank ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		  scmdev->attrs.oper_state != sale->op_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	scmdev->attrs.rank = sale->rank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	scmdev->attrs.oper_state = sale->op_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!scmdev->dev.driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	scmdrv = to_scm_drv(scmdev->dev.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (changed && scmdrv->notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		scmdrv->notify(scmdev, SCM_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	device_unlock(&scmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		kobject_uevent(&scmdev->dev.kobj, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int check_address(struct device *dev, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct scm_device *scmdev = to_scm_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	const struct sale *sale = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return scmdev->address == sale->sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static struct scm_device *scmdev_find(struct sale *sale)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	dev = bus_find_device(&scm_bus_type, NULL, sale, check_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return dev ? to_scm_dev(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static int scm_add(struct chsc_scm_info *scm_info, size_t num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct sale *sale, *scmal = scm_info->scmal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct scm_device *scmdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	for (sale = scmal; sale < scmal + num; sale++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		scmdev = scmdev_find(sale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (scmdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			scmdev_update(scmdev, sale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			/* Release reference from scm_find(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			put_device(&scmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		scmdev = kzalloc(sizeof(*scmdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (!scmdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		scmdev_setup(scmdev, sale, scm_info->is, scm_info->mbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		ret = device_register(&scmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			/* Release reference from device_initialize(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			put_device(&scmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int scm_update_information(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct chsc_scm_info *scm_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	u64 token = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	size_t num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	scm_info = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!scm_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		ret = chsc_scm_info(scm_info, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		num = (scm_info->response.length -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		       (offsetof(struct chsc_scm_info, scmal) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			offsetof(struct chsc_scm_info, response))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		      ) / sizeof(struct sale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		ret = scm_add(scm_info, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		token = scm_info->restok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	} while (token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	free_page((unsigned long)scm_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int scm_dev_avail(struct device *dev, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct scm_driver *scmdrv = to_scm_drv(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct scm_device *scmdev = to_scm_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (dev->driver && scmdrv->notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		scmdrv->notify(scmdev, SCM_AVAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int scm_process_availability_information(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return bus_for_each_dev(&scm_bus_type, NULL, NULL, scm_dev_avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int __init scm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	ret = bus_register(&scm_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	scm_root = root_device_register("scm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (IS_ERR(scm_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		bus_unregister(&scm_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return PTR_ERR(scm_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	scm_update_information();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) subsys_initcall_sync(scm_init);