2 * drivers/firmware/qemu_fw_cfg.c
4 * Copyright 2015 Carnegie Mellon University
6 * Expose entries from QEMU's firmware configuration (fw_cfg) device in
7 * sysfs (read-only, under "/sys/firmware/qemu_fw_cfg/...").
9 * The fw_cfg device may be instantiated via either an ACPI node (on x86
10 * and select subsets of aarch64), a Device Tree node (on arm), or using
11 * a kernel module (or command line) parameter with the following syntax:
13 * [fw_cfg.]ioport=<size>@<base>[:<ctrl_off>:<data_off>]
15 * [fw_cfg.]mmio=<size>@<base>[:<ctrl_off>:<data_off>]
18 * <size> := size of ioport or mmio range
19 * <base> := physical base address of ioport or mmio range
20 * <ctrl_off> := (optional) offset of control register
21 * <data_off> := (optional) offset of data register
24 * fw_cfg.ioport=2@0x510:0:1 (the default on x86)
26 * fw_cfg.mmio=0xA@0x9020000:8:0 (the default on arm)
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/acpi.h>
32 #include <linux/slab.h>
34 #include <linux/ioport.h>
36 MODULE_AUTHOR("Gabriel L. Somlo <somlo@cmu.edu>");
37 MODULE_DESCRIPTION("QEMU fw_cfg sysfs support");
38 MODULE_LICENSE("GPL");
40 /* selector key values for "well-known" fw_cfg entries */
41 #define FW_CFG_SIGNATURE 0x00
42 #define FW_CFG_ID 0x01
43 #define FW_CFG_FILE_DIR 0x19
45 /* size in bytes of fw_cfg signature */
46 #define FW_CFG_SIG_SIZE 4
48 /* fw_cfg "file name" is up to 56 characters (including terminating nul) */
49 #define FW_CFG_MAX_FILE_PATH 56
51 /* fw_cfg file directory entry type */
56 char name
[FW_CFG_MAX_FILE_PATH
];
59 /* fw_cfg device i/o register addresses */
60 static bool fw_cfg_is_mmio
;
61 static phys_addr_t fw_cfg_p_base
;
62 static resource_size_t fw_cfg_p_size
;
63 static void __iomem
*fw_cfg_dev_base
;
64 static void __iomem
*fw_cfg_reg_ctrl
;
65 static void __iomem
*fw_cfg_reg_data
;
67 /* atomic access to fw_cfg device (potentially slow i/o, so using mutex) */
68 static DEFINE_MUTEX(fw_cfg_dev_lock
);
70 /* pick appropriate endianness for selector key */
71 static inline u16
fw_cfg_sel_endianness(u16 key
)
73 return fw_cfg_is_mmio
? cpu_to_be16(key
) : cpu_to_le16(key
);
76 /* read chunk of given fw_cfg blob (caller responsible for sanity-check) */
77 static inline void fw_cfg_read_blob(u16 key
,
78 void *buf
, loff_t pos
, size_t count
)
83 /* If we have ACPI, ensure mutual exclusion against any potential
84 * device access by the firmware, e.g. via AML methods:
86 status
= acpi_acquire_global_lock(ACPI_WAIT_FOREVER
, &glk
);
87 if (ACPI_FAILURE(status
) && status
!= AE_NOT_CONFIGURED
) {
88 /* Should never get here */
89 WARN(1, "fw_cfg_read_blob: Failed to lock ACPI!\n");
90 memset(buf
, 0, count
);
94 mutex_lock(&fw_cfg_dev_lock
);
95 iowrite16(fw_cfg_sel_endianness(key
), fw_cfg_reg_ctrl
);
97 ioread8(fw_cfg_reg_data
);
98 ioread8_rep(fw_cfg_reg_data
, buf
, count
);
99 mutex_unlock(&fw_cfg_dev_lock
);
101 acpi_release_global_lock(glk
);
104 /* clean up fw_cfg device i/o */
105 static void fw_cfg_io_cleanup(void)
107 if (fw_cfg_is_mmio
) {
108 iounmap(fw_cfg_dev_base
);
109 release_mem_region(fw_cfg_p_base
, fw_cfg_p_size
);
111 ioport_unmap(fw_cfg_dev_base
);
112 release_region(fw_cfg_p_base
, fw_cfg_p_size
);
116 /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
117 #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
118 # if (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
119 # define FW_CFG_CTRL_OFF 0x08
120 # define FW_CFG_DATA_OFF 0x00
121 # elif (defined(CONFIG_PPC_PMAC) || defined(CONFIG_SPARC32)) /* ppc/mac,sun4m */
122 # define FW_CFG_CTRL_OFF 0x00
123 # define FW_CFG_DATA_OFF 0x02
124 # elif (defined(CONFIG_X86) || defined(CONFIG_SPARC64)) /* x86, sun4u */
125 # define FW_CFG_CTRL_OFF 0x00
126 # define FW_CFG_DATA_OFF 0x01
128 # error "QEMU FW_CFG not available on this architecture!"
132 /* initialize fw_cfg device i/o from platform data */
133 static int fw_cfg_do_platform_probe(struct platform_device
*pdev
)
135 char sig
[FW_CFG_SIG_SIZE
];
136 struct resource
*range
, *ctrl
, *data
;
138 /* acquire i/o range details */
139 fw_cfg_is_mmio
= false;
140 range
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
142 fw_cfg_is_mmio
= true;
143 range
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
147 fw_cfg_p_base
= range
->start
;
148 fw_cfg_p_size
= resource_size(range
);
150 if (fw_cfg_is_mmio
) {
151 if (!request_mem_region(fw_cfg_p_base
,
152 fw_cfg_p_size
, "fw_cfg_mem"))
154 fw_cfg_dev_base
= ioremap(fw_cfg_p_base
, fw_cfg_p_size
);
155 if (!fw_cfg_dev_base
) {
156 release_mem_region(fw_cfg_p_base
, fw_cfg_p_size
);
160 if (!request_region(fw_cfg_p_base
,
161 fw_cfg_p_size
, "fw_cfg_io"))
163 fw_cfg_dev_base
= ioport_map(fw_cfg_p_base
, fw_cfg_p_size
);
164 if (!fw_cfg_dev_base
) {
165 release_region(fw_cfg_p_base
, fw_cfg_p_size
);
170 /* were custom register offsets provided (e.g. on the command line)? */
171 ctrl
= platform_get_resource_byname(pdev
, IORESOURCE_REG
, "ctrl");
172 data
= platform_get_resource_byname(pdev
, IORESOURCE_REG
, "data");
174 fw_cfg_reg_ctrl
= fw_cfg_dev_base
+ ctrl
->start
;
175 fw_cfg_reg_data
= fw_cfg_dev_base
+ data
->start
;
177 /* use architecture-specific offsets */
178 fw_cfg_reg_ctrl
= fw_cfg_dev_base
+ FW_CFG_CTRL_OFF
;
179 fw_cfg_reg_data
= fw_cfg_dev_base
+ FW_CFG_DATA_OFF
;
182 /* verify fw_cfg device signature */
183 fw_cfg_read_blob(FW_CFG_SIGNATURE
, sig
, 0, FW_CFG_SIG_SIZE
);
184 if (memcmp(sig
, "QEMU", FW_CFG_SIG_SIZE
) != 0) {
192 /* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. */
193 static u32 fw_cfg_rev
;
195 static ssize_t
fw_cfg_showrev(struct kobject
*k
, struct attribute
*a
, char *buf
)
197 return sprintf(buf
, "%u\n", fw_cfg_rev
);
200 static const struct {
201 struct attribute attr
;
202 ssize_t (*show
)(struct kobject
*k
, struct attribute
*a
, char *buf
);
203 } fw_cfg_rev_attr
= {
204 .attr
= { .name
= "rev", .mode
= S_IRUSR
},
205 .show
= fw_cfg_showrev
,
208 /* fw_cfg_sysfs_entry type */
209 struct fw_cfg_sysfs_entry
{
211 struct fw_cfg_file f
;
212 struct list_head list
;
215 /* get fw_cfg_sysfs_entry from kobject member */
216 static inline struct fw_cfg_sysfs_entry
*to_entry(struct kobject
*kobj
)
218 return container_of(kobj
, struct fw_cfg_sysfs_entry
, kobj
);
221 /* fw_cfg_sysfs_attribute type */
222 struct fw_cfg_sysfs_attribute
{
223 struct attribute attr
;
224 ssize_t (*show
)(struct fw_cfg_sysfs_entry
*entry
, char *buf
);
227 /* get fw_cfg_sysfs_attribute from attribute member */
228 static inline struct fw_cfg_sysfs_attribute
*to_attr(struct attribute
*attr
)
230 return container_of(attr
, struct fw_cfg_sysfs_attribute
, attr
);
233 /* global cache of fw_cfg_sysfs_entry objects */
234 static LIST_HEAD(fw_cfg_entry_cache
);
236 /* kobjects removed lazily by kernel, mutual exclusion needed */
237 static DEFINE_SPINLOCK(fw_cfg_cache_lock
);
239 static inline void fw_cfg_sysfs_cache_enlist(struct fw_cfg_sysfs_entry
*entry
)
241 spin_lock(&fw_cfg_cache_lock
);
242 list_add_tail(&entry
->list
, &fw_cfg_entry_cache
);
243 spin_unlock(&fw_cfg_cache_lock
);
246 static inline void fw_cfg_sysfs_cache_delist(struct fw_cfg_sysfs_entry
*entry
)
248 spin_lock(&fw_cfg_cache_lock
);
249 list_del(&entry
->list
);
250 spin_unlock(&fw_cfg_cache_lock
);
253 static void fw_cfg_sysfs_cache_cleanup(void)
255 struct fw_cfg_sysfs_entry
*entry
, *next
;
257 list_for_each_entry_safe(entry
, next
, &fw_cfg_entry_cache
, list
) {
258 /* will end up invoking fw_cfg_sysfs_cache_delist()
259 * via each object's release() method (i.e. destructor)
261 kobject_put(&entry
->kobj
);
265 /* default_attrs: per-entry attributes and show methods */
267 #define FW_CFG_SYSFS_ATTR(_attr) \
268 struct fw_cfg_sysfs_attribute fw_cfg_sysfs_attr_##_attr = { \
269 .attr = { .name = __stringify(_attr), .mode = S_IRUSR }, \
270 .show = fw_cfg_sysfs_show_##_attr, \
273 static ssize_t
fw_cfg_sysfs_show_size(struct fw_cfg_sysfs_entry
*e
, char *buf
)
275 return sprintf(buf
, "%u\n", e
->f
.size
);
278 static ssize_t
fw_cfg_sysfs_show_key(struct fw_cfg_sysfs_entry
*e
, char *buf
)
280 return sprintf(buf
, "%u\n", e
->f
.select
);
283 static ssize_t
fw_cfg_sysfs_show_name(struct fw_cfg_sysfs_entry
*e
, char *buf
)
285 return sprintf(buf
, "%s\n", e
->f
.name
);
288 static FW_CFG_SYSFS_ATTR(size
);
289 static FW_CFG_SYSFS_ATTR(key
);
290 static FW_CFG_SYSFS_ATTR(name
);
292 static struct attribute
*fw_cfg_sysfs_entry_attrs
[] = {
293 &fw_cfg_sysfs_attr_size
.attr
,
294 &fw_cfg_sysfs_attr_key
.attr
,
295 &fw_cfg_sysfs_attr_name
.attr
,
299 /* sysfs_ops: find fw_cfg_[entry, attribute] and call appropriate show method */
300 static ssize_t
fw_cfg_sysfs_attr_show(struct kobject
*kobj
, struct attribute
*a
,
303 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
304 struct fw_cfg_sysfs_attribute
*attr
= to_attr(a
);
306 return attr
->show(entry
, buf
);
309 static const struct sysfs_ops fw_cfg_sysfs_attr_ops
= {
310 .show
= fw_cfg_sysfs_attr_show
,
313 /* release: destructor, to be called via kobject_put() */
314 static void fw_cfg_sysfs_release_entry(struct kobject
*kobj
)
316 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
318 fw_cfg_sysfs_cache_delist(entry
);
322 /* kobj_type: ties together all properties required to register an entry */
323 static struct kobj_type fw_cfg_sysfs_entry_ktype
= {
324 .default_attrs
= fw_cfg_sysfs_entry_attrs
,
325 .sysfs_ops
= &fw_cfg_sysfs_attr_ops
,
326 .release
= fw_cfg_sysfs_release_entry
,
329 /* raw-read method and attribute */
330 static ssize_t
fw_cfg_sysfs_read_raw(struct file
*filp
, struct kobject
*kobj
,
331 struct bin_attribute
*bin_attr
,
332 char *buf
, loff_t pos
, size_t count
)
334 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
336 if (pos
> entry
->f
.size
)
339 if (count
> entry
->f
.size
- pos
)
340 count
= entry
->f
.size
- pos
;
342 fw_cfg_read_blob(entry
->f
.select
, buf
, pos
, count
);
346 static struct bin_attribute fw_cfg_sysfs_attr_raw
= {
347 .attr
= { .name
= "raw", .mode
= S_IRUSR
},
348 .read
= fw_cfg_sysfs_read_raw
,
352 * Create a kset subdirectory matching each '/' delimited dirname token
353 * in 'name', starting with sysfs kset/folder 'dir'; At the end, create
354 * a symlink directed at the given 'target'.
355 * NOTE: We do this on a best-effort basis, since 'name' is not guaranteed
356 * to be a well-behaved path name. Whenever a symlink vs. kset directory
357 * name collision occurs, the kernel will issue big scary warnings while
358 * refusing to add the offending link or directory. We follow up with our
359 * own, slightly less scary error messages explaining the situation :)
361 static int fw_cfg_build_symlink(struct kset
*dir
,
362 struct kobject
*target
, const char *name
)
367 char *name_copy
, *p
, *tok
;
369 if (!dir
|| !target
|| !name
|| !*name
)
372 /* clone a copy of name for parsing */
373 name_copy
= p
= kstrdup(name
, GFP_KERNEL
);
377 /* create folders for each dirname token, then symlink for basename */
378 while ((tok
= strsep(&p
, "/")) && *tok
) {
380 /* last (basename) token? If so, add symlink here */
382 ret
= sysfs_create_link(&dir
->kobj
, target
, tok
);
386 /* does the current dir contain an item named after tok ? */
387 ko
= kset_find_obj(dir
, tok
);
389 /* drop reference added by kset_find_obj */
392 /* ko MUST be a kset - we're about to use it as one ! */
393 if (ko
->ktype
!= dir
->kobj
.ktype
) {
398 /* descend into already existing subdirectory */
401 /* create new subdirectory kset */
402 subdir
= kzalloc(sizeof(struct kset
), GFP_KERNEL
);
407 subdir
->kobj
.kset
= dir
;
408 subdir
->kobj
.ktype
= dir
->kobj
.ktype
;
409 ret
= kobject_set_name(&subdir
->kobj
, "%s", tok
);
414 ret
= kset_register(subdir
);
420 /* descend into newly created subdirectory */
425 /* we're done with cloned copy of name */
430 /* recursively unregister fw_cfg/by_name/ kset directory tree */
431 static void fw_cfg_kset_unregister_recursive(struct kset
*kset
)
433 struct kobject
*k
, *next
;
435 list_for_each_entry_safe(k
, next
, &kset
->list
, entry
)
436 /* all set members are ksets too, but check just in case... */
437 if (k
->ktype
== kset
->kobj
.ktype
)
438 fw_cfg_kset_unregister_recursive(to_kset(k
));
440 /* symlinks are cleanly and automatically removed with the directory */
441 kset_unregister(kset
);
444 /* kobjects & kset representing top-level, by_key, and by_name folders */
445 static struct kobject
*fw_cfg_top_ko
;
446 static struct kobject
*fw_cfg_sel_ko
;
447 static struct kset
*fw_cfg_fname_kset
;
449 /* register an individual fw_cfg file */
450 static int fw_cfg_register_file(const struct fw_cfg_file
*f
)
453 struct fw_cfg_sysfs_entry
*entry
;
455 /* allocate new entry */
456 entry
= kzalloc(sizeof(*entry
), GFP_KERNEL
);
460 /* set file entry information */
461 memcpy(&entry
->f
, f
, sizeof(struct fw_cfg_file
));
463 /* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
464 err
= kobject_init_and_add(&entry
->kobj
, &fw_cfg_sysfs_entry_ktype
,
465 fw_cfg_sel_ko
, "%d", entry
->f
.select
);
469 /* add raw binary content access */
470 err
= sysfs_create_bin_file(&entry
->kobj
, &fw_cfg_sysfs_attr_raw
);
474 /* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */
475 fw_cfg_build_symlink(fw_cfg_fname_kset
, &entry
->kobj
, entry
->f
.name
);
477 /* success, add entry to global cache */
478 fw_cfg_sysfs_cache_enlist(entry
);
482 kobject_del(&entry
->kobj
);
488 /* iterate over all fw_cfg directory entries, registering each one */
489 static int fw_cfg_register_dir_entries(void)
493 struct fw_cfg_file
*dir
;
496 fw_cfg_read_blob(FW_CFG_FILE_DIR
, &count
, 0, sizeof(count
));
497 count
= be32_to_cpu(count
);
498 dir_size
= count
* sizeof(struct fw_cfg_file
);
500 dir
= kmalloc(dir_size
, GFP_KERNEL
);
504 fw_cfg_read_blob(FW_CFG_FILE_DIR
, dir
, sizeof(count
), dir_size
);
506 for (i
= 0; i
< count
; i
++) {
507 dir
[i
].size
= be32_to_cpu(dir
[i
].size
);
508 dir
[i
].select
= be16_to_cpu(dir
[i
].select
);
509 ret
= fw_cfg_register_file(&dir
[i
]);
518 /* unregister top-level or by_key folder */
519 static inline void fw_cfg_kobj_cleanup(struct kobject
*kobj
)
525 static int fw_cfg_sysfs_probe(struct platform_device
*pdev
)
529 /* NOTE: If we supported multiple fw_cfg devices, we'd first create
530 * a subdirectory named after e.g. pdev->id, then hang per-device
531 * by_key (and by_name) subdirectories underneath it. However, only
532 * one fw_cfg device exist system-wide, so if one was already found
533 * earlier, we might as well stop here.
538 /* create by_key and by_name subdirs of /sys/firmware/qemu_fw_cfg/ */
540 fw_cfg_sel_ko
= kobject_create_and_add("by_key", fw_cfg_top_ko
);
543 fw_cfg_fname_kset
= kset_create_and_add("by_name", NULL
, fw_cfg_top_ko
);
544 if (!fw_cfg_fname_kset
)
547 /* initialize fw_cfg device i/o from platform data */
548 err
= fw_cfg_do_platform_probe(pdev
);
552 /* get revision number, add matching top-level attribute */
553 fw_cfg_read_blob(FW_CFG_ID
, &fw_cfg_rev
, 0, sizeof(fw_cfg_rev
));
554 fw_cfg_rev
= le32_to_cpu(fw_cfg_rev
);
555 err
= sysfs_create_file(fw_cfg_top_ko
, &fw_cfg_rev_attr
.attr
);
559 /* process fw_cfg file directory entry, registering each file */
560 err
= fw_cfg_register_dir_entries();
565 pr_debug("fw_cfg: loaded.\n");
569 fw_cfg_sysfs_cache_cleanup();
570 sysfs_remove_file(fw_cfg_top_ko
, &fw_cfg_rev_attr
.attr
);
574 fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset
);
576 fw_cfg_kobj_cleanup(fw_cfg_sel_ko
);
581 static int fw_cfg_sysfs_remove(struct platform_device
*pdev
)
583 pr_debug("fw_cfg: unloading.\n");
584 fw_cfg_sysfs_cache_cleanup();
585 fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset
);
586 fw_cfg_kobj_cleanup(fw_cfg_sel_ko
);
591 static const struct of_device_id fw_cfg_sysfs_mmio_match
[] = {
592 { .compatible
= "qemu,fw-cfg-mmio", },
595 MODULE_DEVICE_TABLE(of
, fw_cfg_sysfs_mmio_match
);
598 static const struct acpi_device_id fw_cfg_sysfs_acpi_match
[] = {
602 MODULE_DEVICE_TABLE(acpi
, fw_cfg_sysfs_acpi_match
);
605 static struct platform_driver fw_cfg_sysfs_driver
= {
606 .probe
= fw_cfg_sysfs_probe
,
607 .remove
= fw_cfg_sysfs_remove
,
610 .of_match_table
= fw_cfg_sysfs_mmio_match
,
611 .acpi_match_table
= ACPI_PTR(fw_cfg_sysfs_acpi_match
),
615 #ifdef CONFIG_FW_CFG_SYSFS_CMDLINE
617 static struct platform_device
*fw_cfg_cmdline_dev
;
619 /* this probably belongs in e.g. include/linux/types.h,
620 * but right now we are the only ones doing it...
622 #ifdef CONFIG_PHYS_ADDR_T_64BIT
623 #define __PHYS_ADDR_PREFIX "ll"
625 #define __PHYS_ADDR_PREFIX ""
628 /* use special scanf/printf modifier for phys_addr_t, resource_size_t */
629 #define PH_ADDR_SCAN_FMT "@%" __PHYS_ADDR_PREFIX "i%n" \
630 ":%" __PHYS_ADDR_PREFIX "i" \
631 ":%" __PHYS_ADDR_PREFIX "i%n"
633 #define PH_ADDR_PR_1_FMT "0x%" __PHYS_ADDR_PREFIX "x@" \
634 "0x%" __PHYS_ADDR_PREFIX "x"
636 #define PH_ADDR_PR_3_FMT PH_ADDR_PR_1_FMT \
637 ":%" __PHYS_ADDR_PREFIX "u" \
638 ":%" __PHYS_ADDR_PREFIX "u"
640 static int fw_cfg_cmdline_set(const char *arg
, const struct kernel_param
*kp
)
642 struct resource res
[3] = {};
645 resource_size_t size
, ctrl_off
, data_off
;
646 int processed
, consumed
= 0;
648 /* only one fw_cfg device can exist system-wide, so if one
649 * was processed on the command line already, we might as
652 if (fw_cfg_cmdline_dev
) {
653 /* avoid leaking previously registered device */
654 platform_device_unregister(fw_cfg_cmdline_dev
);
658 /* consume "<size>" portion of command line argument */
659 size
= memparse(arg
, &str
);
661 /* get "@<base>[:<ctrl_off>:<data_off>]" chunks */
662 processed
= sscanf(str
, PH_ADDR_SCAN_FMT
,
664 &ctrl_off
, &data_off
, &consumed
);
666 /* sscanf() must process precisely 1 or 3 chunks:
667 * <base> is mandatory, optionally followed by <ctrl_off>
669 * there must be no extra characters after the last chunk,
670 * so str[consumed] must be '\0'.
673 (processed
!= 1 && processed
!= 3))
677 res
[0].end
= base
+ size
- 1;
678 res
[0].flags
= !strcmp(kp
->name
, "mmio") ? IORESOURCE_MEM
:
681 /* insert register offsets, if provided */
683 res
[1].name
= "ctrl";
684 res
[1].start
= ctrl_off
;
685 res
[1].flags
= IORESOURCE_REG
;
686 res
[2].name
= "data";
687 res
[2].start
= data_off
;
688 res
[2].flags
= IORESOURCE_REG
;
691 /* "processed" happens to nicely match the number of resources
692 * we need to pass in to this platform device.
694 fw_cfg_cmdline_dev
= platform_device_register_simple("fw_cfg",
695 PLATFORM_DEVID_NONE
, res
, processed
);
696 if (IS_ERR(fw_cfg_cmdline_dev
))
697 return PTR_ERR(fw_cfg_cmdline_dev
);
702 static int fw_cfg_cmdline_get(char *buf
, const struct kernel_param
*kp
)
704 /* stay silent if device was not configured via the command
705 * line, or if the parameter name (ioport/mmio) doesn't match
708 if (!fw_cfg_cmdline_dev
||
709 (!strcmp(kp
->name
, "mmio") ^
710 (fw_cfg_cmdline_dev
->resource
[0].flags
== IORESOURCE_MEM
)))
713 switch (fw_cfg_cmdline_dev
->num_resources
) {
715 return snprintf(buf
, PAGE_SIZE
, PH_ADDR_PR_1_FMT
,
716 resource_size(&fw_cfg_cmdline_dev
->resource
[0]),
717 fw_cfg_cmdline_dev
->resource
[0].start
);
719 return snprintf(buf
, PAGE_SIZE
, PH_ADDR_PR_3_FMT
,
720 resource_size(&fw_cfg_cmdline_dev
->resource
[0]),
721 fw_cfg_cmdline_dev
->resource
[0].start
,
722 fw_cfg_cmdline_dev
->resource
[1].start
,
723 fw_cfg_cmdline_dev
->resource
[2].start
);
726 /* Should never get here */
727 WARN(1, "Unexpected number of resources: %d\n",
728 fw_cfg_cmdline_dev
->num_resources
);
732 static const struct kernel_param_ops fw_cfg_cmdline_param_ops
= {
733 .set
= fw_cfg_cmdline_set
,
734 .get
= fw_cfg_cmdline_get
,
737 device_param_cb(ioport
, &fw_cfg_cmdline_param_ops
, NULL
, S_IRUSR
);
738 device_param_cb(mmio
, &fw_cfg_cmdline_param_ops
, NULL
, S_IRUSR
);
740 #endif /* CONFIG_FW_CFG_SYSFS_CMDLINE */
742 static int __init
fw_cfg_sysfs_init(void)
746 /* create /sys/firmware/qemu_fw_cfg/ top level directory */
747 fw_cfg_top_ko
= kobject_create_and_add("qemu_fw_cfg", firmware_kobj
);
751 ret
= platform_driver_register(&fw_cfg_sysfs_driver
);
753 fw_cfg_kobj_cleanup(fw_cfg_top_ko
);
758 static void __exit
fw_cfg_sysfs_exit(void)
760 platform_driver_unregister(&fw_cfg_sysfs_driver
);
762 #ifdef CONFIG_FW_CFG_SYSFS_CMDLINE
763 platform_device_unregister(fw_cfg_cmdline_dev
);
766 /* clean up /sys/firmware/qemu_fw_cfg/ */
767 fw_cfg_kobj_cleanup(fw_cfg_top_ko
);
770 module_init(fw_cfg_sysfs_init
);
771 module_exit(fw_cfg_sysfs_exit
);