Переглянути джерело

[settings] Add "busdevfn" setting type

Allow network device's "busloc" setting to be formatted as a PCI
bus:dev.fn address using e.g. ${net0/busloc:busdevfn}.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 роки тому
джерело
коміт
3dbcce51ea
3 змінених файлів з 58 додано та 0 видалено
  1. 47
    0
      src/core/settings.c
  2. 1
    0
      src/include/ipxe/settings.h
  3. 10
    0
      src/tests/settings_test.c

+ 47
- 0
src/core/settings.c Переглянути файл

@@ -33,6 +33,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
33 33
 #include <ipxe/uuid.h>
34 34
 #include <ipxe/uri.h>
35 35
 #include <ipxe/base16.h>
36
+#include <ipxe/pci.h>
36 37
 #include <ipxe/init.h>
37 38
 #include <ipxe/settings.h>
38 39
 
@@ -1857,6 +1858,52 @@ struct setting_type setting_type_uuid __setting_type = {
1857 1858
 	.format = format_uuid_setting,
1858 1859
 };
1859 1860
 
1861
+/**
1862
+ * Parse PCI bus:dev.fn setting value
1863
+ *
1864
+ * @v value		Formatted setting value
1865
+ * @v buf		Buffer to contain raw value
1866
+ * @v len		Length of buffer
1867
+ * @ret len		Length of raw value, or negative error
1868
+ */
1869
+static int parse_busdevfn_setting ( const char *value __unused,
1870
+				    void *buf __unused, size_t len __unused ) {
1871
+	return -ENOTSUP;
1872
+}
1873
+
1874
+/**
1875
+ * Format PCI bus:dev.fn setting value
1876
+ *
1877
+ * @v raw		Raw setting value
1878
+ * @v raw_len		Length of raw setting value
1879
+ * @v buf		Buffer to contain formatted value
1880
+ * @v len		Length of buffer
1881
+ * @ret len		Length of formatted value, or negative error
1882
+ */
1883
+static int format_busdevfn_setting ( const void *raw, size_t raw_len, char *buf,
1884
+				     size_t len ) {
1885
+	signed long dummy;
1886
+	unsigned long busdevfn;
1887
+	int check_len;
1888
+
1889
+	/* Extract numeric value */
1890
+	check_len = numeric_setting_value ( raw, raw_len, &dummy, &busdevfn );
1891
+	if ( check_len < 0 )
1892
+		return check_len;
1893
+	assert ( check_len == ( int ) raw_len );
1894
+
1895
+	/* Format value */
1896
+	return snprintf ( buf, len, "%02lx:%02lx.%lx", PCI_BUS ( busdevfn ),
1897
+			  PCI_SLOT ( busdevfn ), PCI_FUNC ( busdevfn ) );
1898
+}
1899
+
1900
+/** PCI bus:dev.fn setting type */
1901
+struct setting_type setting_type_busdevfn __setting_type = {
1902
+	.name = "busdevfn",
1903
+	.parse = parse_busdevfn_setting,
1904
+	.format = format_busdevfn_setting,
1905
+};
1906
+
1860 1907
 /******************************************************************************
1861 1908
  *
1862 1909
  * Setting expansion

+ 1
- 0
src/include/ipxe/settings.h Переглянути файл

@@ -324,6 +324,7 @@ extern struct setting_type setting_type_hex __setting_type;
324 324
 extern struct setting_type setting_type_hexhyp __setting_type;
325 325
 extern struct setting_type setting_type_hexraw __setting_type;
326 326
 extern struct setting_type setting_type_uuid __setting_type;
327
+extern struct setting_type setting_type_busdevfn __setting_type;
327 328
 
328 329
 extern struct setting ip_setting __setting ( SETTING_IPv4 );
329 330
 extern struct setting netmask_setting __setting ( SETTING_IPv4 );

+ 10
- 0
src/tests/settings_test.c Переглянути файл

@@ -182,6 +182,12 @@ static struct setting test_uuid_setting = {
182 182
 	.type = &setting_type_uuid,
183 183
 };
184 184
 
185
+/** Test PCI bus:dev.fn setting type */
186
+static struct setting test_busdevfn_setting = {
187
+	.name = "test_busdevfn",
188
+	.type = &setting_type_busdevfn,
189
+};
190
+
185 191
 /**
186 192
  * Perform settings self-tests
187 193
  *
@@ -282,6 +288,10 @@ static void settings_test_exec ( void ) {
282 288
 			  0x7a, 0x7c, 0xfe, 0x4f, 0xca, 0x4a, 0x57 ),
283 289
 		    "1a6a749d-0eda-461a-a87a-7cfe4fca4a57" );
284 290
 
291
+	/* "busdevfn" setting type (no store capability) */
292
+	fetchf_ok ( &test_settings, &test_busdevfn_setting,
293
+		    RAW ( 0x03, 0x45 ), "03:08.5" );
294
+
285 295
 	/* Clear and unregister test settings block */
286 296
 	clear_settings ( &test_settings );
287 297
 	unregister_settings ( &test_settings );

Завантаження…
Відмінити
Зберегти