1 /*- 2 * Copyright (c) 2025, Samsung Electronics Co., Ltd. 3 * Written by Jaeyoon Choi 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8 #include <sys/param.h> 9 #include <sys/bus.h> 10 #include <sys/conf.h> 11 #include <sys/module.h> 12 13 #include "ufshci_private.h" 14 15 MALLOC_DEFINE(M_UFSHCI, "ufshci", "ufshci(4) memory allocations"); 16 17 int 18 ufshci_attach(device_t dev) 19 { 20 struct ufshci_controller *ctrlr = device_get_softc(dev); 21 int status; 22 23 status = ufshci_ctrlr_construct(ctrlr, dev); 24 if (status != 0) { 25 ufshci_ctrlr_destruct(ctrlr, dev); 26 return (status); 27 } 28 29 ctrlr->config_hook.ich_func = ufshci_ctrlr_start_config_hook; 30 ctrlr->config_hook.ich_arg = ctrlr; 31 32 if (config_intrhook_establish(&ctrlr->config_hook) != 0) 33 return (ENOMEM); 34 35 return (0); 36 } 37 38 int 39 ufshci_detach(device_t dev) 40 { 41 struct ufshci_controller *ctrlr = device_get_softc(dev); 42 43 config_intrhook_drain(&ctrlr->config_hook); 44 45 ufshci_ctrlr_destruct(ctrlr, dev); 46 47 return (0); 48 } 49 50 void 51 ufshci_completion_poll_cb(void *arg, const struct ufshci_completion *cpl, 52 bool error) 53 { 54 struct ufshci_completion_poll_status *status = arg; 55 56 /* 57 * Copy status into the argument passed by the caller, so that the 58 * caller can check the status to determine if the the request passed 59 * or failed. 60 */ 61 memcpy(&status->cpl.response_upiu, &cpl->response_upiu, cpl->size); 62 status->error = error; 63 atomic_store_rel_int(&status->done, 1); 64 } 65 66 static int 67 ufshci_modevent(module_t mod __unused, int type __unused, void *argp __unused) 68 { 69 return (0); 70 } 71 72 static moduledata_t ufshci_mod = { "ufshci", ufshci_modevent, 0 }; 73 74 DECLARE_MODULE(ufshci, ufshci_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); 75 MODULE_VERSION(ufshci, 1); 76 MODULE_DEPEND(ufshci, cam, 1, 1, 1); 77