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 ret = device_register(&sch->dev);
187 mutex_unlock(&sch->reg_mutex);
192 * css_sch_device_unregister - unregister a subchannel
193 * @sch: subchannel to be unregistered
195 void css_sch_device_unregister(struct subchannel *sch)
197 mutex_lock(&sch->reg_mutex);
198 if (device_is_registered(&sch->dev))
199 device_unregister(&sch->dev);
200 mutex_unlock(&sch->reg_mutex);
202 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
204 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
209 memset(ssd, 0, sizeof(struct chsc_ssd_info));
210 ssd->path_mask = pmcw->pim;
211 for (i = 0; i < 8; i++) {
213 if (pmcw->pim & mask) {
214 chp_id_init(&ssd->chpid[i]);
215 ssd->chpid[i].id = pmcw->chpid[i];
220 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
225 for (i = 0; i < 8; i++) {
227 if (ssd->path_mask & mask)
228 if (!chp_is_registered(ssd->chpid[i]))
229 chp_new(ssd->chpid[i]);
233 void css_update_ssd_info(struct subchannel *sch)
237 if (cio_is_console(sch->schid)) {
238 /* Console is initialized too early for functions requiring
239 * memory allocation. */
240 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
242 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
244 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
245 ssd_register_chpids(&sch->ssd_info);
249 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
252 struct subchannel *sch = to_subchannel(dev);
254 return sprintf(buf, "%01x\n", sch->st);
257 static DEVICE_ATTR(type, 0444, type_show, NULL);
259 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
262 struct subchannel *sch = to_subchannel(dev);
264 return sprintf(buf, "css:t%01X\n", sch->st);
267 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
269 static struct attribute *subch_attrs[] = {
271 &dev_attr_modalias.attr,
275 static struct attribute_group subch_attr_group = {
276 .attrs = subch_attrs,
279 static struct attribute_group *default_subch_attr_groups[] = {
284 static int css_register_subchannel(struct subchannel *sch)
288 /* Initialize the subchannel structure */
289 sch->dev.parent = &channel_subsystems[0]->device;
290 sch->dev.bus = &css_bus_type;
291 sch->dev.release = &css_subchannel_release;
292 sch->dev.groups = default_subch_attr_groups;
294 * We don't want to generate uevents for I/O subchannels that don't
295 * have a working ccw device behind them since they will be
296 * unregistered before they can be used anyway, so we delay the add
297 * uevent until after device recognition was successful.
298 * Note that we suppress the uevent for all subchannel types;
299 * the subchannel driver can decide itself when it wants to inform
300 * userspace of its existence.
302 dev_set_uevent_suppress(&sch->dev, 1);
303 css_update_ssd_info(sch);
304 /* make it known to the system */
305 ret = css_sch_device_register(sch);
307 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
308 sch->schid.ssid, sch->schid.sch_no, ret);
313 * No driver matched. Generate the uevent now so that
314 * a fitting driver module may be loaded based on the
317 dev_set_uevent_suppress(&sch->dev, 0);
318 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
323 int css_probe_device(struct subchannel_id schid)
326 struct subchannel *sch;
328 sch = css_alloc_subchannel(schid);
331 ret = css_register_subchannel(sch);
333 css_free_subchannel(sch);
338 check_subchannel(struct device * dev, void * data)
340 struct subchannel *sch;
341 struct subchannel_id *schid = data;
343 sch = to_subchannel(dev);
344 return schid_equal(&sch->schid, schid);
348 get_subchannel_by_schid(struct subchannel_id schid)
352 dev = bus_find_device(&css_bus_type, NULL,
353 &schid, check_subchannel);
355 return dev ? to_subchannel(dev) : NULL;
359 * css_sch_is_valid() - check if a subchannel is valid
360 * @schib: subchannel information block for the subchannel
362 int css_sch_is_valid(struct schib *schib)
364 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
366 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
370 EXPORT_SYMBOL_GPL(css_sch_is_valid);
372 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
377 /* Will be done on the slow path. */
380 if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) {
381 /* Unusable - ignore. */
384 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
385 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
387 return css_probe_device(schid);
390 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
395 if (sch->driver->sch_event)
396 ret = sch->driver->sch_event(sch, slow);
399 "Got subchannel machine check but "
400 "no sch_event handler provided.\n");
405 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
407 struct subchannel *sch;
410 sch = get_subchannel_by_schid(schid);
412 ret = css_evaluate_known_subchannel(sch, slow);
413 put_device(&sch->dev);
415 ret = css_evaluate_new_subchannel(schid, slow);
417 css_schedule_eval(schid);
420 static struct idset *slow_subchannel_set;
421 static spinlock_t slow_subchannel_lock;
423 static int __init slow_subchannel_init(void)
425 spin_lock_init(&slow_subchannel_lock);
426 slow_subchannel_set = idset_sch_new();
427 if (!slow_subchannel_set) {
428 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
434 static int slow_eval_known_fn(struct subchannel *sch, void *data)
439 spin_lock_irq(&slow_subchannel_lock);
440 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
441 idset_sch_del(slow_subchannel_set, sch->schid);
442 spin_unlock_irq(&slow_subchannel_lock);
444 rc = css_evaluate_known_subchannel(sch, 1);
446 css_schedule_eval(sch->schid);
451 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
456 spin_lock_irq(&slow_subchannel_lock);
457 eval = idset_sch_contains(slow_subchannel_set, schid);
458 idset_sch_del(slow_subchannel_set, schid);
459 spin_unlock_irq(&slow_subchannel_lock);
461 rc = css_evaluate_new_subchannel(schid, 1);
464 css_schedule_eval(schid);
470 /* These should abort looping */
479 static void css_slow_path_func(struct work_struct *unused)
481 CIO_TRACE_EVENT(4, "slowpath");
482 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
486 static DECLARE_WORK(slow_path_work, css_slow_path_func);
487 struct workqueue_struct *slow_path_wq;
489 void css_schedule_eval(struct subchannel_id schid)
493 spin_lock_irqsave(&slow_subchannel_lock, flags);
494 idset_sch_add(slow_subchannel_set, schid);
495 queue_work(slow_path_wq, &slow_path_work);
496 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
499 void css_schedule_eval_all(void)
503 spin_lock_irqsave(&slow_subchannel_lock, flags);
504 idset_fill(slow_subchannel_set);
505 queue_work(slow_path_wq, &slow_path_work);
506 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
509 void css_wait_for_slow_path(void)
511 flush_workqueue(slow_path_wq);
514 /* Reprobe subchannel if unregistered. */
515 static int reprobe_subchannel(struct subchannel_id schid, void *data)
519 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
520 schid.ssid, schid.sch_no);
524 ret = css_probe_device(schid);
531 /* These should abort looping */
540 static void reprobe_after_idle(struct work_struct *unused)
542 /* Make sure initial subchannel scan is done. */
543 wait_event(ccw_device_init_wq,
544 atomic_read(&ccw_device_init_count) == 0);
546 css_schedule_reprobe();
549 static DECLARE_WORK(reprobe_idle_work, reprobe_after_idle);
551 /* Work function used to reprobe all unregistered subchannels. */
552 static void reprobe_all(struct work_struct *unused)
556 CIO_MSG_EVENT(4, "reprobe start\n");
558 /* Make sure initial subchannel scan is done. */
559 if (atomic_read(&ccw_device_init_count) != 0) {
560 queue_work(ccw_device_work, &reprobe_idle_work);
564 ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL);
566 CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
570 static DECLARE_WORK(css_reprobe_work, reprobe_all);
572 /* Schedule reprobing of all unregistered subchannels. */
573 void css_schedule_reprobe(void)
576 queue_work(slow_path_wq, &css_reprobe_work);
579 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
582 * Called from the machine check handler for subchannel report words.
584 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
586 struct subchannel_id mchk_schid;
589 css_schedule_eval_all();
592 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
593 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
594 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
595 crw0->erc, crw0->rsid);
597 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
598 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
599 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
600 crw1->anc, crw1->erc, crw1->rsid);
601 init_subchannel_id(&mchk_schid);
602 mchk_schid.sch_no = crw0->rsid;
604 mchk_schid.ssid = (crw1->rsid >> 8) & 3;
607 * Since we are always presented with IPI in the CRW, we have to
608 * use stsch() to find out if the subchannel in question has come
611 css_evaluate_subchannel(mchk_schid, 0);
615 __init_channel_subsystem(struct subchannel_id schid, void *data)
617 struct subchannel *sch;
620 if (cio_is_console(schid))
621 sch = cio_get_console_subchannel();
623 sch = css_alloc_subchannel(schid);
632 panic("Out of memory in init_channel_subsystem\n");
633 /* -ENXIO: no more subchannels. */
636 /* -EIO: this subchannel set not supported. */
644 * We register ALL valid subchannels in ioinfo, even those
645 * that have been present before init_channel_subsystem.
646 * These subchannels can't have been registered yet (kmalloc
647 * not working) so we do it now. This is true e.g. for the
648 * console subchannel.
650 css_register_subchannel(sch);
655 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
657 if (css_general_characteristics.mcss) {
658 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
659 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
662 css->global_pgid.pgid_high.cpu_addr = stap();
664 css->global_pgid.pgid_high.cpu_addr = 0;
667 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
668 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
669 css->global_pgid.tod_high = tod_high;
674 channel_subsystem_release(struct device *dev)
676 struct channel_subsystem *css;
679 mutex_destroy(&css->mutex);
680 if (css->pseudo_subchannel) {
681 /* Implies that it has been generated but never registered. */
682 css_subchannel_release(&css->pseudo_subchannel->dev);
683 css->pseudo_subchannel = NULL;
689 css_cm_enable_show(struct device *dev, struct device_attribute *attr,
692 struct channel_subsystem *css = to_css(dev);
697 mutex_lock(&css->mutex);
698 ret = sprintf(buf, "%x\n", css->cm_enabled);
699 mutex_unlock(&css->mutex);
704 css_cm_enable_store(struct device *dev, struct device_attribute *attr,
705 const char *buf, size_t count)
707 struct channel_subsystem *css = to_css(dev);
711 ret = strict_strtoul(buf, 16, &val);
714 mutex_lock(&css->mutex);
717 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
720 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
725 mutex_unlock(&css->mutex);
726 return ret < 0 ? ret : count;
729 static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
731 static int __init setup_css(int nr)
735 struct channel_subsystem *css;
737 css = channel_subsystems[nr];
738 memset(css, 0, sizeof(struct channel_subsystem));
739 css->pseudo_subchannel =
740 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
741 if (!css->pseudo_subchannel)
743 css->pseudo_subchannel->dev.parent = &css->device;
744 css->pseudo_subchannel->dev.release = css_subchannel_release;
745 dev_set_name(&css->pseudo_subchannel->dev, "defunct");
746 ret = cio_create_sch_lock(css->pseudo_subchannel);
748 kfree(css->pseudo_subchannel);
751 mutex_init(&css->mutex);
754 dev_set_name(&css->device, "css%x", nr);
755 css->device.release = channel_subsystem_release;
756 tod_high = (u32) (get_clock() >> 32);
757 css_generate_pgid(css, tod_high);
761 static int css_reboot_event(struct notifier_block *this,
768 for (i = 0; i <= __MAX_CSSID; i++) {
769 struct channel_subsystem *css;
771 css = channel_subsystems[i];
772 mutex_lock(&css->mutex);
774 if (chsc_secm(css, 0))
776 mutex_unlock(&css->mutex);
782 static struct notifier_block css_reboot_notifier = {
783 .notifier_call = css_reboot_event,
787 * Since the css devices are neither on a bus nor have a class
788 * nor have a special device type, we cannot stop/restart channel
789 * path measurements via the normal suspend/resume callbacks, but have
792 static int css_power_event(struct notifier_block *this, unsigned long event,
799 case PM_HIBERNATION_PREPARE:
800 case PM_SUSPEND_PREPARE:
802 for (i = 0; i <= __MAX_CSSID; i++) {
803 struct channel_subsystem *css;
805 css = channel_subsystems[i];
806 mutex_lock(&css->mutex);
807 if (!css->cm_enabled) {
808 mutex_unlock(&css->mutex);
811 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
814 if (__chsc_do_secm(css, 0, secm_area))
816 free_page((unsigned long)secm_area);
820 mutex_unlock(&css->mutex);
823 case PM_POST_HIBERNATION:
824 case PM_POST_SUSPEND:
826 for (i = 0; i <= __MAX_CSSID; i++) {
827 struct channel_subsystem *css;
829 css = channel_subsystems[i];
830 mutex_lock(&css->mutex);
831 if (!css->cm_enabled) {
832 mutex_unlock(&css->mutex);
835 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
838 if (__chsc_do_secm(css, 1, secm_area))
840 free_page((unsigned long)secm_area);
844 mutex_unlock(&css->mutex);
846 /* search for subchannels, which appeared during hibernation */
847 css_schedule_reprobe();
855 static struct notifier_block css_power_notifier = {
856 .notifier_call = css_power_event,
860 * Now that the driver core is running, we can setup our channel subsystem.
861 * The struct subchannel's are created during probing (except for the
862 * static console subchannel).
865 init_channel_subsystem (void)
869 ret = chsc_determine_css_characteristics();
871 goto out; /* No need to continue. */
873 ret = chsc_alloc_sei_area();
877 ret = slow_subchannel_init();
881 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
885 if ((ret = bus_register(&css_bus_type)))
888 /* Try to enable MSS. */
889 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
891 case 0: /* Success. */
892 max_ssid = __MAX_SSID;
899 /* Setup css structure. */
900 for (i = 0; i <= __MAX_CSSID; i++) {
901 struct channel_subsystem *css;
903 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
908 channel_subsystems[i] = css;
911 kfree(channel_subsystems[i]);
914 ret = device_register(&css->device);
916 put_device(&css->device);
919 if (css_chsc_characteristics.secm) {
920 ret = device_create_file(&css->device,
921 &dev_attr_cm_enable);
925 ret = device_register(&css->pseudo_subchannel->dev);
929 ret = register_reboot_notifier(&css_reboot_notifier);
932 ret = register_pm_notifier(&css_power_notifier);
934 unregister_reboot_notifier(&css_reboot_notifier);
939 /* Enable default isc for I/O subchannels. */
940 isc_register(IO_SCH_ISC);
942 for_each_subchannel(__init_channel_subsystem, NULL);
945 if (css_chsc_characteristics.secm)
946 device_remove_file(&channel_subsystems[i]->device,
947 &dev_attr_cm_enable);
949 device_unregister(&channel_subsystems[i]->device);
952 struct channel_subsystem *css;
955 css = channel_subsystems[i];
956 device_unregister(&css->pseudo_subchannel->dev);
957 css->pseudo_subchannel = NULL;
958 if (css_chsc_characteristics.secm)
959 device_remove_file(&css->device,
960 &dev_attr_cm_enable);
961 device_unregister(&css->device);
964 bus_unregister(&css_bus_type);
966 crw_unregister_handler(CRW_RSC_CSS);
967 chsc_free_sei_area();
968 kfree(slow_subchannel_set);
969 pr_alert("The CSS device driver initialization failed with "
974 int sch_is_pseudo_sch(struct subchannel *sch)
976 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
979 static int css_bus_match(struct device *dev, struct device_driver *drv)
981 struct subchannel *sch = to_subchannel(dev);
982 struct css_driver *driver = to_cssdriver(drv);
983 struct css_device_id *id;
985 for (id = driver->subchannel_type; id->match_flags; id++) {
986 if (sch->st == id->type)
993 static int css_probe(struct device *dev)
995 struct subchannel *sch;
998 sch = to_subchannel(dev);
999 sch->driver = to_cssdriver(dev->driver);
1000 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1006 static int css_remove(struct device *dev)
1008 struct subchannel *sch;
1011 sch = to_subchannel(dev);
1012 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
1017 static void css_shutdown(struct device *dev)
1019 struct subchannel *sch;
1021 sch = to_subchannel(dev);
1022 if (sch->driver && sch->driver->shutdown)
1023 sch->driver->shutdown(sch);
1026 static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
1028 struct subchannel *sch = to_subchannel(dev);
1031 ret = add_uevent_var(env, "ST=%01X", sch->st);
1034 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1038 static int css_pm_prepare(struct device *dev)
1040 struct subchannel *sch = to_subchannel(dev);
1041 struct css_driver *drv;
1043 if (mutex_is_locked(&sch->reg_mutex))
1045 if (!sch->dev.driver)
1047 drv = to_cssdriver(sch->dev.driver);
1048 /* Notify drivers that they may not register children. */
1049 return drv->prepare ? drv->prepare(sch) : 0;
1052 static void css_pm_complete(struct device *dev)
1054 struct subchannel *sch = to_subchannel(dev);
1055 struct css_driver *drv;
1057 if (!sch->dev.driver)
1059 drv = to_cssdriver(sch->dev.driver);
1064 static int css_pm_freeze(struct device *dev)
1066 struct subchannel *sch = to_subchannel(dev);
1067 struct css_driver *drv;
1069 if (!sch->dev.driver)
1071 drv = to_cssdriver(sch->dev.driver);
1072 return drv->freeze ? drv->freeze(sch) : 0;
1075 static int css_pm_thaw(struct device *dev)
1077 struct subchannel *sch = to_subchannel(dev);
1078 struct css_driver *drv;
1080 if (!sch->dev.driver)
1082 drv = to_cssdriver(sch->dev.driver);
1083 return drv->thaw ? drv->thaw(sch) : 0;
1086 static int css_pm_restore(struct device *dev)
1088 struct subchannel *sch = to_subchannel(dev);
1089 struct css_driver *drv;
1091 if (!sch->dev.driver)
1093 drv = to_cssdriver(sch->dev.driver);
1094 return drv->restore ? drv->restore(sch) : 0;
1097 static struct dev_pm_ops css_pm_ops = {
1098 .prepare = css_pm_prepare,
1099 .complete = css_pm_complete,
1100 .freeze = css_pm_freeze,
1101 .thaw = css_pm_thaw,
1102 .restore = css_pm_restore,
1105 struct bus_type css_bus_type = {
1107 .match = css_bus_match,
1109 .remove = css_remove,
1110 .shutdown = css_shutdown,
1111 .uevent = css_uevent,
1116 * css_driver_register - register a css driver
1117 * @cdrv: css driver to register
1119 * This is mainly a wrapper around driver_register that sets name
1120 * and bus_type in the embedded struct device_driver correctly.
1122 int css_driver_register(struct css_driver *cdrv)
1124 cdrv->drv.name = cdrv->name;
1125 cdrv->drv.bus = &css_bus_type;
1126 cdrv->drv.owner = cdrv->owner;
1127 return driver_register(&cdrv->drv);
1129 EXPORT_SYMBOL_GPL(css_driver_register);
1132 * css_driver_unregister - unregister a css driver
1133 * @cdrv: css driver to unregister
1135 * This is a wrapper around driver_unregister.
1137 void css_driver_unregister(struct css_driver *cdrv)
1139 driver_unregister(&cdrv->drv);
1141 EXPORT_SYMBOL_GPL(css_driver_unregister);
1143 subsys_initcall(init_channel_subsystem);
1145 MODULE_LICENSE("GPL");
1146 EXPORT_SYMBOL(css_bus_type);