Lines Matching refs:tb
123 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_show() local
128 uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_show()
132 pm_runtime_get_sync(&tb->dev); in boot_acl_show()
134 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_show()
138 ret = tb->cm_ops->get_boot_acl(tb, uuids, tb->nboot_acl); in boot_acl_show()
140 mutex_unlock(&tb->lock); in boot_acl_show()
143 mutex_unlock(&tb->lock); in boot_acl_show()
145 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { in boot_acl_show()
149 ret += sysfs_emit_at(buf, ret, "%s", i < tb->nboot_acl - 1 ? "," : "\n"); in boot_acl_show()
153 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_show()
154 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_show()
163 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_store() local
174 if (count > (UUID_STRING_LEN + 1) * tb->nboot_acl + 1) in boot_acl_store()
176 if (count < tb->nboot_acl - 1) in boot_acl_store()
183 acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_store()
190 while ((s = strsep(&uuid_str, ",")) != NULL && i < tb->nboot_acl) { in boot_acl_store()
206 if (s || i < tb->nboot_acl) { in boot_acl_store()
211 pm_runtime_get_sync(&tb->dev); in boot_acl_store()
213 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_store()
217 ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); in boot_acl_store()
220 kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); in boot_acl_store()
222 mutex_unlock(&tb->lock); in boot_acl_store()
225 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_store()
226 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_store()
240 const struct tb *tb = container_of(dev, struct tb, dev); in deauthorization_show() local
244 if (tb->security_level == TB_SECURITY_USER || in deauthorization_show()
245 tb->security_level == TB_SECURITY_SECURE) in deauthorization_show()
246 deauthorization = !!tb->cm_ops->disapprove_switch; in deauthorization_show()
256 struct tb *tb = container_of(dev, struct tb, dev); in iommu_dma_protection_show() local
258 return sysfs_emit(buf, "%d\n", tb->nhi->iommu_dma_protection); in iommu_dma_protection_show()
265 struct tb *tb = container_of(dev, struct tb, dev); in security_show() local
268 if (tb->security_level < ARRAY_SIZE(tb_security_names)) in security_show()
269 name = tb_security_names[tb->security_level]; in security_show()
287 struct tb *tb = container_of(dev, struct tb, dev); in domain_attr_is_visible() local
290 if (tb->nboot_acl && in domain_attr_is_visible()
291 tb->cm_ops->get_boot_acl && in domain_attr_is_visible()
292 tb->cm_ops->set_boot_acl) in domain_attr_is_visible()
320 struct tb *tb = container_of(dev, struct tb, dev); in tb_domain_release() local
322 tb_ctl_free(tb->ctl); in tb_domain_release()
323 destroy_workqueue(tb->wq); in tb_domain_release()
324 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_release()
325 mutex_destroy(&tb->lock); in tb_domain_release()
326 kfree(tb); in tb_domain_release()
337 struct tb *tb = data; in tb_domain_event_cb() local
339 if (!tb->cm_ops->handle_event) { in tb_domain_event_cb()
340 tb_warn(tb, "domain does not have event handler\n"); in tb_domain_event_cb()
348 return tb_xdomain_handle_request(tb, type, buf, size); in tb_domain_event_cb()
352 tb->cm_ops->handle_event(tb, type, buf, size); in tb_domain_event_cb()
373 struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize) in tb_domain_alloc()
375 struct tb *tb; in tb_domain_alloc() local
385 tb = kzalloc(sizeof(*tb) + privsize, GFP_KERNEL); in tb_domain_alloc()
386 if (!tb) in tb_domain_alloc()
389 tb->nhi = nhi; in tb_domain_alloc()
390 mutex_init(&tb->lock); in tb_domain_alloc()
392 tb->index = ida_simple_get(&tb_domain_ida, 0, 0, GFP_KERNEL); in tb_domain_alloc()
393 if (tb->index < 0) in tb_domain_alloc()
396 tb->wq = alloc_ordered_workqueue("thunderbolt%d", 0, tb->index); in tb_domain_alloc()
397 if (!tb->wq) in tb_domain_alloc()
400 tb->ctl = tb_ctl_alloc(nhi, timeout_msec, tb_domain_event_cb, tb); in tb_domain_alloc()
401 if (!tb->ctl) in tb_domain_alloc()
404 tb->dev.parent = &nhi->pdev->dev; in tb_domain_alloc()
405 tb->dev.bus = &tb_bus_type; in tb_domain_alloc()
406 tb->dev.type = &tb_domain_type; in tb_domain_alloc()
407 tb->dev.groups = domain_attr_groups; in tb_domain_alloc()
408 dev_set_name(&tb->dev, "domain%d", tb->index); in tb_domain_alloc()
409 device_initialize(&tb->dev); in tb_domain_alloc()
411 return tb; in tb_domain_alloc()
414 destroy_workqueue(tb->wq); in tb_domain_alloc()
416 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_alloc()
418 kfree(tb); in tb_domain_alloc()
434 int tb_domain_add(struct tb *tb) in tb_domain_add() argument
438 if (WARN_ON(!tb->cm_ops)) in tb_domain_add()
441 mutex_lock(&tb->lock); in tb_domain_add()
446 tb_ctl_start(tb->ctl); in tb_domain_add()
448 if (tb->cm_ops->driver_ready) { in tb_domain_add()
449 ret = tb->cm_ops->driver_ready(tb); in tb_domain_add()
454 tb_dbg(tb, "security level set to %s\n", in tb_domain_add()
455 tb_security_names[tb->security_level]); in tb_domain_add()
457 ret = device_add(&tb->dev); in tb_domain_add()
462 if (tb->cm_ops->start) { in tb_domain_add()
463 ret = tb->cm_ops->start(tb); in tb_domain_add()
469 mutex_unlock(&tb->lock); in tb_domain_add()
471 device_init_wakeup(&tb->dev, true); in tb_domain_add()
473 pm_runtime_no_callbacks(&tb->dev); in tb_domain_add()
474 pm_runtime_set_active(&tb->dev); in tb_domain_add()
475 pm_runtime_enable(&tb->dev); in tb_domain_add()
476 pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); in tb_domain_add()
477 pm_runtime_mark_last_busy(&tb->dev); in tb_domain_add()
478 pm_runtime_use_autosuspend(&tb->dev); in tb_domain_add()
483 device_del(&tb->dev); in tb_domain_add()
485 tb_ctl_stop(tb->ctl); in tb_domain_add()
486 mutex_unlock(&tb->lock); in tb_domain_add()
498 void tb_domain_remove(struct tb *tb) in tb_domain_remove() argument
500 mutex_lock(&tb->lock); in tb_domain_remove()
501 if (tb->cm_ops->stop) in tb_domain_remove()
502 tb->cm_ops->stop(tb); in tb_domain_remove()
504 tb_ctl_stop(tb->ctl); in tb_domain_remove()
505 mutex_unlock(&tb->lock); in tb_domain_remove()
507 flush_workqueue(tb->wq); in tb_domain_remove()
508 device_unregister(&tb->dev); in tb_domain_remove()
517 int tb_domain_suspend_noirq(struct tb *tb) in tb_domain_suspend_noirq() argument
526 mutex_lock(&tb->lock); in tb_domain_suspend_noirq()
527 if (tb->cm_ops->suspend_noirq) in tb_domain_suspend_noirq()
528 ret = tb->cm_ops->suspend_noirq(tb); in tb_domain_suspend_noirq()
530 tb_ctl_stop(tb->ctl); in tb_domain_suspend_noirq()
531 mutex_unlock(&tb->lock); in tb_domain_suspend_noirq()
543 int tb_domain_resume_noirq(struct tb *tb) in tb_domain_resume_noirq() argument
547 mutex_lock(&tb->lock); in tb_domain_resume_noirq()
548 tb_ctl_start(tb->ctl); in tb_domain_resume_noirq()
549 if (tb->cm_ops->resume_noirq) in tb_domain_resume_noirq()
550 ret = tb->cm_ops->resume_noirq(tb); in tb_domain_resume_noirq()
551 mutex_unlock(&tb->lock); in tb_domain_resume_noirq()
556 int tb_domain_suspend(struct tb *tb) in tb_domain_suspend() argument
558 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0; in tb_domain_suspend()
561 int tb_domain_freeze_noirq(struct tb *tb) in tb_domain_freeze_noirq() argument
565 mutex_lock(&tb->lock); in tb_domain_freeze_noirq()
566 if (tb->cm_ops->freeze_noirq) in tb_domain_freeze_noirq()
567 ret = tb->cm_ops->freeze_noirq(tb); in tb_domain_freeze_noirq()
569 tb_ctl_stop(tb->ctl); in tb_domain_freeze_noirq()
570 mutex_unlock(&tb->lock); in tb_domain_freeze_noirq()
575 int tb_domain_thaw_noirq(struct tb *tb) in tb_domain_thaw_noirq() argument
579 mutex_lock(&tb->lock); in tb_domain_thaw_noirq()
580 tb_ctl_start(tb->ctl); in tb_domain_thaw_noirq()
581 if (tb->cm_ops->thaw_noirq) in tb_domain_thaw_noirq()
582 ret = tb->cm_ops->thaw_noirq(tb); in tb_domain_thaw_noirq()
583 mutex_unlock(&tb->lock); in tb_domain_thaw_noirq()
588 void tb_domain_complete(struct tb *tb) in tb_domain_complete() argument
590 if (tb->cm_ops->complete) in tb_domain_complete()
591 tb->cm_ops->complete(tb); in tb_domain_complete()
594 int tb_domain_runtime_suspend(struct tb *tb) in tb_domain_runtime_suspend() argument
596 if (tb->cm_ops->runtime_suspend) { in tb_domain_runtime_suspend()
597 int ret = tb->cm_ops->runtime_suspend(tb); in tb_domain_runtime_suspend()
601 tb_ctl_stop(tb->ctl); in tb_domain_runtime_suspend()
605 int tb_domain_runtime_resume(struct tb *tb) in tb_domain_runtime_resume() argument
607 tb_ctl_start(tb->ctl); in tb_domain_runtime_resume()
608 if (tb->cm_ops->runtime_resume) { in tb_domain_runtime_resume()
609 int ret = tb->cm_ops->runtime_resume(tb); in tb_domain_runtime_resume()
625 int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw) in tb_domain_disapprove_switch() argument
627 if (!tb->cm_ops->disapprove_switch) in tb_domain_disapprove_switch()
630 return tb->cm_ops->disapprove_switch(tb, sw); in tb_domain_disapprove_switch()
642 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch() argument
646 if (!tb->cm_ops->approve_switch) in tb_domain_approve_switch()
654 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch()
668 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch_key() argument
673 if (!tb->cm_ops->approve_switch || !tb->cm_ops->add_switch_key) in tb_domain_approve_switch_key()
681 ret = tb->cm_ops->add_switch_key(tb, sw); in tb_domain_approve_switch_key()
685 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch_key()
700 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_challenge_switch_key() argument
710 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) in tb_domain_challenge_switch_key()
719 ret = tb->cm_ops->challenge_switch_key(tb, sw, challenge, response); in tb_domain_challenge_switch_key()
754 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_challenge_switch_key()
773 int tb_domain_disconnect_pcie_paths(struct tb *tb) in tb_domain_disconnect_pcie_paths() argument
775 if (!tb->cm_ops->disconnect_pcie_paths) in tb_domain_disconnect_pcie_paths()
778 return tb->cm_ops->disconnect_pcie_paths(tb); in tb_domain_disconnect_pcie_paths()
797 int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_domain_approve_xdomain_paths() argument
801 if (!tb->cm_ops->approve_xdomain_paths) in tb_domain_approve_xdomain_paths()
804 return tb->cm_ops->approve_xdomain_paths(tb, xd, transmit_path, in tb_domain_approve_xdomain_paths()
824 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_domain_disconnect_xdomain_paths() argument
828 if (!tb->cm_ops->disconnect_xdomain_paths) in tb_domain_disconnect_xdomain_paths()
831 return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, in tb_domain_disconnect_xdomain_paths()
838 struct tb *tb = data; in disconnect_xdomain() local
842 if (xd && xd->tb == tb) in disconnect_xdomain()
858 int tb_domain_disconnect_all_paths(struct tb *tb) in tb_domain_disconnect_all_paths() argument
862 ret = tb_domain_disconnect_pcie_paths(tb); in tb_domain_disconnect_all_paths()
866 return bus_for_each_dev(&tb_bus_type, NULL, tb, disconnect_xdomain); in tb_domain_disconnect_all_paths()