2 * driver for channel subsystem
4 * Copyright IBM Corp. 2002, 2009
6 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
7 * Cornelia Huck (cornelia.huck@de.ibm.com)
10 #define KMSG_COMPONENT "cio"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/list.h>
19 #include <linux/reboot.h>
20 #include <linux/suspend.h>
26 #include "cio_debug.h"
33 int css_init_done = 0;
34 static int need_reprobe = 0;
35 static int max_ssid = 0;
37 struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
40 for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
42 struct subchannel_id schid;
45 init_subchannel_id(&schid);
49 ret = fn(schid, data);
52 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
54 } while (schid.ssid++ < max_ssid);
61 int (*fn_known_sch)(struct subchannel *, void *);
62 int (*fn_unknown_sch)(struct subchannel_id, void *);
65 static int call_fn_known_sch(struct device *dev, void *data)
67 struct subchannel *sch = to_subchannel(dev);
68 struct cb_data *cb = data;
71 idset_sch_del(cb->set, sch->schid);
73 rc = cb->fn_known_sch(sch, cb->data);
77 static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
79 struct cb_data *cb = data;
82 if (idset_sch_contains(cb->set, schid))
83 rc = cb->fn_unknown_sch(schid, cb->data);
87 static int call_fn_all_sch(struct subchannel_id schid, void *data)
89 struct cb_data *cb = data;
90 struct subchannel *sch;
93 sch = get_subchannel_by_schid(schid);
96 rc = cb->fn_known_sch(sch, cb->data);
97 put_device(&sch->dev);
99 if (cb->fn_unknown_sch)
100 rc = cb->fn_unknown_sch(schid, cb->data);
106 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
107 int (*fn_unknown)(struct subchannel_id,
114 cb.fn_known_sch = fn_known;
115 cb.fn_unknown_sch = fn_unknown;
117 cb.set = idset_sch_new();
119 /* fall back to brute force scanning in case of oom */
120 return for_each_subchannel(call_fn_all_sch, &cb);
124 /* Process registered subchannels. */
125 rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
128 /* Process unregistered subchannels. */
130 rc = for_each_subchannel(call_fn_unknown_sch, &cb);
137 static struct subchannel *
138 css_alloc_subchannel(struct subchannel_id schid)
140 struct subchannel *sch;
143 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
145 return ERR_PTR(-ENOMEM);
146 ret = cio_validate_subchannel (sch, schid);
155 css_free_subchannel(struct subchannel *sch)
158 /* Reset intparm to zeroes. */
159 sch->config.intparm = 0;
160 cio_commit_config(sch);
167 css_subchannel_release(struct device *dev)
169 struct subchannel *sch;
171 sch = to_subchannel(dev);
172 if (!cio_is_console(sch->schid)) {
173 /* Reset intparm to zeroes. */
174 sch->config.intparm = 0;
175 cio_commit_config(sch);
181 static int css_sch_device_register(struct subchannel *sch)
185 mutex_lock(&sch->reg_mutex);
186 if (cio_is_console(sch->schid))
187 sch->dev.init_name = cio_get_console_sch_name(sch->schid);
189 dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
191 ret = device_register(&sch->dev);
192 mutex_unlock(&sch->reg_mutex);
197 * css_sch_device_unregister - unregister a subchannel
198 * @sch: subchannel to be unregistered
200 void css_sch_device_unregister(struct subchannel *sch)
202 mutex_lock(&sch->reg_mutex);
203 if (device_is_registered(&sch->dev))
204 device_unregister(&sch->dev);
205 mutex_unlock(&sch->reg_mutex);
207 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
209 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
214 memset(ssd, 0, sizeof(struct chsc_ssd_info));
215 ssd->path_mask = pmcw->pim;
216 for (i = 0; i < 8; i++) {
218 if (pmcw->pim & mask) {
219 chp_id_init(&ssd->chpid[i]);
220 ssd->chpid[i].id = pmcw->chpid[i];
225 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
230 for (i = 0; i < 8; i++) {
232 if (ssd->path_mask & mask)
233 if (!chp_is_registered(ssd->chpid[i]))
234 chp_new(ssd->chpid[i]);
238 void css_update_ssd_info(struct subchannel *sch)
242 if (cio_is_console(sch->schid)) {
243 /* Console is initialized too early for functions requiring
244 * memory allocation. */
245 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
247 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
249 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
250 ssd_register_chpids(&sch->ssd_info);
254 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
257 struct subchannel *sch = to_subchannel(dev);
259 return sprintf(buf, "%01x\n", sch->st);
262 static DEVICE_ATTR(type, 0444, type_show, NULL);
264 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
267 struct subchannel *sch = to_subchannel(dev);
269 return sprintf(buf, "css:t%01X\n", sch->st);
272 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
274 static struct attribute *subch_attrs[] = {
276 &dev_attr_modalias.attr,
280 static struct attribute_group subch_attr_group = {
281 .attrs = subch_attrs,
284 static struct attribute_group *default_subch_attr_groups[] = {
289 static int css_register_subchannel(struct subchannel *sch)
293 /* Initialize the subchannel structure */
294 sch->dev.parent = &channel_subsystems[0]->device;
295 sch->dev.bus = &css_bus_type;
296 sch->dev.release = &css_subchannel_release;
297 sch->dev.groups = default_subch_attr_groups;
299 * We don't want to generate uevents for I/O subchannels that don't
300 * have a working ccw device behind them since they will be
301 * unregistered before they can be used anyway, so we delay the add
302 * uevent until after device recognition was successful.
303 * Note that we suppress the uevent for all subchannel types;
304 * the subchannel driver can decide itself when it wants to inform
305 * userspace of its existence.
307 dev_set_uevent_suppress(&sch->dev, 1);
308 css_update_ssd_info(sch);
309 /* make it known to the system */
310 ret = css_sch_device_register(sch);
312 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
313 sch->schid.ssid, sch->schid.sch_no, ret);
318 * No driver matched. Generate the uevent now so that
319 * a fitting driver module may be loaded based on the
322 dev_set_uevent_suppress(&sch->dev, 0);
323 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
328 int css_probe_device(struct subchannel_id schid)
331 struct subchannel *sch;
333 sch = css_alloc_subchannel(schid);
336 ret = css_register_subchannel(sch);
338 css_free_subchannel(sch);
343 check_subchannel(struct device * dev, void * data)
345 struct subchannel *sch;
346 struct subchannel_id *schid = data;
348 sch = to_subchannel(dev);
349 return schid_equal(&sch->schid, schid);
353 get_subchannel_by_schid(struct subchannel_id schid)
357 dev = bus_find_device(&css_bus_type, NULL,
358 &schid, check_subchannel);
360 return dev ? to_subchannel(dev) : NULL;
364 * css_sch_is_valid() - check if a subchannel is valid
365 * @schib: subchannel information block for the subchannel
367 int css_sch_is_valid(struct schib *schib)
369 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
371 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
375 EXPORT_SYMBOL_GPL(css_sch_is_valid);
377 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
382 /* Will be done on the slow path. */
385 if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) {
386 /* Unusable - ignore. */
389 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
390 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
392 return css_probe_device(schid);
395 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
400 if (sch->driver->sch_event)
401 ret = sch->driver->sch_event(sch, slow);
404 "Got subchannel machine check but "
405 "no sch_event handler provided.\n");
410 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
412 struct subchannel *sch;
415 sch = get_subchannel_by_schid(schid);
417 ret = css_evaluate_known_subchannel(sch, slow);
418 put_device(&sch->dev);
420 ret = css_evaluate_new_subchannel(schid, slow);
422 css_schedule_eval(schid);
425 static struct idset *slow_subchannel_set;
426 static spinlock_t slow_subchannel_lock;
428 static int __init slow_subchannel_init(void)
430 spin_lock_init(&slow_subchannel_lock);
431 slow_subchannel_set = idset_sch_new();
432 if (!slow_subchannel_set) {
433 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
439 static int slow_eval_known_fn(struct subchannel *sch, void *data)
444 spin_lock_irq(&slow_subchannel_lock);
445 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
446 idset_sch_del(slow_subchannel_set, sch->schid);
447 spin_unlock_irq(&slow_subchannel_lock);
449 rc = css_evaluate_known_subchannel(sch, 1);
451 css_schedule_eval(sch->schid);
456 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
461 spin_lock_irq(&slow_subchannel_lock);
462 eval = idset_sch_contains(slow_subchannel_set, schid);
463 idset_sch_del(slow_subchannel_set, schid);
464 spin_unlock_irq(&slow_subchannel_lock);
466 rc = css_evaluate_new_subchannel(schid, 1);
469 css_schedule_eval(schid);
475 /* These should abort looping */
484 static void css_slow_path_func(struct work_struct *unused)
486 CIO_TRACE_EVENT(4, "slowpath");
487 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
491 static DECLARE_WORK(slow_path_work, css_slow_path_func);
492 struct workqueue_struct *slow_path_wq;
494 void css_schedule_eval(struct subchannel_id schid)
498 spin_lock_irqsave(&slow_subchannel_lock, flags);
499 idset_sch_add(slow_subchannel_set, schid);
500 queue_work(slow_path_wq, &slow_path_work);
501 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
504 void css_schedule_eval_all(void)
508 spin_lock_irqsave(&slow_subchannel_lock, flags);
509 idset_fill(slow_subchannel_set);
510 queue_work(slow_path_wq, &slow_path_work);
511 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
514 void css_wait_for_slow_path(void)
516 flush_workqueue(slow_path_wq);
519 /* Reprobe subchannel if unregistered. */
520 static int reprobe_subchannel(struct subchannel_id schid, void *data)
524 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
525 schid.ssid, schid.sch_no);
529 ret = css_probe_device(schid);
536 /* These should abort looping */
545 static void reprobe_after_idle(struct work_struct *unused)
547 /* Make sure initial subchannel scan is done. */
548 wait_event(ccw_device_init_wq,
549 atomic_read(&ccw_device_init_count) == 0);
551 css_schedule_reprobe();
554 static DECLARE_WORK(reprobe_idle_work, reprobe_after_idle);
556 /* Work function used to reprobe all unregistered subchannels. */
557 static void reprobe_all(struct work_struct *unused)
561 CIO_MSG_EVENT(4, "reprobe start\n");
563 /* Make sure initial subchannel scan is done. */
564 if (atomic_read(&ccw_device_init_count) != 0) {
565 queue_work(ccw_device_work, &reprobe_idle_work);
569 ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL);
571 CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
575 static DECLARE_WORK(css_reprobe_work, reprobe_all);
577 /* Schedule reprobing of all unregistered subchannels. */
578 void css_schedule_reprobe(void)
581 queue_work(slow_path_wq, &css_reprobe_work);
584 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
587 * Called from the machine check handler for subchannel report words.
589 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
591 struct subchannel_id mchk_schid;
594 css_schedule_eval_all();
597 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
598 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
599 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
600 crw0->erc, crw0->rsid);
602 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
603 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
604 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
605 crw1->anc, crw1->erc, crw1->rsid);
606 init_subchannel_id(&mchk_schid);
607 mchk_schid.sch_no = crw0->rsid;
609 mchk_schid.ssid = (crw1->rsid >> 8) & 3;
612 * Since we are always presented with IPI in the CRW, we have to
613 * use stsch() to find out if the subchannel in question has come
616 css_evaluate_subchannel(mchk_schid, 0);
620 __init_channel_subsystem(struct subchannel_id schid, void *data)
622 struct subchannel *sch;
625 if (cio_is_console(schid))
626 sch = cio_get_console_subchannel();
628 sch = css_alloc_subchannel(schid);
637 panic("Out of memory in init_channel_subsystem\n");
638 /* -ENXIO: no more subchannels. */
641 /* -EIO: this subchannel set not supported. */
649 * We register ALL valid subchannels in ioinfo, even those
650 * that have been present before init_channel_subsystem.
651 * These subchannels can't have been registered yet (kmalloc
652 * not working) so we do it now. This is true e.g. for the
653 * console subchannel.
655 css_register_subchannel(sch);
660 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
662 if (css_general_characteristics.mcss) {
663 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
664 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
667 css->global_pgid.pgid_high.cpu_addr = stap();
669 css->global_pgid.pgid_high.cpu_addr = 0;
672 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
673 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
674 css->global_pgid.tod_high = tod_high;
679 channel_subsystem_release(struct device *dev)
681 struct channel_subsystem *css;
684 mutex_destroy(&css->mutex);
685 if (css->pseudo_subchannel) {
686 /* Implies that it has been generated but never registered. */
687 css_subchannel_release(&css->pseudo_subchannel->dev);
688 css->pseudo_subchannel = NULL;
694 css_cm_enable_show(struct device *dev, struct device_attribute *attr,
697 struct channel_subsystem *css = to_css(dev);
702 mutex_lock(&css->mutex);
703 ret = sprintf(buf, "%x\n", css->cm_enabled);
704 mutex_unlock(&css->mutex);
709 css_cm_enable_store(struct device *dev, struct device_attribute *attr,
710 const char *buf, size_t count)
712 struct channel_subsystem *css = to_css(dev);
716 ret = strict_strtoul(buf, 16, &val);
719 mutex_lock(&css->mutex);
722 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
725 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
730 mutex_unlock(&css->mutex);
731 return ret < 0 ? ret : count;
734 static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
736 static int __init setup_css(int nr)
740 struct channel_subsystem *css;
742 css = channel_subsystems[nr];
743 memset(css, 0, sizeof(struct channel_subsystem));
744 css->pseudo_subchannel =
745 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
746 if (!css->pseudo_subchannel)
748 css->pseudo_subchannel->dev.parent = &css->device;
749 css->pseudo_subchannel->dev.release = css_subchannel_release;
750 dev_set_name(&css->pseudo_subchannel->dev, "defunct");
751 ret = cio_create_sch_lock(css->pseudo_subchannel);
753 kfree(css->pseudo_subchannel);
756 mutex_init(&css->mutex);
759 dev_set_name(&css->device, "css%x", nr);
760 css->device.release = channel_subsystem_release;
761 tod_high = (u32) (get_clock() >> 32);
762 css_generate_pgid(css, tod_high);
766 static int css_reboot_event(struct notifier_block *this,
773 for (i = 0; i <= __MAX_CSSID; i++) {
774 struct channel_subsystem *css;
776 css = channel_subsystems[i];
777 mutex_lock(&css->mutex);
779 if (chsc_secm(css, 0))
781 mutex_unlock(&css->mutex);
787 static struct notifier_block css_reboot_notifier = {
788 .notifier_call = css_reboot_event,
792 * Since the css devices are neither on a bus nor have a class
793 * nor have a special device type, we cannot stop/restart channel
794 * path measurements via the normal suspend/resume callbacks, but have
797 static int css_power_event(struct notifier_block *this, unsigned long event,
804 case PM_HIBERNATION_PREPARE:
805 case PM_SUSPEND_PREPARE:
807 for (i = 0; i <= __MAX_CSSID; i++) {
808 struct channel_subsystem *css;
810 css = channel_subsystems[i];
811 mutex_lock(&css->mutex);
812 if (!css->cm_enabled) {
813 mutex_unlock(&css->mutex);
816 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
819 if (__chsc_do_secm(css, 0, secm_area))
821 free_page((unsigned long)secm_area);
825 mutex_unlock(&css->mutex);
828 case PM_POST_HIBERNATION:
829 case PM_POST_SUSPEND:
831 for (i = 0; i <= __MAX_CSSID; i++) {
832 struct channel_subsystem *css;
834 css = channel_subsystems[i];
835 mutex_lock(&css->mutex);
836 if (!css->cm_enabled) {
837 mutex_unlock(&css->mutex);
840 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
843 if (__chsc_do_secm(css, 1, secm_area))
845 free_page((unsigned long)secm_area);
849 mutex_unlock(&css->mutex);
851 /* search for subchannels, which appeared during hibernation */
852 css_schedule_reprobe();
860 static struct notifier_block css_power_notifier = {
861 .notifier_call = css_power_event,
865 * Now that the driver core is running, we can setup our channel subsystem.
866 * The struct subchannel's are created during probing (except for the
867 * static console subchannel).
870 init_channel_subsystem (void)
874 ret = chsc_determine_css_characteristics();
876 goto out; /* No need to continue. */
878 ret = chsc_alloc_sei_area();
882 ret = slow_subchannel_init();
886 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
890 if ((ret = bus_register(&css_bus_type)))
893 /* Try to enable MSS. */
894 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
896 case 0: /* Success. */
897 max_ssid = __MAX_SSID;
904 /* Setup css structure. */
905 for (i = 0; i <= __MAX_CSSID; i++) {
906 struct channel_subsystem *css;
908 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
913 channel_subsystems[i] = css;
916 kfree(channel_subsystems[i]);
919 ret = device_register(&css->device);
921 put_device(&css->device);
924 if (css_chsc_characteristics.secm) {
925 ret = device_create_file(&css->device,
926 &dev_attr_cm_enable);
930 ret = device_register(&css->pseudo_subchannel->dev);
934 ret = register_reboot_notifier(&css_reboot_notifier);
937 ret = register_pm_notifier(&css_power_notifier);
939 unregister_reboot_notifier(&css_reboot_notifier);
944 /* Enable default isc for I/O subchannels. */
945 isc_register(IO_SCH_ISC);
947 for_each_subchannel(__init_channel_subsystem, NULL);
950 if (css_chsc_characteristics.secm)
951 device_remove_file(&channel_subsystems[i]->device,
952 &dev_attr_cm_enable);
954 device_unregister(&channel_subsystems[i]->device);
957 struct channel_subsystem *css;
960 css = channel_subsystems[i];
961 device_unregister(&css->pseudo_subchannel->dev);
962 css->pseudo_subchannel = NULL;
963 if (css_chsc_characteristics.secm)
964 device_remove_file(&css->device,
965 &dev_attr_cm_enable);
966 device_unregister(&css->device);
969 bus_unregister(&css_bus_type);
971 crw_unregister_handler(CRW_RSC_CSS);
972 chsc_free_sei_area();
973 kfree(slow_subchannel_set);
974 pr_alert("The CSS device driver initialization failed with "
979 int sch_is_pseudo_sch(struct subchannel *sch)
981 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
984 static int css_bus_match(struct device *dev, struct device_driver *drv)
986 struct subchannel *sch = to_subchannel(dev);
987 struct css_driver *driver = to_cssdriver(drv);
988 struct css_device_id *id;
990 for (id = driver->subchannel_type; id->match_flags; id++) {
991 if (sch->st == id->type)
998 static int css_probe(struct device *dev)
1000 struct subchannel *sch;
1003 sch = to_subchannel(dev);
1004 sch->driver = to_cssdriver(dev->driver);
1005 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1011 static int css_remove(struct device *dev)
1013 struct subchannel *sch;
1016 sch = to_subchannel(dev);
1017 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
1022 static void css_shutdown(struct device *dev)
1024 struct subchannel *sch;
1026 sch = to_subchannel(dev);
1027 if (sch->driver && sch->driver->shutdown)
1028 sch->driver->shutdown(sch);
1031 static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
1033 struct subchannel *sch = to_subchannel(dev);
1036 ret = add_uevent_var(env, "ST=%01X", sch->st);
1039 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1043 static int css_pm_prepare(struct device *dev)
1045 struct subchannel *sch = to_subchannel(dev);
1046 struct css_driver *drv;
1048 if (mutex_is_locked(&sch->reg_mutex))
1050 if (!sch->dev.driver)
1052 drv = to_cssdriver(sch->dev.driver);
1053 /* Notify drivers that they may not register children. */
1054 return drv->prepare ? drv->prepare(sch) : 0;
1057 static void css_pm_complete(struct device *dev)
1059 struct subchannel *sch = to_subchannel(dev);
1060 struct css_driver *drv;
1062 if (!sch->dev.driver)
1064 drv = to_cssdriver(sch->dev.driver);
1069 static int css_pm_freeze(struct device *dev)
1071 struct subchannel *sch = to_subchannel(dev);
1072 struct css_driver *drv;
1074 if (!sch->dev.driver)
1076 drv = to_cssdriver(sch->dev.driver);
1077 return drv->freeze ? drv->freeze(sch) : 0;
1080 static int css_pm_thaw(struct device *dev)
1082 struct subchannel *sch = to_subchannel(dev);
1083 struct css_driver *drv;
1085 if (!sch->dev.driver)
1087 drv = to_cssdriver(sch->dev.driver);
1088 return drv->thaw ? drv->thaw(sch) : 0;
1091 static int css_pm_restore(struct device *dev)
1093 struct subchannel *sch = to_subchannel(dev);
1094 struct css_driver *drv;
1096 if (!sch->dev.driver)
1098 drv = to_cssdriver(sch->dev.driver);
1099 return drv->restore ? drv->restore(sch) : 0;
1102 static struct dev_pm_ops css_pm_ops = {
1103 .prepare = css_pm_prepare,
1104 .complete = css_pm_complete,
1105 .freeze = css_pm_freeze,
1106 .thaw = css_pm_thaw,
1107 .restore = css_pm_restore,
1110 struct bus_type css_bus_type = {
1112 .match = css_bus_match,
1114 .remove = css_remove,
1115 .shutdown = css_shutdown,
1116 .uevent = css_uevent,
1121 * css_driver_register - register a css driver
1122 * @cdrv: css driver to register
1124 * This is mainly a wrapper around driver_register that sets name
1125 * and bus_type in the embedded struct device_driver correctly.
1127 int css_driver_register(struct css_driver *cdrv)
1129 cdrv->drv.name = cdrv->name;
1130 cdrv->drv.bus = &css_bus_type;
1131 cdrv->drv.owner = cdrv->owner;
1132 return driver_register(&cdrv->drv);
1134 EXPORT_SYMBOL_GPL(css_driver_register);
1137 * css_driver_unregister - unregister a css driver
1138 * @cdrv: css driver to unregister
1140 * This is a wrapper around driver_unregister.
1142 void css_driver_unregister(struct css_driver *cdrv)
1144 driver_unregister(&cdrv->drv);
1146 EXPORT_SYMBOL_GPL(css_driver_unregister);
1148 subsys_initcall(init_channel_subsystem);
1150 MODULE_LICENSE("GPL");
1151 EXPORT_SYMBOL(css_bus_type);