1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2021 Intel Corporation. All rights reserved. 3 */ 4 5 #ifndef SPDK_INIT_INTERNAL_H 6 #define SPDK_INIT_INTERNAL_H 7 8 #include "spdk/stdinc.h" 9 #include "spdk/queue.h" 10 11 struct spdk_json_write_ctx; 12 13 struct spdk_subsystem { 14 const char *name; 15 /* User must call spdk_subsystem_init_next() when they are done with their initialization. */ 16 void (*init)(void); 17 void (*fini)(void); 18 19 /** 20 * Write JSON configuration handler. 21 * 22 * \param w JSON write context 23 */ 24 void (*write_config_json)(struct spdk_json_write_ctx *w); 25 TAILQ_ENTRY(spdk_subsystem) tailq; 26 }; 27 28 struct spdk_subsystem_depend { 29 const char *name; 30 const char *depends_on; 31 TAILQ_ENTRY(spdk_subsystem_depend) tailq; 32 }; 33 34 void spdk_add_subsystem(struct spdk_subsystem *subsystem); 35 void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend); 36 37 void spdk_subsystem_init_next(int rc); 38 void spdk_subsystem_fini_next(void); 39 40 /** 41 * \brief Register a new subsystem 42 */ 43 #define SPDK_SUBSYSTEM_REGISTER(_name) \ 44 __attribute__((constructor)) static void _name ## _register(void) \ 45 { \ 46 spdk_add_subsystem(&_name); \ 47 } 48 49 /** 50 * \brief Declare that a subsystem depends on another subsystem. 51 */ 52 #define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on) \ 53 static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \ 54 .name = #_name, \ 55 .depends_on = #_depends_on, \ 56 }; \ 57 __attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \ 58 { \ 59 spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \ 60 } 61 62 #endif 63