monitor: inline ambiguous helper functions
[qemu/ar7.git] / tests / libqos / fw_cfg.c
blobd0889d1e22af43f371c3335449404e5fdcc8de8d
1 /*
2 * libqos fw_cfg support
4 * Copyright IBM, Corp. 2012-2013
5 * Copyright (C) 2013 Red Hat Inc.
7 * Authors:
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"
16 #include "libqos/fw_cfg.h"
17 #include "libqtest.h"
18 #include "qemu/bswap.h"
20 void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
22 fw_cfg->select(fw_cfg, key);
25 void qfw_cfg_read_data(QFWCFG *fw_cfg, void *data, size_t len)
27 fw_cfg->read(fw_cfg, data, len);
30 void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void *data, size_t len)
32 qfw_cfg_select(fw_cfg, key);
33 qfw_cfg_read_data(fw_cfg, data, len);
36 uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key)
38 uint16_t value;
39 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
40 return le16_to_cpu(value);
43 uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key)
45 uint32_t value;
46 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
47 return le32_to_cpu(value);
50 uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
52 uint64_t value;
53 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
54 return le64_to_cpu(value);
57 static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
59 qtest_writew(fw_cfg->qts, fw_cfg->base, key);
62 static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
64 uint8_t *ptr = data;
65 int i;
67 for (i = 0; i < len; i++) {
68 ptr[i] = qtest_readb(fw_cfg->qts, fw_cfg->base + 2);
72 QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base)
74 QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
76 fw_cfg->base = base;
77 fw_cfg->qts = qts;
78 fw_cfg->select = mm_fw_cfg_select;
79 fw_cfg->read = mm_fw_cfg_read;
81 return fw_cfg;
84 static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
86 qtest_outw(fw_cfg->qts, fw_cfg->base, key);
89 static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
91 uint8_t *ptr = data;
92 int i;
94 for (i = 0; i < len; i++) {
95 ptr[i] = qtest_inb(fw_cfg->qts, fw_cfg->base + 1);
99 QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base)
101 QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
103 fw_cfg->base = base;
104 fw_cfg->qts = qts;
105 fw_cfg->select = io_fw_cfg_select;
106 fw_cfg->read = io_fw_cfg_read;
108 return fw_cfg;