Browse Source

[settings] Make built-in settings a linker table

Allow for configurable provision of built-in settings by placing them
in a linker table rather than an array.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
3e975ecf3f
2 changed files with 68 additions and 46 deletions
  1. 46
    46
      src/core/settings.c
  2. 22
    0
      src/include/ipxe/settings.h

+ 46
- 46
src/core/settings.c View File

@@ -2247,29 +2247,8 @@ struct setting priority_setting __setting ( SETTING_MISC ) = {
2247 2247
  ******************************************************************************
2248 2248
  */
2249 2249
 
2250
-/** A built-in setting operation */
2251
-struct builtin_setting_operation {
2252
-	/** Setting */
2253
-	struct setting *setting;
2254
-	/** Fetch setting value
2255
-	 *
2256
-	 * @v data		Buffer to fill with setting data
2257
-	 * @v len		Length of buffer
2258
-	 * @ret len		Length of setting data, or negative error
2259
-	 */
2260
-	int ( * fetch ) ( void *data, size_t len );
2261
-};
2262
-
2263 2250
 /** Built-in setting scope */
2264
-static struct settings_scope builtin_scope;
2265
-
2266
-/** Error number setting */
2267
-struct setting errno_setting __setting ( SETTING_MISC ) = {
2268
-	.name = "errno",
2269
-	.description = "Last error",
2270
-	.type = &setting_type_uint32,
2271
-	.scope = &builtin_scope,
2272
-};
2251
+struct settings_scope builtin_scope;
2273 2252
 
2274 2253
 /**
2275 2254
  * Fetch error number setting
@@ -2289,14 +2268,20 @@ static int errno_fetch ( void *data, size_t len ) {
2289 2268
 	return sizeof ( content );
2290 2269
 }
2291 2270
 
2292
-/** Build architecture setting */
2293
-struct setting buildarch_setting __setting ( SETTING_MISC ) = {
2294
-	.name = "buildarch",
2295
-	.description = "Build architecture",
2296
-	.type = &setting_type_string,
2271
+/** Error number setting */
2272
+struct setting errno_setting __setting ( SETTING_MISC ) = {
2273
+	.name = "errno",
2274
+	.description = "Last error",
2275
+	.type = &setting_type_uint32,
2297 2276
 	.scope = &builtin_scope,
2298 2277
 };
2299 2278
 
2279
+/** Error number built-in setting */
2280
+struct builtin_setting errno_builtin_setting __builtin_setting = {
2281
+	.setting = &errno_setting,
2282
+	.fetch = errno_fetch,
2283
+};
2284
+
2300 2285
 /**
2301 2286
  * Fetch build architecture setting
2302 2287
  *
@@ -2311,14 +2296,20 @@ static int buildarch_fetch ( void *data, size_t len ) {
2311 2296
 	return ( sizeof ( buildarch ) - 1 /* NUL */ );
2312 2297
 }
2313 2298
 
2314
-/** Platform setting */
2315
-struct setting platform_setting __setting ( SETTING_MISC ) = {
2316
-	.name = "platform",
2317
-	.description = "Platform",
2299
+/** Build architecture setting */
2300
+struct setting buildarch_setting __setting ( SETTING_MISC ) = {
2301
+	.name = "buildarch",
2302
+	.description = "Build architecture",
2318 2303
 	.type = &setting_type_string,
2319 2304
 	.scope = &builtin_scope,
2320 2305
 };
2321 2306
 
2307
+/** Build architecture built-in setting */
2308
+struct builtin_setting buildarch_builtin_setting __builtin_setting = {
2309
+	.setting = &buildarch_setting,
2310
+	.fetch = buildarch_fetch,
2311
+};
2312
+
2322 2313
 /**
2323 2314
  * Fetch platform setting
2324 2315
  *
@@ -2333,14 +2324,20 @@ static int platform_fetch ( void *data, size_t len ) {
2333 2324
 	return ( sizeof ( platform ) - 1 /* NUL */ );
2334 2325
 }
2335 2326
 
2336
-/** Version setting */
2337
-struct setting version_setting __setting ( SETTING_MISC ) = {
2338
-	.name = "version",
2339
-	.description = "Version",
2327
+/** Platform setting */
2328
+struct setting platform_setting __setting ( SETTING_MISC ) = {
2329
+	.name = "platform",
2330
+	.description = "Platform",
2340 2331
 	.type = &setting_type_string,
2341 2332
 	.scope = &builtin_scope,
2342 2333
 };
2343 2334
 
2335
+/** Platform built-in setting */
2336
+struct builtin_setting platform_builtin_setting __builtin_setting = {
2337
+	.setting = &platform_setting,
2338
+	.fetch = platform_fetch,
2339
+};
2340
+
2344 2341
 /**
2345 2342
  * Fetch version setting
2346 2343
  *
@@ -2353,12 +2350,18 @@ static int version_fetch ( void *data, size_t len ) {
2353 2350
 	return ( strlen ( product_version ) );
2354 2351
 }
2355 2352
 
2356
-/** List of built-in setting operations */
2357
-static struct builtin_setting_operation builtin_setting_operations[] = {
2358
-	{ &errno_setting, errno_fetch },
2359
-	{ &buildarch_setting, buildarch_fetch },
2360
-	{ &platform_setting, platform_fetch },
2361
-	{ &version_setting, version_fetch },
2353
+/** Version setting */
2354
+struct setting version_setting __setting ( SETTING_MISC ) = {
2355
+	.name = "version",
2356
+	.description = "Version",
2357
+	.type = &setting_type_string,
2358
+	.scope = &builtin_scope,
2359
+};
2360
+
2361
+/** Version built-in setting */
2362
+struct builtin_setting version_builtin_setting __builtin_setting = {
2363
+	.setting = &version_setting,
2364
+	.fetch = version_fetch,
2362 2365
 };
2363 2366
 
2364 2367
 /**
@@ -2373,12 +2376,9 @@ static struct builtin_setting_operation builtin_setting_operations[] = {
2373 2376
 static int builtin_fetch ( struct settings *settings __unused,
2374 2377
 			   struct setting *setting,
2375 2378
 			   void *data, size_t len ) {
2376
-	struct builtin_setting_operation *builtin;
2377
-	unsigned int i;
2379
+	struct builtin_setting *builtin;
2378 2380
 
2379
-	for ( i = 0 ; i < ( sizeof ( builtin_setting_operations ) /
2380
-			    sizeof ( builtin_setting_operations[0] ) ) ; i++ ) {
2381
-		builtin = &builtin_setting_operations[i];
2381
+	for_each_table_entry ( builtin, BUILTIN_SETTINGS ) {
2382 2382
 		if ( setting_cmp ( setting, builtin->setting ) == 0 )
2383 2383
 			return builtin->fetch ( data, len );
2384 2384
 	}

+ 22
- 0
src/include/ipxe/settings.h View File

@@ -253,6 +253,28 @@ struct settings_applicator {
253 253
 /** Declare a settings applicator */
254 254
 #define __settings_applicator __table_entry ( SETTINGS_APPLICATORS, 01 )
255 255
 
256
+/** A built-in setting */
257
+struct builtin_setting {
258
+	/** Setting */
259
+	struct setting *setting;
260
+	/** Fetch setting value
261
+	 *
262
+	 * @v data		Buffer to fill with setting data
263
+	 * @v len		Length of buffer
264
+	 * @ret len		Length of setting data, or negative error
265
+	 */
266
+	int ( * fetch ) ( void *data, size_t len );
267
+};
268
+
269
+/** Built-in settings table */
270
+#define BUILTIN_SETTINGS __table ( struct builtin_setting, "builtin_settings" )
271
+
272
+/** Declare a built-in setting */
273
+#define __builtin_setting __table_entry ( BUILTIN_SETTINGS, 01 )
274
+
275
+/** Built-in setting scope */
276
+extern struct settings_scope builtin_scope;
277
+
256 278
 /**
257 279
  * A generic settings block
258 280
  *

Loading…
Cancel
Save