18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * TURBOchannel driver services. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2005 James Simmons 58c2ecf20Sopenharmony_ci * Copyright (c) 2006 Maciej W. Rozycki 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Loosely based on drivers/dio/dio-driver.c and 88c2ecf20Sopenharmony_ci * drivers/pci/pci-driver.c. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU 118c2ecf20Sopenharmony_ci * General Public License. See the file "COPYING" in the main 128c2ecf20Sopenharmony_ci * directory of this archive for more details. 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/init.h> 168c2ecf20Sopenharmony_ci#include <linux/module.h> 178c2ecf20Sopenharmony_ci#include <linux/tc.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/** 208c2ecf20Sopenharmony_ci * tc_register_driver - register a new TC driver 218c2ecf20Sopenharmony_ci * @drv: the driver structure to register 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Adds the driver structure to the list of registered drivers 248c2ecf20Sopenharmony_ci * Returns a negative value on error, otherwise 0. 258c2ecf20Sopenharmony_ci * If no error occurred, the driver remains registered even if 268c2ecf20Sopenharmony_ci * no device was claimed during registration. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ciint tc_register_driver(struct tc_driver *tdrv) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci return driver_register(&tdrv->driver); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ciEXPORT_SYMBOL(tc_register_driver); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/** 358c2ecf20Sopenharmony_ci * tc_unregister_driver - unregister a TC driver 368c2ecf20Sopenharmony_ci * @drv: the driver structure to unregister 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * Deletes the driver structure from the list of registered TC drivers, 398c2ecf20Sopenharmony_ci * gives it a chance to clean up by calling its remove() function for 408c2ecf20Sopenharmony_ci * each device it was responsible for, and marks those devices as 418c2ecf20Sopenharmony_ci * driverless. 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_civoid tc_unregister_driver(struct tc_driver *tdrv) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci driver_unregister(&tdrv->driver); 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ciEXPORT_SYMBOL(tc_unregister_driver); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/** 508c2ecf20Sopenharmony_ci * tc_match_device - tell if a TC device structure has a matching 518c2ecf20Sopenharmony_ci * TC device ID structure 528c2ecf20Sopenharmony_ci * @tdrv: the TC driver to earch for matching TC device ID strings 538c2ecf20Sopenharmony_ci * @tdev: the TC device structure to match against 548c2ecf20Sopenharmony_ci * 558c2ecf20Sopenharmony_ci * Used by a driver to check whether a TC device present in the 568c2ecf20Sopenharmony_ci * system is in its list of supported devices. Returns the matching 578c2ecf20Sopenharmony_ci * tc_device_id structure or %NULL if there is no match. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_cistatic const struct tc_device_id *tc_match_device(struct tc_driver *tdrv, 608c2ecf20Sopenharmony_ci struct tc_dev *tdev) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci const struct tc_device_id *id = tdrv->id_table; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci if (id) { 658c2ecf20Sopenharmony_ci while (id->name[0] || id->vendor[0]) { 668c2ecf20Sopenharmony_ci if (strcmp(tdev->name, id->name) == 0 && 678c2ecf20Sopenharmony_ci strcmp(tdev->vendor, id->vendor) == 0) 688c2ecf20Sopenharmony_ci return id; 698c2ecf20Sopenharmony_ci id++; 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci return NULL; 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/** 768c2ecf20Sopenharmony_ci * tc_bus_match - Tell if a device structure has a matching 778c2ecf20Sopenharmony_ci * TC device ID structure 788c2ecf20Sopenharmony_ci * @dev: the device structure to match against 798c2ecf20Sopenharmony_ci * @drv: the device driver to search for matching TC device ID strings 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * Used by a driver to check whether a TC device present in the 828c2ecf20Sopenharmony_ci * system is in its list of supported devices. Returns 1 if there 838c2ecf20Sopenharmony_ci * is a match or 0 otherwise. 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_cistatic int tc_bus_match(struct device *dev, struct device_driver *drv) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci struct tc_dev *tdev = to_tc_dev(dev); 888c2ecf20Sopenharmony_ci struct tc_driver *tdrv = to_tc_driver(drv); 898c2ecf20Sopenharmony_ci const struct tc_device_id *id; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci id = tc_match_device(tdrv, tdev); 928c2ecf20Sopenharmony_ci if (id) 938c2ecf20Sopenharmony_ci return 1; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci return 0; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct bus_type tc_bus_type = { 998c2ecf20Sopenharmony_ci .name = "tc", 1008c2ecf20Sopenharmony_ci .match = tc_bus_match, 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ciEXPORT_SYMBOL(tc_bus_type); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic int __init tc_driver_init(void) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci return bus_register(&tc_bus_type); 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cipostcore_initcall(tc_driver_init); 110