From 62eaf4c0e11a3f07723a821735018c4cbbdfbe22 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 26 Jul 2020 13:49:20 +0200 Subject: [PATCH] mmc_bus: add execute_command function For now it just forwards the command to the SDHCI controller. The bus will gain more features and functions as work advances (tracking which card is active, arbitration of DMA transfers, etc). Change-Id: I094eb84f27e7789387a3f8fb65fba1e5fcfa3e8a Reviewed-on: https://review.haiku-os.org/c/haiku/+/3094 Reviewed-by: waddlesplash --- headers/private/drivers/mmc.h | 9 ++++ .../kernel/bus_managers/mmc/mmc_bus.cpp | 1 + .../kernel/bus_managers/mmc/mmc_module.cpp | 44 ++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/headers/private/drivers/mmc.h b/headers/private/drivers/mmc.h index 8638e5fe1e..2723962192 100644 --- a/headers/private/drivers/mmc.h +++ b/headers/private/drivers/mmc.h @@ -35,4 +35,13 @@ typedef struct mmc_bus_interface { } mmc_bus_interface; +// Interface between mmc device driver (mmc_disk, sdio drivers, ...) and mmc_bus +typedef struct mmc_device_interface { + driver_module_info info; + + status_t (*execute_command)(device_node* node, uint8_t command, + uint32_t argument, uint32_t* result); +} mmc_device_interface; + + #endif /* _MMC_H */ diff --git a/src/add-ons/kernel/bus_managers/mmc/mmc_bus.cpp b/src/add-ons/kernel/bus_managers/mmc/mmc_bus.cpp index cf289fdd30..b756861d74 100644 --- a/src/add-ons/kernel/bus_managers/mmc/mmc_bus.cpp +++ b/src/add-ons/kernel/bus_managers/mmc/mmc_bus.cpp @@ -178,6 +178,7 @@ MMCBus::WorkerThread(void* cookie) device_attr attrs[] = { { B_DEVICE_BUS, B_STRING_TYPE, {string: "mmc" }}, + { B_DEVICE_PRETTY_NAME, B_STRING_TYPE, {string: "mmc device" }}, { B_DEVICE_VENDOR_ID, B_UINT32_TYPE, {ui32: vendor}}, { B_DEVICE_ID, B_STRING_TYPE, {string: name}}, { B_DEVICE_UNIQUE_ID, B_UINT32_TYPE, {ui32: serial}}, diff --git a/src/add-ons/kernel/bus_managers/mmc/mmc_module.cpp b/src/add-ons/kernel/bus_managers/mmc/mmc_module.cpp index cb917f8d53..5104f874ad 100644 --- a/src/add-ons/kernel/bus_managers/mmc/mmc_module.cpp +++ b/src/add-ons/kernel/bus_managers/mmc/mmc_module.cpp @@ -78,6 +78,27 @@ mmc_bus_added_device(device_node* parent) } +static status_t +mmc_bus_execute_command(device_node* node, uint8_t command, uint32_t argument, + uint32_t* result) +{ + // FIXME store these in the bus cookie or something instead of + // getting/putting the parents each time. + mmc_bus_interface* sdhci; + void* cookie; + + TRACE("In mmc_bus_execute_command\n"); + device_node* parent = gDeviceManager->get_parent_node(node); + device_node* grandparent = gDeviceManager->get_parent_node(parent); + gDeviceManager->get_driver(grandparent, (driver_module_info**)&sdhci, + &cookie); + gDeviceManager->put_node(grandparent); + gDeviceManager->put_node(parent); + + return sdhci->execute_command(cookie, command, argument, result); +} + + static status_t std_ops(int32 op, ...) { @@ -113,18 +134,21 @@ driver_module_info mmc_bus_device_module = { }; -driver_module_info mmc_bus_controller_module = { +mmc_device_interface mmc_bus_controller_module = { { - MMC_BUS_MODULE_NAME, - 0, - &std_ops - }, + { + MMC_BUS_MODULE_NAME, + 0, + &std_ops + }, - NULL, // supported devices - mmc_bus_added_device, - NULL, - NULL, - NULL + NULL, // supported devices + mmc_bus_added_device, + NULL, + NULL, + NULL + }, + mmc_bus_execute_command };