1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef SPDK_INTERNAL_EVENT_H 35 #define SPDK_INTERNAL_EVENT_H 36 37 #include "spdk/stdinc.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #include "spdk/event.h" 44 #include "spdk/json.h" 45 #include "spdk/thread.h" 46 47 struct spdk_event { 48 uint32_t lcore; 49 spdk_event_fn fn; 50 void *arg1; 51 void *arg2; 52 }; 53 54 int spdk_reactors_init(void); 55 void spdk_reactors_fini(void); 56 57 void spdk_reactors_start(void); 58 void spdk_reactors_stop(void *arg1); 59 60 struct spdk_subsystem { 61 const char *name; 62 /* User must call spdk_subsystem_init_next() when they are done with their initialization. */ 63 void (*init)(void); 64 void (*fini)(void); 65 void (*config)(FILE *fp); 66 67 /** 68 * Write JSON configuration handler. 69 * 70 * \param w JSON write context 71 */ 72 void (*write_config_json)(struct spdk_json_write_ctx *w); 73 TAILQ_ENTRY(spdk_subsystem) tailq; 74 }; 75 76 TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem); 77 extern struct spdk_subsystem_list g_subsystems; 78 79 struct spdk_subsystem *spdk_subsystem_find(struct spdk_subsystem_list *list, const char *name); 80 81 struct spdk_subsystem_depend { 82 const char *name; 83 const char *depends_on; 84 TAILQ_ENTRY(spdk_subsystem_depend) tailq; 85 }; 86 87 TAILQ_HEAD(spdk_subsystem_depend_list, spdk_subsystem_depend); 88 extern struct spdk_subsystem_depend_list g_subsystems_deps; 89 90 void spdk_add_subsystem(struct spdk_subsystem *subsystem); 91 void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend); 92 93 typedef void (*spdk_subsystem_init_fn)(int rc, void *ctx); 94 void spdk_subsystem_init(spdk_subsystem_init_fn cb_fn, void *cb_arg); 95 void spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg); 96 void spdk_subsystem_init_next(int rc); 97 void spdk_subsystem_fini_next(void); 98 void spdk_subsystem_config(FILE *fp); 99 void spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr, 100 spdk_subsystem_init_fn cb_fn, void *cb_arg); 101 102 /** 103 * Save pointed \c subsystem configuration to the JSON write context \c w. In case of 104 * error \c null is written to the JSON context. 105 * 106 * \param w JSON write context 107 * \param subsystem the subsystem to query 108 */ 109 void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem); 110 111 void spdk_rpc_initialize(const char *listen_addr); 112 void spdk_rpc_finish(void); 113 114 /** 115 * \brief Register a new subsystem 116 */ 117 #define SPDK_SUBSYSTEM_REGISTER(_name) \ 118 __attribute__((constructor)) static void _name ## _register(void) \ 119 { \ 120 spdk_add_subsystem(&_name); \ 121 } 122 123 /** 124 * \brief Declare that a subsystem depends on another subsystem. 125 */ 126 #define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on) \ 127 static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \ 128 .name = #_name, \ 129 .depends_on = #_depends_on, \ 130 }; \ 131 __attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \ 132 { \ 133 spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \ 134 } 135 136 #ifdef __cplusplus 137 } 138 #endif 139 140 #endif /* SPDK_INTERNAL_EVENT_H */ 141