ia64/xen-unstable

view tools/libxc/powerpc64/utils.c @ 13939:09b3fd488726

[XEND][POWERPC] Remove FlatDeviceTree.py, eliminate devtree from prose builder.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Sun Jan 21 08:15:39 2007 -0500 (2007-01-21)
parents a510c94ceaa3
children 978ff6fad81f
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright IBM Corporation 2006, 2007
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 * Jimi Xenidis <jimix@watson.ibm.com>
20 */
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/types.h>
28 #include <inttypes.h>
30 #include <xen/xen.h>
31 #include <xen/memory.h>
32 #include <xc_private.h>
33 #include <xg_private.h>
34 #include <xenctrl.h>
36 #include "flatdevtree_env.h"
37 #include "flatdevtree.h"
38 #include "utils.h"
40 int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
41 unsigned long nr_pages)
42 {
43 int rc;
44 int i;
45 xen_pfn_t *p;
47 *page_array = malloc(nr_pages * sizeof(xen_pfn_t));
48 if (*page_array == NULL) {
49 perror("malloc");
50 return -1;
51 }
53 DPRINTF("xc_get_pfn_list\n");
54 /* We know that the RMA is machine contiguous so lets just get the
55 * first MFN and fill the rest in ourselves */
56 rc = xc_get_pfn_list(xc_handle, domid, *page_array, 1);
57 if (rc == -1) {
58 perror("Could not get the page frame list");
59 return -1;
60 }
61 p = *page_array;
62 for (i = 1; i < nr_pages; i++)
63 p[i] = p[i - 1] + 1;
64 return 0;
65 }
67 int install_image(
68 int xc_handle,
69 int domid,
70 xen_pfn_t *page_array,
71 void *image,
72 unsigned long paddr,
73 unsigned long size)
74 {
75 uint8_t *img = image;
76 int i;
77 int rc = 0;
79 if (paddr & ~PAGE_MASK) {
80 printf("*** unaligned address\n");
81 return -1;
82 }
84 for (i = 0; i < size; i += PAGE_SIZE) {
85 void *page = img + i;
86 xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT;
87 xen_pfn_t mfn = page_array[pfn];
89 rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page);
90 if (rc < 0) {
91 perror("xc_copy_to_domain_page");
92 break;
93 }
94 }
95 return rc;
96 }
98 void *load_file(const char *path, unsigned long *filesize)
99 {
100 void *img;
101 ssize_t size;
102 int fd;
104 DPRINTF("load_file(%s)\n", path);
106 fd = open(path, O_RDONLY);
107 if (fd < 0) {
108 perror(path);
109 return NULL;
110 }
112 size = lseek(fd, 0, SEEK_END);
113 if (size < 0) {
114 perror(path);
115 close(fd);
116 return NULL;
117 }
118 lseek(fd, 0, SEEK_SET);
120 img = malloc(size);
121 if (img == NULL) {
122 perror(path);
123 close(fd);
124 return NULL;
125 }
127 size = read(fd, img, size);
128 if (size <= 0) {
129 perror(path);
130 close(fd);
131 free(img);
132 return NULL;
133 }
135 if (filesize)
136 *filesize = size;
137 close(fd);
138 return img;
139 }
141 int load_elf_kernel(
142 int xc_handle,
143 int domid,
144 const char *kernel_path,
145 struct domain_setup_info *dsi,
146 xen_pfn_t *page_array)
147 {
148 struct load_funcs load_funcs;
149 char *kernel_img;
150 unsigned long kernel_size;
151 int rc;
153 /* load the kernel ELF file */
154 kernel_img = load_file(kernel_path, &kernel_size);
155 if (kernel_img == NULL) {
156 rc = -1;
157 goto out;
158 }
160 DPRINTF("probe_elf\n");
161 rc = probe_elf(kernel_img, kernel_size, &load_funcs);
162 if (rc < 0) {
163 rc = -1;
164 printf("%s is not an ELF file\n", kernel_path);
165 goto out;
166 }
168 DPRINTF("parseimage\n");
169 rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi);
170 if (rc < 0) {
171 rc = -1;
172 goto out;
173 }
175 DPRINTF("loadimage\n");
176 (load_funcs.loadimage)(kernel_img, kernel_size, xc_handle, domid,
177 page_array, dsi);
179 DPRINTF(" v_start %016"PRIx64"\n", dsi->v_start);
180 DPRINTF(" v_end %016"PRIx64"\n", dsi->v_end);
181 DPRINTF(" v_kernstart %016"PRIx64"\n", dsi->v_kernstart);
182 DPRINTF(" v_kernend %016"PRIx64"\n", dsi->v_kernend);
183 DPRINTF(" v_kernentry %016"PRIx64"\n", dsi->v_kernentry);
185 out:
186 free(kernel_img);
187 return rc;
188 }