2 * libqos fw_cfg support
4 * Copyright IBM, Corp. 2012-2013
5 * Copyright (C) 2013 Red Hat Inc.
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Markus Armbruster <armbru@redhat.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
15 #include "qemu/osdep.h"
17 #include "libqos/fw_cfg.h"
19 #include "qemu/bswap.h"
21 void qfw_cfg_select(QFWCFG
*fw_cfg
, uint16_t key
)
23 fw_cfg
->select(fw_cfg
, key
);
26 void qfw_cfg_read_data(QFWCFG
*fw_cfg
, void *data
, size_t len
)
28 fw_cfg
->read(fw_cfg
, data
, len
);
31 void qfw_cfg_get(QFWCFG
*fw_cfg
, uint16_t key
, void *data
, size_t len
)
33 qfw_cfg_select(fw_cfg
, key
);
34 qfw_cfg_read_data(fw_cfg
, data
, len
);
37 uint16_t qfw_cfg_get_u16(QFWCFG
*fw_cfg
, uint16_t key
)
40 qfw_cfg_get(fw_cfg
, key
, &value
, sizeof(value
));
41 return le16_to_cpu(value
);
44 uint32_t qfw_cfg_get_u32(QFWCFG
*fw_cfg
, uint16_t key
)
47 qfw_cfg_get(fw_cfg
, key
, &value
, sizeof(value
));
48 return le32_to_cpu(value
);
51 uint64_t qfw_cfg_get_u64(QFWCFG
*fw_cfg
, uint16_t key
)
54 qfw_cfg_get(fw_cfg
, key
, &value
, sizeof(value
));
55 return le64_to_cpu(value
);
58 static void mm_fw_cfg_select(QFWCFG
*fw_cfg
, uint16_t key
)
60 writew(fw_cfg
->base
, key
);
63 static void mm_fw_cfg_read(QFWCFG
*fw_cfg
, void *data
, size_t len
)
68 for (i
= 0; i
< len
; i
++) {
69 ptr
[i
] = readb(fw_cfg
->base
+ 2);
73 QFWCFG
*mm_fw_cfg_init(uint64_t base
)
75 QFWCFG
*fw_cfg
= g_malloc0(sizeof(*fw_cfg
));
78 fw_cfg
->select
= mm_fw_cfg_select
;
79 fw_cfg
->read
= mm_fw_cfg_read
;
84 static void io_fw_cfg_select(QFWCFG
*fw_cfg
, uint16_t key
)
86 outw(fw_cfg
->base
, key
);
89 static void io_fw_cfg_read(QFWCFG
*fw_cfg
, void *data
, size_t len
)
94 for (i
= 0; i
< len
; i
++) {
95 ptr
[i
] = inb(fw_cfg
->base
+ 1);
99 QFWCFG
*io_fw_cfg_init(uint16_t base
)
101 QFWCFG
*fw_cfg
= g_malloc0(sizeof(*fw_cfg
));
104 fw_cfg
->select
= io_fw_cfg_select
;
105 fw_cfg
->read
= io_fw_cfg_read
;