]> git.proxmox.com Git - mirror_qemu.git/blame - tests/libqos/fw_cfg.c
libqos: Track QTestState with QPCIBus
[mirror_qemu.git] / tests / libqos / fw_cfg.c
CommitLineData
234c69c5
AL
1/*
2 * libqos fw_cfg support
3 *
4 * Copyright IBM, Corp. 2012-2013
7a100165 5 * Copyright (C) 2013 Red Hat Inc.
234c69c5
AL
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
7a100165 9 * Markus Armbruster <armbru@redhat.com>
234c69c5
AL
10 *
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.
13 */
14
681c28a3 15#include "qemu/osdep.h"
234c69c5 16#include "libqos/fw_cfg.h"
7a100165 17#include "libqtest.h"
1a63e059 18#include "qemu/bswap.h"
234c69c5
AL
19
20void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
21{
22 fw_cfg->select(fw_cfg, key);
23}
24
25void qfw_cfg_read_data(QFWCFG *fw_cfg, void *data, size_t len)
26{
27 fw_cfg->read(fw_cfg, data, len);
28}
29
30void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void *data, size_t len)
31{
32 qfw_cfg_select(fw_cfg, key);
33 qfw_cfg_read_data(fw_cfg, data, len);
34}
35
36uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key)
37{
38 uint16_t value;
39 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
1a63e059 40 return le16_to_cpu(value);
234c69c5
AL
41}
42
43uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key)
44{
45 uint32_t value;
46 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
1a63e059 47 return le32_to_cpu(value);
234c69c5
AL
48}
49
50uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
51{
52 uint64_t value;
53 qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
1a63e059 54 return le64_to_cpu(value);
234c69c5
AL
55}
56
7a100165
MA
57static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
58{
59 writew(fw_cfg->base, key);
60}
61
62static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
63{
64 uint8_t *ptr = data;
65 int i;
66
67 for (i = 0; i < len; i++) {
68 ptr[i] = readb(fw_cfg->base + 2);
69 }
70}
71
72QFWCFG *mm_fw_cfg_init(uint64_t base)
73{
74 QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
75
76 fw_cfg->base = base;
77 fw_cfg->select = mm_fw_cfg_select;
78 fw_cfg->read = mm_fw_cfg_read;
79
80 return fw_cfg;
81}
26491a38
MA
82
83static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
84{
85 outw(fw_cfg->base, key);
86}
87
88static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
89{
90 uint8_t *ptr = data;
91 int i;
92
93 for (i = 0; i < len; i++) {
94 ptr[i] = inb(fw_cfg->base + 1);
95 }
96}
97
98QFWCFG *io_fw_cfg_init(uint16_t base)
99{
100 QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
101
102 fw_cfg->base = base;
103 fw_cfg->select = io_fw_cfg_select;
104 fw_cfg->read = io_fw_cfg_read;
105
106 return fw_cfg;
107}