From 8cace3f05003c6cb4d38c36890055f03151c2ad4 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Fri, 16 Oct 2026 02:39:56 +0800 Subject: Remove old code Signed-off-by: Richard Qin --- drivers/base/driver.cc | 72 -------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 drivers/base/driver.cc (limited to 'drivers/base/driver.cc') diff --git a/drivers/base/driver.cc b/drivers/base/driver.cc deleted file mode 100644 index ce15b6d..0000000 --- a/drivers/base/driver.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * drivers/base/driver.cc — driver_register / driver_unregister. - * - * Mirrors Linux drivers/base/driver.c. Registers a device_driver on - * its bus and tries to bind any unbound matching devices. - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include -#include - -/* Implemented in core.cc — bind a device to a driver on its bus. - * Returns 1 on success, 0 on no-match-or-probe-fail. */ -int device_try_bind(device* dev, device_driver* drv); - -int driver_register(device_driver* drv) -{ - if (drv == nullptr || drv->bus == nullptr) { - return -EINVAL; - } - if (!drv->bus->registered) { - kprintf("[driver] register '%s' fail: bus '%s' not registered\n", - drv->name != nullptr ? drv->name : "?", - drv->bus->name != nullptr ? drv->bus->name : "?"); - return -ENODEV; - } - - drv->bus_node.init(); - drv->devices.init(); - - LockGuard g(drv->bus->lock); - list_add_tail(&drv->bus_node, &drv->bus->drivers); - - /* Try to bind any unbound devices already on the bus. */ - list_node* cur = drv->bus->devices.next; - while (cur != &drv->bus->devices) { - device* dev = list_entry(cur); - cur = cur->next; - if (dev->driver == nullptr) { - device_try_bind(dev, drv); - } - } - return 0; -} - -void driver_unregister(device_driver* drv) -{ - if (drv == nullptr || drv->bus == nullptr) { - return; - } - - LockGuard g(drv->bus->lock); - - /* Unbind every device bound to this driver. */ - while (!drv->devices.is_empty()) { - list_node* first = drv->devices.next; - device* dev = list_entry(first); - if (drv->remove != nullptr) { - drv->remove(dev); - } - list_del_init(&dev->driver_list); - dev->driver = nullptr; - } - list_del_init(&drv->bus_node); -} -- cgit v1.2.3