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
)
80 mutex_lock(&fw_cfg_dev_lock
);
81 iowrite16(fw_cfg_sel_endianness(key
), fw_cfg_reg_ctrl
);
83 ioread8(fw_cfg_reg_data
);
84 ioread8_rep(fw_cfg_reg_data
, buf
, count
);
85 mutex_unlock(&fw_cfg_dev_lock
);
88 /* clean up fw_cfg device i/o */
89 static void fw_cfg_io_cleanup(void)
92 iounmap(fw_cfg_dev_base
);
93 release_mem_region(fw_cfg_p_base
, fw_cfg_p_size
);
95 ioport_unmap(fw_cfg_dev_base
);
96 release_region(fw_cfg_p_base
, fw_cfg_p_size
);
100 /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
101 #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
102 # if (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
103 # define FW_CFG_CTRL_OFF 0x08
104 # define FW_CFG_DATA_OFF 0x00
105 # elif (defined(CONFIG_PPC_PMAC) || defined(CONFIG_SPARC32)) /* ppc/mac,sun4m */
106 # define FW_CFG_CTRL_OFF 0x00
107 # define FW_CFG_DATA_OFF 0x02
108 # elif (defined(CONFIG_X86) || defined(CONFIG_SPARC64)) /* x86, sun4u */
109 # define FW_CFG_CTRL_OFF 0x00
110 # define FW_CFG_DATA_OFF 0x01
112 # warning "QEMU FW_CFG may not be available on this architecture!"
113 # define FW_CFG_CTRL_OFF 0x00
114 # define FW_CFG_DATA_OFF 0x01
118 /* initialize fw_cfg device i/o from platform data */
119 static int fw_cfg_do_platform_probe(struct platform_device
*pdev
)
121 char sig
[FW_CFG_SIG_SIZE
];
122 struct resource
*range
, *ctrl
, *data
;
124 /* acquire i/o range details */
125 fw_cfg_is_mmio
= false;
126 range
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
128 fw_cfg_is_mmio
= true;
129 range
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
133 fw_cfg_p_base
= range
->start
;
134 fw_cfg_p_size
= resource_size(range
);
136 if (fw_cfg_is_mmio
) {
137 if (!request_mem_region(fw_cfg_p_base
,
138 fw_cfg_p_size
, "fw_cfg_mem"))
140 fw_cfg_dev_base
= ioremap(fw_cfg_p_base
, fw_cfg_p_size
);
141 if (!fw_cfg_dev_base
) {
142 release_mem_region(fw_cfg_p_base
, fw_cfg_p_size
);
146 if (!request_region(fw_cfg_p_base
,
147 fw_cfg_p_size
, "fw_cfg_io"))
149 fw_cfg_dev_base
= ioport_map(fw_cfg_p_base
, fw_cfg_p_size
);
150 if (!fw_cfg_dev_base
) {
151 release_region(fw_cfg_p_base
, fw_cfg_p_size
);
156 /* were custom register offsets provided (e.g. on the command line)? */
157 ctrl
= platform_get_resource_byname(pdev
, IORESOURCE_REG
, "ctrl");
158 data
= platform_get_resource_byname(pdev
, IORESOURCE_REG
, "data");
160 fw_cfg_reg_ctrl
= fw_cfg_dev_base
+ ctrl
->start
;
161 fw_cfg_reg_data
= fw_cfg_dev_base
+ data
->start
;
163 /* use architecture-specific offsets */
164 fw_cfg_reg_ctrl
= fw_cfg_dev_base
+ FW_CFG_CTRL_OFF
;
165 fw_cfg_reg_data
= fw_cfg_dev_base
+ FW_CFG_DATA_OFF
;
168 /* verify fw_cfg device signature */
169 fw_cfg_read_blob(FW_CFG_SIGNATURE
, sig
, 0, FW_CFG_SIG_SIZE
);
170 if (memcmp(sig
, "QEMU", FW_CFG_SIG_SIZE
) != 0) {
178 /* fw_cfg revision attribute, in /sys/firmware/qemu_fw_cfg top-level dir. */
179 static u32 fw_cfg_rev
;
181 static ssize_t
fw_cfg_showrev(struct kobject
*k
, struct attribute
*a
, char *buf
)
183 return sprintf(buf
, "%u\n", fw_cfg_rev
);
186 static const struct {
187 struct attribute attr
;
188 ssize_t (*show
)(struct kobject
*k
, struct attribute
*a
, char *buf
);
189 } fw_cfg_rev_attr
= {
190 .attr
= { .name
= "rev", .mode
= S_IRUSR
},
191 .show
= fw_cfg_showrev
,
194 /* fw_cfg_sysfs_entry type */
195 struct fw_cfg_sysfs_entry
{
197 struct fw_cfg_file f
;
198 struct list_head list
;
201 /* get fw_cfg_sysfs_entry from kobject member */
202 static inline struct fw_cfg_sysfs_entry
*to_entry(struct kobject
*kobj
)
204 return container_of(kobj
, struct fw_cfg_sysfs_entry
, kobj
);
207 /* fw_cfg_sysfs_attribute type */
208 struct fw_cfg_sysfs_attribute
{
209 struct attribute attr
;
210 ssize_t (*show
)(struct fw_cfg_sysfs_entry
*entry
, char *buf
);
213 /* get fw_cfg_sysfs_attribute from attribute member */
214 static inline struct fw_cfg_sysfs_attribute
*to_attr(struct attribute
*attr
)
216 return container_of(attr
, struct fw_cfg_sysfs_attribute
, attr
);
219 /* global cache of fw_cfg_sysfs_entry objects */
220 static LIST_HEAD(fw_cfg_entry_cache
);
222 /* kobjects removed lazily by kernel, mutual exclusion needed */
223 static DEFINE_SPINLOCK(fw_cfg_cache_lock
);
225 static inline void fw_cfg_sysfs_cache_enlist(struct fw_cfg_sysfs_entry
*entry
)
227 spin_lock(&fw_cfg_cache_lock
);
228 list_add_tail(&entry
->list
, &fw_cfg_entry_cache
);
229 spin_unlock(&fw_cfg_cache_lock
);
232 static inline void fw_cfg_sysfs_cache_delist(struct fw_cfg_sysfs_entry
*entry
)
234 spin_lock(&fw_cfg_cache_lock
);
235 list_del(&entry
->list
);
236 spin_unlock(&fw_cfg_cache_lock
);
239 static void fw_cfg_sysfs_cache_cleanup(void)
241 struct fw_cfg_sysfs_entry
*entry
, *next
;
243 list_for_each_entry_safe(entry
, next
, &fw_cfg_entry_cache
, list
) {
244 /* will end up invoking fw_cfg_sysfs_cache_delist()
245 * via each object's release() method (i.e. destructor)
247 kobject_put(&entry
->kobj
);
251 /* default_attrs: per-entry attributes and show methods */
253 #define FW_CFG_SYSFS_ATTR(_attr) \
254 struct fw_cfg_sysfs_attribute fw_cfg_sysfs_attr_##_attr = { \
255 .attr = { .name = __stringify(_attr), .mode = S_IRUSR }, \
256 .show = fw_cfg_sysfs_show_##_attr, \
259 static ssize_t
fw_cfg_sysfs_show_size(struct fw_cfg_sysfs_entry
*e
, char *buf
)
261 return sprintf(buf
, "%u\n", e
->f
.size
);
264 static ssize_t
fw_cfg_sysfs_show_key(struct fw_cfg_sysfs_entry
*e
, char *buf
)
266 return sprintf(buf
, "%u\n", e
->f
.select
);
269 static ssize_t
fw_cfg_sysfs_show_name(struct fw_cfg_sysfs_entry
*e
, char *buf
)
271 return sprintf(buf
, "%s\n", e
->f
.name
);
274 static FW_CFG_SYSFS_ATTR(size
);
275 static FW_CFG_SYSFS_ATTR(key
);
276 static FW_CFG_SYSFS_ATTR(name
);
278 static struct attribute
*fw_cfg_sysfs_entry_attrs
[] = {
279 &fw_cfg_sysfs_attr_size
.attr
,
280 &fw_cfg_sysfs_attr_key
.attr
,
281 &fw_cfg_sysfs_attr_name
.attr
,
285 /* sysfs_ops: find fw_cfg_[entry, attribute] and call appropriate show method */
286 static ssize_t
fw_cfg_sysfs_attr_show(struct kobject
*kobj
, struct attribute
*a
,
289 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
290 struct fw_cfg_sysfs_attribute
*attr
= to_attr(a
);
292 return attr
->show(entry
, buf
);
295 static const struct sysfs_ops fw_cfg_sysfs_attr_ops
= {
296 .show
= fw_cfg_sysfs_attr_show
,
299 /* release: destructor, to be called via kobject_put() */
300 static void fw_cfg_sysfs_release_entry(struct kobject
*kobj
)
302 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
304 fw_cfg_sysfs_cache_delist(entry
);
308 /* kobj_type: ties together all properties required to register an entry */
309 static struct kobj_type fw_cfg_sysfs_entry_ktype
= {
310 .default_attrs
= fw_cfg_sysfs_entry_attrs
,
311 .sysfs_ops
= &fw_cfg_sysfs_attr_ops
,
312 .release
= fw_cfg_sysfs_release_entry
,
315 /* raw-read method and attribute */
316 static ssize_t
fw_cfg_sysfs_read_raw(struct file
*filp
, struct kobject
*kobj
,
317 struct bin_attribute
*bin_attr
,
318 char *buf
, loff_t pos
, size_t count
)
320 struct fw_cfg_sysfs_entry
*entry
= to_entry(kobj
);
322 if (pos
> entry
->f
.size
)
325 if (count
> entry
->f
.size
- pos
)
326 count
= entry
->f
.size
- pos
;
328 fw_cfg_read_blob(entry
->f
.select
, buf
, pos
, count
);
332 static struct bin_attribute fw_cfg_sysfs_attr_raw
= {
333 .attr
= { .name
= "raw", .mode
= S_IRUSR
},
334 .read
= fw_cfg_sysfs_read_raw
,
338 * Create a kset subdirectory matching each '/' delimited dirname token
339 * in 'name', starting with sysfs kset/folder 'dir'; At the end, create
340 * a symlink directed at the given 'target'.
341 * NOTE: We do this on a best-effort basis, since 'name' is not guaranteed
342 * to be a well-behaved path name. Whenever a symlink vs. kset directory
343 * name collision occurs, the kernel will issue big scary warnings while
344 * refusing to add the offending link or directory. We follow up with our
345 * own, slightly less scary error messages explaining the situation :)
347 static int fw_cfg_build_symlink(struct kset
*dir
,
348 struct kobject
*target
, const char *name
)
353 char *name_copy
, *p
, *tok
;
355 if (!dir
|| !target
|| !name
|| !*name
)
358 /* clone a copy of name for parsing */
359 name_copy
= p
= kstrdup(name
, GFP_KERNEL
);
363 /* create folders for each dirname token, then symlink for basename */
364 while ((tok
= strsep(&p
, "/")) && *tok
) {
366 /* last (basename) token? If so, add symlink here */
368 ret
= sysfs_create_link(&dir
->kobj
, target
, tok
);
372 /* does the current dir contain an item named after tok ? */
373 ko
= kset_find_obj(dir
, tok
);
375 /* drop reference added by kset_find_obj */
378 /* ko MUST be a kset - we're about to use it as one ! */
379 if (ko
->ktype
!= dir
->kobj
.ktype
) {
384 /* descend into already existing subdirectory */
387 /* create new subdirectory kset */
388 subdir
= kzalloc(sizeof(struct kset
), GFP_KERNEL
);
393 subdir
->kobj
.kset
= dir
;
394 subdir
->kobj
.ktype
= dir
->kobj
.ktype
;
395 ret
= kobject_set_name(&subdir
->kobj
, "%s", tok
);
400 ret
= kset_register(subdir
);
406 /* descend into newly created subdirectory */
411 /* we're done with cloned copy of name */
416 /* recursively unregister fw_cfg/by_name/ kset directory tree */
417 static void fw_cfg_kset_unregister_recursive(struct kset
*kset
)
419 struct kobject
*k
, *next
;
421 list_for_each_entry_safe(k
, next
, &kset
->list
, entry
)
422 /* all set members are ksets too, but check just in case... */
423 if (k
->ktype
== kset
->kobj
.ktype
)
424 fw_cfg_kset_unregister_recursive(to_kset(k
));
426 /* symlinks are cleanly and automatically removed with the directory */
427 kset_unregister(kset
);
430 /* kobjects & kset representing top-level, by_key, and by_name folders */
431 static struct kobject
*fw_cfg_top_ko
;
432 static struct kobject
*fw_cfg_sel_ko
;
433 static struct kset
*fw_cfg_fname_kset
;
435 /* register an individual fw_cfg file */
436 static int fw_cfg_register_file(const struct fw_cfg_file
*f
)
439 struct fw_cfg_sysfs_entry
*entry
;
441 /* allocate new entry */
442 entry
= kzalloc(sizeof(*entry
), GFP_KERNEL
);
446 /* set file entry information */
447 memcpy(&entry
->f
, f
, sizeof(struct fw_cfg_file
));
449 /* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
450 err
= kobject_init_and_add(&entry
->kobj
, &fw_cfg_sysfs_entry_ktype
,
451 fw_cfg_sel_ko
, "%d", entry
->f
.select
);
455 /* add raw binary content access */
456 err
= sysfs_create_bin_file(&entry
->kobj
, &fw_cfg_sysfs_attr_raw
);
460 /* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */
461 fw_cfg_build_symlink(fw_cfg_fname_kset
, &entry
->kobj
, entry
->f
.name
);
463 /* success, add entry to global cache */
464 fw_cfg_sysfs_cache_enlist(entry
);
468 kobject_del(&entry
->kobj
);
474 /* iterate over all fw_cfg directory entries, registering each one */
475 static int fw_cfg_register_dir_entries(void)
479 struct fw_cfg_file
*dir
;
482 fw_cfg_read_blob(FW_CFG_FILE_DIR
, &count
, 0, sizeof(count
));
483 count
= be32_to_cpu(count
);
484 dir_size
= count
* sizeof(struct fw_cfg_file
);
486 dir
= kmalloc(dir_size
, GFP_KERNEL
);
490 fw_cfg_read_blob(FW_CFG_FILE_DIR
, dir
, sizeof(count
), dir_size
);
492 for (i
= 0; i
< count
; i
++) {
493 dir
[i
].size
= be32_to_cpu(dir
[i
].size
);
494 dir
[i
].select
= be16_to_cpu(dir
[i
].select
);
495 ret
= fw_cfg_register_file(&dir
[i
]);
504 /* unregister top-level or by_key folder */
505 static inline void fw_cfg_kobj_cleanup(struct kobject
*kobj
)
511 static int fw_cfg_sysfs_probe(struct platform_device
*pdev
)
515 /* NOTE: If we supported multiple fw_cfg devices, we'd first create
516 * a subdirectory named after e.g. pdev->id, then hang per-device
517 * by_key (and by_name) subdirectories underneath it. However, only
518 * one fw_cfg device exist system-wide, so if one was already found
519 * earlier, we might as well stop here.
524 /* create by_key and by_name subdirs of /sys/firmware/qemu_fw_cfg/ */
526 fw_cfg_sel_ko
= kobject_create_and_add("by_key", fw_cfg_top_ko
);
529 fw_cfg_fname_kset
= kset_create_and_add("by_name", NULL
, fw_cfg_top_ko
);
530 if (!fw_cfg_fname_kset
)
533 /* initialize fw_cfg device i/o from platform data */
534 err
= fw_cfg_do_platform_probe(pdev
);
538 /* get revision number, add matching top-level attribute */
539 fw_cfg_read_blob(FW_CFG_ID
, &fw_cfg_rev
, 0, sizeof(fw_cfg_rev
));
540 fw_cfg_rev
= le32_to_cpu(fw_cfg_rev
);
541 err
= sysfs_create_file(fw_cfg_top_ko
, &fw_cfg_rev_attr
.attr
);
545 /* process fw_cfg file directory entry, registering each file */
546 err
= fw_cfg_register_dir_entries();
551 pr_debug("fw_cfg: loaded.\n");
555 fw_cfg_sysfs_cache_cleanup();
556 sysfs_remove_file(fw_cfg_top_ko
, &fw_cfg_rev_attr
.attr
);
560 fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset
);
562 fw_cfg_kobj_cleanup(fw_cfg_sel_ko
);
567 static int fw_cfg_sysfs_remove(struct platform_device
*pdev
)
569 pr_debug("fw_cfg: unloading.\n");
570 fw_cfg_sysfs_cache_cleanup();
571 fw_cfg_kset_unregister_recursive(fw_cfg_fname_kset
);
572 fw_cfg_kobj_cleanup(fw_cfg_sel_ko
);
577 static const struct of_device_id fw_cfg_sysfs_mmio_match
[] = {
578 { .compatible
= "qemu,fw-cfg-mmio", },
581 MODULE_DEVICE_TABLE(of
, fw_cfg_sysfs_mmio_match
);
584 static const struct acpi_device_id fw_cfg_sysfs_acpi_match
[] = {
588 MODULE_DEVICE_TABLE(acpi
, fw_cfg_sysfs_acpi_match
);
591 static struct platform_driver fw_cfg_sysfs_driver
= {
592 .probe
= fw_cfg_sysfs_probe
,
593 .remove
= fw_cfg_sysfs_remove
,
596 .of_match_table
= fw_cfg_sysfs_mmio_match
,
597 .acpi_match_table
= ACPI_PTR(fw_cfg_sysfs_acpi_match
),
601 #ifdef CONFIG_FW_CFG_SYSFS_CMDLINE
603 static struct platform_device
*fw_cfg_cmdline_dev
;
605 /* this probably belongs in e.g. include/linux/types.h,
606 * but right now we are the only ones doing it...
608 #ifdef CONFIG_PHYS_ADDR_T_64BIT
609 #define __PHYS_ADDR_PREFIX "ll"
611 #define __PHYS_ADDR_PREFIX ""
614 /* use special scanf/printf modifier for phys_addr_t, resource_size_t */
615 #define PH_ADDR_SCAN_FMT "@%" __PHYS_ADDR_PREFIX "i%n" \
616 ":%" __PHYS_ADDR_PREFIX "i" \
617 ":%" __PHYS_ADDR_PREFIX "i%n"
619 #define PH_ADDR_PR_1_FMT "0x%" __PHYS_ADDR_PREFIX "x@" \
620 "0x%" __PHYS_ADDR_PREFIX "x"
622 #define PH_ADDR_PR_3_FMT PH_ADDR_PR_1_FMT \
623 ":%" __PHYS_ADDR_PREFIX "u" \
624 ":%" __PHYS_ADDR_PREFIX "u"
626 static int fw_cfg_cmdline_set(const char *arg
, const struct kernel_param
*kp
)
628 struct resource res
[3] = {};
631 resource_size_t size
, ctrl_off
, data_off
;
632 int processed
, consumed
= 0;
634 /* only one fw_cfg device can exist system-wide, so if one
635 * was processed on the command line already, we might as
638 if (fw_cfg_cmdline_dev
) {
639 /* avoid leaking previously registered device */
640 platform_device_unregister(fw_cfg_cmdline_dev
);
644 /* consume "<size>" portion of command line argument */
645 size
= memparse(arg
, &str
);
647 /* get "@<base>[:<ctrl_off>:<data_off>]" chunks */
648 processed
= sscanf(str
, PH_ADDR_SCAN_FMT
,
650 &ctrl_off
, &data_off
, &consumed
);
652 /* sscanf() must process precisely 1 or 3 chunks:
653 * <base> is mandatory, optionally followed by <ctrl_off>
655 * there must be no extra characters after the last chunk,
656 * so str[consumed] must be '\0'.
659 (processed
!= 1 && processed
!= 3))
663 res
[0].end
= base
+ size
- 1;
664 res
[0].flags
= !strcmp(kp
->name
, "mmio") ? IORESOURCE_MEM
:
667 /* insert register offsets, if provided */
669 res
[1].name
= "ctrl";
670 res
[1].start
= ctrl_off
;
671 res
[1].flags
= IORESOURCE_REG
;
672 res
[2].name
= "data";
673 res
[2].start
= data_off
;
674 res
[2].flags
= IORESOURCE_REG
;
677 /* "processed" happens to nicely match the number of resources
678 * we need to pass in to this platform device.
680 fw_cfg_cmdline_dev
= platform_device_register_simple("fw_cfg",
681 PLATFORM_DEVID_NONE
, res
, processed
);
682 if (IS_ERR(fw_cfg_cmdline_dev
))
683 return PTR_ERR(fw_cfg_cmdline_dev
);
688 static int fw_cfg_cmdline_get(char *buf
, const struct kernel_param
*kp
)
690 /* stay silent if device was not configured via the command
691 * line, or if the parameter name (ioport/mmio) doesn't match
694 if (!fw_cfg_cmdline_dev
||
695 (!strcmp(kp
->name
, "mmio") ^
696 (fw_cfg_cmdline_dev
->resource
[0].flags
== IORESOURCE_MEM
)))
699 switch (fw_cfg_cmdline_dev
->num_resources
) {
701 return snprintf(buf
, PAGE_SIZE
, PH_ADDR_PR_1_FMT
,
702 resource_size(&fw_cfg_cmdline_dev
->resource
[0]),
703 fw_cfg_cmdline_dev
->resource
[0].start
);
705 return snprintf(buf
, PAGE_SIZE
, PH_ADDR_PR_3_FMT
,
706 resource_size(&fw_cfg_cmdline_dev
->resource
[0]),
707 fw_cfg_cmdline_dev
->resource
[0].start
,
708 fw_cfg_cmdline_dev
->resource
[1].start
,
709 fw_cfg_cmdline_dev
->resource
[2].start
);
712 /* Should never get here */
713 WARN(1, "Unexpected number of resources: %d\n",
714 fw_cfg_cmdline_dev
->num_resources
);
718 static const struct kernel_param_ops fw_cfg_cmdline_param_ops
= {
719 .set
= fw_cfg_cmdline_set
,
720 .get
= fw_cfg_cmdline_get
,
723 device_param_cb(ioport
, &fw_cfg_cmdline_param_ops
, NULL
, S_IRUSR
);
724 device_param_cb(mmio
, &fw_cfg_cmdline_param_ops
, NULL
, S_IRUSR
);
726 #endif /* CONFIG_FW_CFG_SYSFS_CMDLINE */
728 static int __init
fw_cfg_sysfs_init(void)
730 /* create /sys/firmware/qemu_fw_cfg/ top level directory */
731 fw_cfg_top_ko
= kobject_create_and_add("qemu_fw_cfg", firmware_kobj
);
735 return platform_driver_register(&fw_cfg_sysfs_driver
);
738 static void __exit
fw_cfg_sysfs_exit(void)
740 platform_driver_unregister(&fw_cfg_sysfs_driver
);
742 #ifdef CONFIG_FW_CFG_SYSFS_CMDLINE
743 platform_device_unregister(fw_cfg_cmdline_dev
);
746 /* clean up /sys/firmware/qemu_fw_cfg/ */
747 fw_cfg_kobj_cleanup(fw_cfg_top_ko
);
750 module_init(fw_cfg_sysfs_init
);
751 module_exit(fw_cfg_sysfs_exit
);