failover: g_strcmp0() knows how to handle NULL
[qemu.git] / pc-bios / optionrom / optrom_fw_cfg.h
bloba3660a52006f39327ef212e1e40e952e221cb85c
1 /*
2 * Common Option ROM Functions for fw_cfg
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright (c) 2015-2019 Red Hat Inc.
18 * Authors:
19 * Marc MarĂ­ <marc.mari.barcelo@gmail.com>
20 * Richard W.M. Jones <rjones@redhat.com>
21 * Stefano Garzarella <sgarzare@redhat.com>
24 #ifndef OPTROM_FW_CFG_H
25 #define OPTROM_FW_CFG_H
27 #include "../../include/standard-headers/linux/qemu_fw_cfg.h"
29 #define BIOS_CFG_IOPORT_CFG 0x510
30 #define BIOS_CFG_IOPORT_DATA 0x511
31 #define BIOS_CFG_DMA_ADDR_HIGH 0x514
32 #define BIOS_CFG_DMA_ADDR_LOW 0x518
34 static __attribute__((unused))
35 void bios_cfg_select(uint16_t key)
37 outw(key, BIOS_CFG_IOPORT_CFG);
40 static __attribute__((unused))
41 void bios_cfg_read_entry_io(void *buf, uint16_t entry, uint32_t len)
43 bios_cfg_select(entry);
44 insb(BIOS_CFG_IOPORT_DATA, buf, len);
48 * clang is happy to inline this function, and bloats the
49 * ROM.
51 static __attribute__((__noinline__)) __attribute__((unused))
52 void bios_cfg_read_entry_dma(void *buf, uint16_t entry, uint32_t len)
54 struct fw_cfg_dma_access access;
55 uint32_t control = (entry << 16) | FW_CFG_DMA_CTL_SELECT
56 | FW_CFG_DMA_CTL_READ;
58 access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
59 access.length = cpu_to_be32(len);
60 access.control = cpu_to_be32(control);
62 barrier();
64 outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
66 while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) {
67 barrier();
71 static __attribute__((unused))
72 void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len,
73 uint32_t version)
75 if (version & FW_CFG_VERSION_DMA) {
76 bios_cfg_read_entry_dma(buf, entry, len);
77 } else {
78 bios_cfg_read_entry_io(buf, entry, len);
82 static __attribute__((unused))
83 uint32_t bios_cfg_version(void)
85 uint32_t version;
87 bios_cfg_read_entry_io(&version, FW_CFG_ID, sizeof(version));
89 return version;
92 #endif /* OPTROM_FW_CFG_H */