blob: b0b3b5945ef09ba67ac4e700741ec687f5537d51 [file] [log] [blame]
Miao Yanf60df202016-01-07 01:32:00 -08001/*
2 * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#ifndef __FW_CFG__
8#define __FW_CFG__
9
Miao Yan25757222016-01-20 01:57:04 -080010#include <linux/list.h>
11
Miao Yanf60df202016-01-07 01:32:00 -080012enum qemu_fwcfg_items {
13 FW_CFG_SIGNATURE = 0x00,
14 FW_CFG_ID = 0x01,
15 FW_CFG_UUID = 0x02,
16 FW_CFG_RAM_SIZE = 0x03,
17 FW_CFG_NOGRAPHIC = 0x04,
18 FW_CFG_NB_CPUS = 0x05,
19 FW_CFG_MACHINE_ID = 0x06,
20 FW_CFG_KERNEL_ADDR = 0x07,
21 FW_CFG_KERNEL_SIZE = 0x08,
22 FW_CFG_KERNEL_CMDLINE = 0x09,
23 FW_CFG_INITRD_ADDR = 0x0a,
24 FW_CFG_INITRD_SIZE = 0x0b,
25 FW_CFG_BOOT_DEVICE = 0x0c,
26 FW_CFG_NUMA = 0x0d,
27 FW_CFG_BOOT_MENU = 0x0e,
28 FW_CFG_MAX_CPUS = 0x0f,
29 FW_CFG_KERNEL_ENTRY = 0x10,
30 FW_CFG_KERNEL_DATA = 0x11,
31 FW_CFG_INITRD_DATA = 0x12,
32 FW_CFG_CMDLINE_ADDR = 0x13,
33 FW_CFG_CMDLINE_SIZE = 0x14,
34 FW_CFG_CMDLINE_DATA = 0x15,
35 FW_CFG_SETUP_ADDR = 0x16,
36 FW_CFG_SETUP_SIZE = 0x17,
37 FW_CFG_SETUP_DATA = 0x18,
38 FW_CFG_FILE_DIR = 0x19,
39 FW_CFG_FILE_FIRST = 0x20,
40 FW_CFG_WRITE_CHANNEL = 0x4000,
41 FW_CFG_ARCH_LOCAL = 0x8000,
42 FW_CFG_INVALID = 0xffff,
43};
44
Miao Yanfa287b12016-01-20 01:57:06 -080045enum {
46 BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1,
47 BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2,
48 BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
49};
50
51enum {
52 BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
53 BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
54};
55
Miao Yanf60df202016-01-07 01:32:00 -080056#define FW_CFG_FILE_SLOTS 0x10
57#define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST + FW_CFG_FILE_SLOTS)
58#define FW_CFG_ENTRY_MASK ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
59
60#define FW_CFG_MAX_FILE_PATH 56
Miao Yanfa287b12016-01-20 01:57:06 -080061#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
Miao Yanf60df202016-01-07 01:32:00 -080062
63#define QEMU_FW_CFG_SIGNATURE (('Q' << 24) | ('E' << 16) | ('M' << 8) | 'U')
64
65#define FW_CFG_DMA_ERROR (1 << 0)
66#define FW_CFG_DMA_READ (1 << 1)
67#define FW_CFG_DMA_SKIP (1 << 2)
68#define FW_CFG_DMA_SELECT (1 << 3)
69
70#define FW_CFG_DMA_ENABLED (1 << 1)
71
72struct fw_cfg_file {
73 __be32 size;
74 __be16 select;
75 __be16 reserved;
76 char name[FW_CFG_MAX_FILE_PATH];
77};
78
Miao Yan25757222016-01-20 01:57:04 -080079struct fw_file {
80 struct fw_cfg_file cfg; /* firmware file information */
81 unsigned long addr; /* firmware file in-memory address */
82 struct list_head list; /* list node to link to fw_list */
Miao Yanf60df202016-01-07 01:32:00 -080083};
84
Miao Yan099b2192016-05-22 19:37:11 -070085struct fw_cfg_file_iter {
86 struct list_head *entry; /* structure to iterate file list */
87};
88
Miao Yanf60df202016-01-07 01:32:00 -080089struct fw_cfg_dma_access {
90 __be32 control;
91 __be32 length;
92 __be64 address;
93};
94
Miao Yan2e82e742016-05-22 19:37:15 -070095struct fw_cfg_arch_ops {
96 void (*arch_read_pio)(uint16_t selector, uint32_t size,
97 void *address);
98 void (*arch_read_dma)(struct fw_cfg_dma_access *dma);
99};
100
Miao Yanfa287b12016-01-20 01:57:06 -0800101struct bios_linker_entry {
102 __le32 command;
103 union {
104 /*
105 * COMMAND_ALLOCATE - allocate a table from @alloc.file
106 * subject to @alloc.align alignment (must be power of 2)
107 * and @alloc.zone (can be HIGH or FSEG) requirements.
108 *
109 * Must appear exactly once for each file, and before
110 * this file is referenced by any other command.
111 */
112 struct {
113 char file[BIOS_LINKER_LOADER_FILESZ];
114 __le32 align;
115 uint8_t zone;
116 } alloc;
117
118 /*
119 * COMMAND_ADD_POINTER - patch the table (originating from
120 * @dest_file) at @pointer.offset, by adding a pointer to the
121 * table originating from @src_file. 1,2,4 or 8 byte unsigned
122 * addition is used depending on @pointer.size.
123 */
124 struct {
125 char dest_file[BIOS_LINKER_LOADER_FILESZ];
126 char src_file[BIOS_LINKER_LOADER_FILESZ];
127 __le32 offset;
128 uint8_t size;
129 } pointer;
130
131 /*
132 * COMMAND_ADD_CHECKSUM - calculate checksum of the range
133 * specified by @cksum_start and @cksum_length fields,
134 * and then add the value at @cksum.offset.
135 * Checksum simply sums -X for each byte X in the range
136 * using 8-bit math.
137 */
138 struct {
139 char file[BIOS_LINKER_LOADER_FILESZ];
140 __le32 offset;
141 __le32 start;
142 __le32 length;
143 } cksum;
144
145 /* padding */
146 char pad[124];
147 };
148} __packed;
149
Miao Yanf60df202016-01-07 01:32:00 -0800150/**
151 * Initialize QEMU fw_cfg interface
Miao Yan2e82e742016-05-22 19:37:15 -0700152 *
153 * @ops: arch specific read operations
Miao Yanf60df202016-01-07 01:32:00 -0800154 */
Miao Yan2e82e742016-05-22 19:37:15 -0700155void qemu_fwcfg_init(struct fw_cfg_arch_ops *ops);
Miao Yanf60df202016-01-07 01:32:00 -0800156
Tom Rinidd6f3ab2016-05-06 10:40:22 -0400157void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address);
158int qemu_fwcfg_read_firmware_list(void);
159struct fw_file *qemu_fwcfg_find_file(const char *name);
Tom Rinidd6f3ab2016-05-06 10:40:22 -0400160
Miao Yanf60df202016-01-07 01:32:00 -0800161/**
162 * Get system cpu number
163 *
164 * @return: cpu number in system
165 */
166int qemu_fwcfg_online_cpus(void);
167
Miao Yan099b2192016-05-22 19:37:11 -0700168/* helper functions to iterate firmware file list */
169struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter);
170struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter);
171bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter);
172
Miao Yand3ad0622016-05-22 19:37:13 -0700173bool qemu_fwcfg_present(void);
174bool qemu_fwcfg_dma_present(void);
175
Miao Yanf60df202016-01-07 01:32:00 -0800176#endif