ia64/xen-unstable

view xen/include/xen/libelf.h @ 19800:78962f85c562

IOMMU: Add two generic functions to vendor neutral interface

Add 2 generic functions into the vendor neutral iommu interface, The
reason is that from changeset 19732, there is only one global flag
"iommu_enabled" that controls iommu enablement for both vtd and amd
systems, so we need different code paths for vtd and amd iommu systems
if this flag has been turned on. Also, the early checking of
"iommu_enabled" in iommu_setup() is removed to prevent iommu
functionalities from been disabled on amd systems.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 19 08:41:50 2009 +0100 (2009-06-19)
parents 7df072566b8c
children
line source
1 /******************************************************************************
2 * libelf.h
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
23 #ifndef __XEN_LIBELF_H__
24 #define __XEN_LIBELF_H__
26 #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
27 #define XEN_ELF_LITTLE_ENDIAN
28 #else
29 #error define architectural endianness
30 #endif
32 #undef ELFSIZE
33 #include "elfstructs.h"
34 #ifdef __XEN__
35 #include <public/elfnote.h>
36 #include <public/features.h>
37 #else
38 #include <xen/elfnote.h>
39 #include <xen/features.h>
40 #endif
42 /* ------------------------------------------------------------------------ */
44 typedef union {
45 Elf32_Ehdr e32;
46 Elf64_Ehdr e64;
47 } elf_ehdr;
49 typedef union {
50 Elf32_Phdr e32;
51 Elf64_Phdr e64;
52 } elf_phdr;
54 typedef union {
55 Elf32_Shdr e32;
56 Elf64_Shdr e64;
57 } elf_shdr;
59 typedef union {
60 Elf32_Sym e32;
61 Elf64_Sym e64;
62 } elf_sym;
64 typedef union {
65 Elf32_Rel e32;
66 Elf64_Rel e64;
67 } elf_rel;
69 typedef union {
70 Elf32_Rela e32;
71 Elf64_Rela e64;
72 } elf_rela;
74 typedef union {
75 Elf32_Note e32;
76 Elf64_Note e64;
77 } elf_note;
79 struct elf_binary {
80 /* elf binary */
81 const char *image;
82 size_t size;
83 char class;
84 char data;
86 const elf_ehdr *ehdr;
87 const char *sec_strtab;
88 const elf_shdr *sym_tab;
89 const char *sym_strtab;
91 /* loaded to */
92 char *dest;
93 uint64_t pstart;
94 uint64_t pend;
95 uint64_t reloc_offset;
97 uint64_t bsd_symtab_pstart;
98 uint64_t bsd_symtab_pend;
100 #ifndef __XEN__
101 /* misc */
102 FILE *log;
103 #endif
104 int verbose;
105 };
107 /* ------------------------------------------------------------------------ */
108 /* accessing elf header fields */
110 #ifdef XEN_ELF_BIG_ENDIAN
111 # define NATIVE_ELFDATA ELFDATA2MSB
112 #else
113 # define NATIVE_ELFDATA ELFDATA2LSB
114 #endif
116 #define elf_32bit(elf) (ELFCLASS32 == (elf)->class)
117 #define elf_64bit(elf) (ELFCLASS64 == (elf)->class)
118 #define elf_msb(elf) (ELFDATA2MSB == (elf)->data)
119 #define elf_lsb(elf) (ELFDATA2LSB == (elf)->data)
120 #define elf_swap(elf) (NATIVE_ELFDATA != (elf)->data)
122 #define elf_uval(elf, str, elem) \
123 ((ELFCLASS64 == (elf)->class) \
124 ? elf_access_unsigned((elf), (str), \
125 offsetof(typeof(*(str)),e64.elem), \
126 sizeof((str)->e64.elem)) \
127 : elf_access_unsigned((elf), (str), \
128 offsetof(typeof(*(str)),e32.elem), \
129 sizeof((str)->e32.elem)))
131 #define elf_sval(elf, str, elem) \
132 ((ELFCLASS64 == (elf)->class) \
133 ? elf_access_signed((elf), (str), \
134 offsetof(typeof(*(str)),e64.elem), \
135 sizeof((str)->e64.elem)) \
136 : elf_access_signed((elf), (str), \
137 offsetof(typeof(*(str)),e32.elem), \
138 sizeof((str)->e32.elem)))
140 #define elf_size(elf, str) \
141 ((ELFCLASS64 == (elf)->class) \
142 ? sizeof((str)->e64) : sizeof((str)->e32))
144 uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr,
145 uint64_t offset, size_t size);
146 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
147 uint64_t offset, size_t size);
149 uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr);
151 /* ------------------------------------------------------------------------ */
152 /* xc_libelf_tools.c */
154 int elf_shdr_count(struct elf_binary *elf);
155 int elf_phdr_count(struct elf_binary *elf);
157 const elf_shdr *elf_shdr_by_name(struct elf_binary *elf, const char *name);
158 const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index);
159 const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index);
161 const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr);
162 const void *elf_section_start(struct elf_binary *elf, const elf_shdr * shdr);
163 const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr);
165 const void *elf_segment_start(struct elf_binary *elf, const elf_phdr * phdr);
166 const void *elf_segment_end(struct elf_binary *elf, const elf_phdr * phdr);
168 const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol);
169 const elf_sym *elf_sym_by_index(struct elf_binary *elf, int index);
171 const char *elf_note_name(struct elf_binary *elf, const elf_note * note);
172 const void *elf_note_desc(struct elf_binary *elf, const elf_note * note);
173 uint64_t elf_note_numeric(struct elf_binary *elf, const elf_note * note);
174 const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note);
176 int elf_is_elfbinary(const void *image);
177 int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
179 /* ------------------------------------------------------------------------ */
180 /* xc_libelf_loader.c */
182 int elf_init(struct elf_binary *elf, const char *image, size_t size);
183 #ifdef __XEN__
184 void elf_set_verbose(struct elf_binary *elf);
185 #else
186 void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose);
187 #endif
189 void elf_parse_binary(struct elf_binary *elf);
190 void elf_load_binary(struct elf_binary *elf);
192 void *elf_get_ptr(struct elf_binary *elf, unsigned long addr);
193 uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol);
195 void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart); /* private */
197 /* ------------------------------------------------------------------------ */
198 /* xc_libelf_relocate.c */
200 int elf_reloc(struct elf_binary *elf);
202 /* ------------------------------------------------------------------------ */
203 /* xc_libelf_dominfo.c */
205 #define UNSET_ADDR ((uint64_t)-1)
207 enum xen_elfnote_type {
208 XEN_ENT_NONE = 0,
209 XEN_ENT_LONG = 1,
210 XEN_ENT_STR = 2
211 };
213 struct xen_elfnote {
214 enum xen_elfnote_type type;
215 const char *name;
216 union {
217 const char *str;
218 uint64_t num;
219 } data;
220 };
222 struct elf_dom_parms {
223 /* raw */
224 const char *guest_info;
225 const void *elf_note_start;
226 const void *elf_note_end;
227 struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1];
229 /* parsed */
230 char guest_os[16];
231 char guest_ver[16];
232 char xen_ver[16];
233 char loader[16];
234 int pae;
235 int bsd_symtab;
236 uint64_t virt_base;
237 uint64_t virt_entry;
238 uint64_t virt_hypercall;
239 uint64_t virt_hv_start_low;
240 uint64_t p2m_base;
241 uint64_t elf_paddr_offset;
242 uint32_t f_supported[XENFEAT_NR_SUBMAPS];
243 uint32_t f_required[XENFEAT_NR_SUBMAPS];
245 /* calculated */
246 uint64_t virt_offset;
247 uint64_t virt_kstart;
248 uint64_t virt_kend;
249 };
251 static inline void elf_xen_feature_set(int nr, uint32_t * addr)
252 {
253 addr[nr >> 5] |= 1 << (nr & 31);
254 }
255 static inline int elf_xen_feature_get(int nr, uint32_t * addr)
256 {
257 return !!(addr[nr >> 5] & (1 << (nr & 31)));
258 }
260 int elf_xen_parse_features(const char *features,
261 uint32_t *supported,
262 uint32_t *required);
263 int elf_xen_parse_note(struct elf_binary *elf,
264 struct elf_dom_parms *parms,
265 const elf_note *note);
266 int elf_xen_parse_guest_info(struct elf_binary *elf,
267 struct elf_dom_parms *parms);
268 int elf_xen_parse(struct elf_binary *elf,
269 struct elf_dom_parms *parms);
271 #endif /* __XEN_LIBELF_H__ */