Statistics
| Branch: | Revision:

root / cpu-common.h @ 18ebcc86

History | View | Annotate | Download (7.1 kB)

1 1ad2134f Paul Brook
#ifndef CPU_COMMON_H
2 1ad2134f Paul Brook
#define CPU_COMMON_H 1
3 1ad2134f Paul Brook
4 1ad2134f Paul Brook
/* CPU interfaces that are target indpendent.  */
5 1ad2134f Paul Brook
6 37b76cfd Paolo Bonzini
#ifdef TARGET_PHYS_ADDR_BITS
7 37b76cfd Paolo Bonzini
#include "targphys.h"
8 37b76cfd Paolo Bonzini
#endif
9 37b76cfd Paolo Bonzini
10 37b76cfd Paolo Bonzini
#ifndef NEED_CPU_H
11 37b76cfd Paolo Bonzini
#include "poison.h"
12 37b76cfd Paolo Bonzini
#endif
13 37b76cfd Paolo Bonzini
14 1ad2134f Paul Brook
#include "bswap.h"
15 f6f3fbca Michael S. Tsirkin
#include "qemu-queue.h"
16 1ad2134f Paul Brook
17 b3755a91 Paul Brook
#if !defined(CONFIG_USER_ONLY)
18 b3755a91 Paul Brook
19 dd310534 Alexander Graf
enum device_endian {
20 dd310534 Alexander Graf
    DEVICE_NATIVE_ENDIAN,
21 dd310534 Alexander Graf
    DEVICE_BIG_ENDIAN,
22 dd310534 Alexander Graf
    DEVICE_LITTLE_ENDIAN,
23 dd310534 Alexander Graf
};
24 dd310534 Alexander Graf
25 1ad2134f Paul Brook
/* address in the RAM (different from a physical address) */
26 f15fbc4b Anthony PERARD
#if defined(CONFIG_XEN_BACKEND) && TARGET_PHYS_ADDR_BITS == 64
27 f15fbc4b Anthony PERARD
typedef uint64_t ram_addr_t;
28 f15fbc4b Anthony PERARD
#  define RAM_ADDR_MAX UINT64_MAX
29 f15fbc4b Anthony PERARD
#  define RAM_ADDR_FMT "%" PRIx64
30 f15fbc4b Anthony PERARD
#else
31 c227f099 Anthony Liguori
typedef unsigned long ram_addr_t;
32 f15fbc4b Anthony PERARD
#  define RAM_ADDR_MAX ULONG_MAX
33 f15fbc4b Anthony PERARD
#  define RAM_ADDR_FMT "%lx"
34 f15fbc4b Anthony PERARD
#endif
35 1ad2134f Paul Brook
36 1ad2134f Paul Brook
/* memory API */
37 1ad2134f Paul Brook
38 c227f099 Anthony Liguori
typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
39 c227f099 Anthony Liguori
typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
40 1ad2134f Paul Brook
41 0fd542fb Michael S. Tsirkin
void cpu_register_physical_memory_log(target_phys_addr_t start_addr,
42 0fd542fb Michael S. Tsirkin
                                      ram_addr_t size,
43 0fd542fb Michael S. Tsirkin
                                      ram_addr_t phys_offset,
44 0fd542fb Michael S. Tsirkin
                                      ram_addr_t region_offset,
45 0fd542fb Michael S. Tsirkin
                                      bool log_dirty);
46 0fd542fb Michael S. Tsirkin
47 0fd542fb Michael S. Tsirkin
static inline void cpu_register_physical_memory_offset(target_phys_addr_t start_addr,
48 0fd542fb Michael S. Tsirkin
                                                       ram_addr_t size,
49 0fd542fb Michael S. Tsirkin
                                                       ram_addr_t phys_offset,
50 0fd542fb Michael S. Tsirkin
                                                       ram_addr_t region_offset)
51 0fd542fb Michael S. Tsirkin
{
52 0fd542fb Michael S. Tsirkin
    cpu_register_physical_memory_log(start_addr, size, phys_offset,
53 0fd542fb Michael S. Tsirkin
                                     region_offset, false);
54 0fd542fb Michael S. Tsirkin
}
55 0fd542fb Michael S. Tsirkin
56 c227f099 Anthony Liguori
static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
57 c227f099 Anthony Liguori
                                                ram_addr_t size,
58 c227f099 Anthony Liguori
                                                ram_addr_t phys_offset)
59 1ad2134f Paul Brook
{
60 1ad2134f Paul Brook
    cpu_register_physical_memory_offset(start_addr, size, phys_offset, 0);
61 1ad2134f Paul Brook
}
62 1ad2134f Paul Brook
63 c227f099 Anthony Liguori
ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
64 84b89d78 Cam Macdonell
ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
65 84b89d78 Cam Macdonell
                        ram_addr_t size, void *host);
66 1724f049 Alex Williamson
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
67 c227f099 Anthony Liguori
void qemu_ram_free(ram_addr_t addr);
68 1f2e98b6 Alex Williamson
void qemu_ram_free_from_ptr(ram_addr_t addr);
69 cd19cfa2 Huang Ying
void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
70 1ad2134f Paul Brook
/* This should only be used for ram local to a device.  */
71 c227f099 Anthony Liguori
void *qemu_get_ram_ptr(ram_addr_t addr);
72 8ab934f9 Stefano Stabellini
void *qemu_ram_ptr_length(ram_addr_t addr, ram_addr_t *size);
73 b2e0a138 Michael S. Tsirkin
/* Same but slower, to use for migration, where the order of
74 b2e0a138 Michael S. Tsirkin
 * RAMBlocks must not change. */
75 b2e0a138 Michael S. Tsirkin
void *qemu_safe_ram_ptr(ram_addr_t addr);
76 050a0ddf Anthony PERARD
void qemu_put_ram_ptr(void *addr);
77 1ad2134f Paul Brook
/* This should not be used by devices.  */
78 e890261f Marcelo Tosatti
int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
79 e890261f Marcelo Tosatti
ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr);
80 1ad2134f Paul Brook
81 d60efc6b Blue Swirl
int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read,
82 d60efc6b Blue Swirl
                           CPUWriteMemoryFunc * const *mem_write,
83 dd310534 Alexander Graf
                           void *opaque, enum device_endian endian);
84 1ad2134f Paul Brook
void cpu_unregister_io_memory(int table_address);
85 1ad2134f Paul Brook
86 c227f099 Anthony Liguori
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
87 1ad2134f Paul Brook
                            int len, int is_write);
88 c227f099 Anthony Liguori
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
89 3bad9814 Stefan Weil
                                            void *buf, int len)
90 1ad2134f Paul Brook
{
91 1ad2134f Paul Brook
    cpu_physical_memory_rw(addr, buf, len, 0);
92 1ad2134f Paul Brook
}
93 c227f099 Anthony Liguori
static inline void cpu_physical_memory_write(target_phys_addr_t addr,
94 3bad9814 Stefan Weil
                                             const void *buf, int len)
95 1ad2134f Paul Brook
{
96 3bad9814 Stefan Weil
    cpu_physical_memory_rw(addr, (void *)buf, len, 1);
97 1ad2134f Paul Brook
}
98 c227f099 Anthony Liguori
void *cpu_physical_memory_map(target_phys_addr_t addr,
99 c227f099 Anthony Liguori
                              target_phys_addr_t *plen,
100 1ad2134f Paul Brook
                              int is_write);
101 c227f099 Anthony Liguori
void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
102 c227f099 Anthony Liguori
                               int is_write, target_phys_addr_t access_len);
103 1ad2134f Paul Brook
void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque));
104 1ad2134f Paul Brook
void cpu_unregister_map_client(void *cookie);
105 1ad2134f Paul Brook
106 f6f3fbca Michael S. Tsirkin
struct CPUPhysMemoryClient;
107 f6f3fbca Michael S. Tsirkin
typedef struct CPUPhysMemoryClient CPUPhysMemoryClient;
108 f6f3fbca Michael S. Tsirkin
struct CPUPhysMemoryClient {
109 f6f3fbca Michael S. Tsirkin
    void (*set_memory)(struct CPUPhysMemoryClient *client,
110 f6f3fbca Michael S. Tsirkin
                       target_phys_addr_t start_addr,
111 f6f3fbca Michael S. Tsirkin
                       ram_addr_t size,
112 0fd542fb Michael S. Tsirkin
                       ram_addr_t phys_offset,
113 0fd542fb Michael S. Tsirkin
                       bool log_dirty);
114 f6f3fbca Michael S. Tsirkin
    int (*sync_dirty_bitmap)(struct CPUPhysMemoryClient *client,
115 f6f3fbca Michael S. Tsirkin
                             target_phys_addr_t start_addr,
116 f6f3fbca Michael S. Tsirkin
                             target_phys_addr_t end_addr);
117 f6f3fbca Michael S. Tsirkin
    int (*migration_log)(struct CPUPhysMemoryClient *client,
118 f6f3fbca Michael S. Tsirkin
                         int enable);
119 e5896b12 Anthony PERARD
    int (*log_start)(struct CPUPhysMemoryClient *client,
120 e5896b12 Anthony PERARD
                     target_phys_addr_t phys_addr, ram_addr_t size);
121 e5896b12 Anthony PERARD
    int (*log_stop)(struct CPUPhysMemoryClient *client,
122 e5896b12 Anthony PERARD
                    target_phys_addr_t phys_addr, ram_addr_t size);
123 f6f3fbca Michael S. Tsirkin
    QLIST_ENTRY(CPUPhysMemoryClient) list;
124 f6f3fbca Michael S. Tsirkin
};
125 f6f3fbca Michael S. Tsirkin
126 f6f3fbca Michael S. Tsirkin
void cpu_register_phys_memory_client(CPUPhysMemoryClient *);
127 f6f3fbca Michael S. Tsirkin
void cpu_unregister_phys_memory_client(CPUPhysMemoryClient *);
128 f6f3fbca Michael S. Tsirkin
129 6842a08e Blue Swirl
/* Coalesced MMIO regions are areas where write operations can be reordered.
130 6842a08e Blue Swirl
 * This usually implies that write operations are side-effect free.  This allows
131 6842a08e Blue Swirl
 * batching which can make a major impact on performance when using
132 6842a08e Blue Swirl
 * virtualization.
133 6842a08e Blue Swirl
 */
134 6842a08e Blue Swirl
void qemu_register_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
135 6842a08e Blue Swirl
136 6842a08e Blue Swirl
void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
137 6842a08e Blue Swirl
138 6842a08e Blue Swirl
void qemu_flush_coalesced_mmio_buffer(void);
139 6842a08e Blue Swirl
140 c227f099 Anthony Liguori
uint32_t ldub_phys(target_phys_addr_t addr);
141 1e78bcc1 Alexander Graf
uint32_t lduw_le_phys(target_phys_addr_t addr);
142 1e78bcc1 Alexander Graf
uint32_t lduw_be_phys(target_phys_addr_t addr);
143 1e78bcc1 Alexander Graf
uint32_t ldl_le_phys(target_phys_addr_t addr);
144 1e78bcc1 Alexander Graf
uint32_t ldl_be_phys(target_phys_addr_t addr);
145 1e78bcc1 Alexander Graf
uint64_t ldq_le_phys(target_phys_addr_t addr);
146 1e78bcc1 Alexander Graf
uint64_t ldq_be_phys(target_phys_addr_t addr);
147 c227f099 Anthony Liguori
void stb_phys(target_phys_addr_t addr, uint32_t val);
148 1e78bcc1 Alexander Graf
void stw_le_phys(target_phys_addr_t addr, uint32_t val);
149 1e78bcc1 Alexander Graf
void stw_be_phys(target_phys_addr_t addr, uint32_t val);
150 1e78bcc1 Alexander Graf
void stl_le_phys(target_phys_addr_t addr, uint32_t val);
151 1e78bcc1 Alexander Graf
void stl_be_phys(target_phys_addr_t addr, uint32_t val);
152 1e78bcc1 Alexander Graf
void stq_le_phys(target_phys_addr_t addr, uint64_t val);
153 1e78bcc1 Alexander Graf
void stq_be_phys(target_phys_addr_t addr, uint64_t val);
154 c227f099 Anthony Liguori
155 21673cde Blue Swirl
#ifdef NEED_CPU_H
156 21673cde Blue Swirl
uint32_t lduw_phys(target_phys_addr_t addr);
157 21673cde Blue Swirl
uint32_t ldl_phys(target_phys_addr_t addr);
158 21673cde Blue Swirl
uint64_t ldq_phys(target_phys_addr_t addr);
159 21673cde Blue Swirl
void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
160 21673cde Blue Swirl
void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
161 21673cde Blue Swirl
void stw_phys(target_phys_addr_t addr, uint32_t val);
162 21673cde Blue Swirl
void stl_phys(target_phys_addr_t addr, uint32_t val);
163 21673cde Blue Swirl
void stq_phys(target_phys_addr_t addr, uint64_t val);
164 21673cde Blue Swirl
#endif
165 21673cde Blue Swirl
166 c227f099 Anthony Liguori
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
167 1ad2134f Paul Brook
                                   const uint8_t *buf, int len);
168 1ad2134f Paul Brook
169 1ad2134f Paul Brook
#define IO_MEM_SHIFT       3
170 1ad2134f Paul Brook
171 1ad2134f Paul Brook
#define IO_MEM_RAM         (0 << IO_MEM_SHIFT) /* hardcoded offset */
172 1ad2134f Paul Brook
#define IO_MEM_ROM         (1 << IO_MEM_SHIFT) /* hardcoded offset */
173 1ad2134f Paul Brook
#define IO_MEM_UNASSIGNED  (2 << IO_MEM_SHIFT)
174 1ad2134f Paul Brook
#define IO_MEM_NOTDIRTY    (3 << IO_MEM_SHIFT)
175 1ad2134f Paul Brook
176 1ad2134f Paul Brook
/* Acts like a ROM when read and like a device when written.  */
177 1ad2134f Paul Brook
#define IO_MEM_ROMD        (1)
178 1ad2134f Paul Brook
#define IO_MEM_SUBPAGE     (2)
179 1ad2134f Paul Brook
180 b3755a91 Paul Brook
#endif
181 b3755a91 Paul Brook
182 1ad2134f Paul Brook
#endif /* !CPU_COMMON_H */