ia64/xen-unstable
changeset 12953:1a3c1168db6a
[TOOLS][POWERPC] Use a smaller page array and place common code in utils.c
Since all the bits must be loaded into the RMA there is no need to get
the entire page array, just those pages in the RMA.
We also place common functions in utils.c
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Since all the bits must be loaded into the RMA there is no need to get
the entire page array, just those pages in the RMA.
We also place common functions in utils.c
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author | Jimi Xenidis <jimix@watson.ibm.com> |
---|---|
date | Wed Oct 18 09:01:37 2006 -0400 (2006-10-18) |
parents | 5c3b6b623c57 |
children | 95cf2e3e7e0a |
files | tools/libxc/powerpc64/Makefile tools/libxc/powerpc64/utils.c tools/libxc/powerpc64/utils.h tools/libxc/powerpc64/xc_linux_build.c tools/libxc/powerpc64/xc_prose_build.c |
line diff
1.1 --- a/tools/libxc/powerpc64/Makefile Wed Oct 18 06:50:35 2006 -0400 1.2 +++ b/tools/libxc/powerpc64/Makefile Wed Oct 18 09:01:37 2006 -0400 1.3 @@ -1,4 +1,6 @@ 1.4 +GUEST_SRCS-y += powerpc64/flatdevtree.c 1.5 GUEST_SRCS-y += powerpc64/xc_linux_build.c 1.6 -GUEST_SRCS-y += powerpc64/flatdevtree.c 1.7 GUEST_SRCS-y += powerpc64/xc_prose_build.c 1.8 +GUEST_SRCS-y += powerpc64/utils.c 1.9 + 1.10 CTRL_SRCS-y += powerpc64/xc_memory.c
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tools/libxc/powerpc64/utils.c Wed Oct 18 09:01:37 2006 -0400 2.3 @@ -0,0 +1,162 @@ 2.4 +/* 2.5 + * This program is free software; you can redistribute it and/or modify 2.6 + * it under the terms of the GNU General Public License as published by 2.7 + * the Free Software Foundation; either version 2 of the License, or 2.8 + * (at your option) any later version. 2.9 + * 2.10 + * This program is distributed in the hope that it will be useful, 2.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 2.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2.13 + * GNU General Public License for more details. 2.14 + * 2.15 + * You should have received a copy of the GNU General Public License 2.16 + * along with this program; if not, write to the Free Software 2.17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 2.18 + * 2.19 + * Copyright (C) IBM Corporation 2006 2.20 + * 2.21 + * Authors: Hollis Blanchard <hollisb@us.ibm.com> 2.22 + * Jimi Xenidis <jimix@watson.ibm.com> 2.23 + */ 2.24 +#include <stdio.h> 2.25 +#include <stdint.h> 2.26 +#include <stdlib.h> 2.27 +#include <string.h> 2.28 +#include <unistd.h> 2.29 +#include <fcntl.h> 2.30 +#include <sys/types.h> 2.31 +#include <inttypes.h> 2.32 + 2.33 +#include <xen/xen.h> 2.34 +#include <xen/memory.h> 2.35 +#include <xc_private.h> 2.36 +#include <xg_private.h> 2.37 +#include <xenctrl.h> 2.38 + 2.39 +#include "flatdevtree_env.h" 2.40 +#include "flatdevtree.h" 2.41 +#include "utils.h" 2.42 + 2.43 +unsigned long get_rma_pages(void *devtree) 2.44 +{ 2.45 + void *rma; 2.46 + uint64_t rma_reg[2]; 2.47 + int rc; 2.48 + 2.49 + rma = ft_find_node(devtree, "/memory@0"); 2.50 + if (rma == NULL) { 2.51 + DPRINTF("couldn't find /memory@0\n"); 2.52 + return 0; 2.53 + } 2.54 + rc = ft_get_prop(devtree, rma, "reg", rma_reg, sizeof(rma_reg)); 2.55 + if (rc < 0) { 2.56 + DPRINTF("couldn't get /memory@0/reg\n"); 2.57 + return 0; 2.58 + } 2.59 + if (rma_reg[0] != 0) { 2.60 + DPRINTF("RMA did not start at 0\n"); 2.61 + return 0; 2.62 + } 2.63 + return rma_reg[1] >> PAGE_SHIFT; 2.64 +} 2.65 + 2.66 +int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array, 2.67 + unsigned long nr_pages) 2.68 +{ 2.69 + int rc; 2.70 + int i; 2.71 + xen_pfn_t *p; 2.72 + 2.73 + *page_array = malloc(nr_pages * sizeof(xen_pfn_t)); 2.74 + if (*page_array == NULL) { 2.75 + perror("malloc"); 2.76 + return -1; 2.77 + } 2.78 + 2.79 + DPRINTF("xc_get_pfn_list\n"); 2.80 + /* We know that the RMA is machine contiguous so lets just get the 2.81 + * first MFN and fill the rest in ourselves */ 2.82 + rc = xc_get_pfn_list(xc_handle, domid, *page_array, 1); 2.83 + if (rc != 1) { 2.84 + perror("Could not get the page frame list"); 2.85 + return -1; 2.86 + } 2.87 + p = *page_array; 2.88 + for (i = 1; i < nr_pages; i++) 2.89 + p[i] = p[i - 1] + 1; 2.90 + return 0; 2.91 +} 2.92 + 2.93 +int install_image( 2.94 + int xc_handle, 2.95 + int domid, 2.96 + xen_pfn_t *page_array, 2.97 + void *image, 2.98 + unsigned long paddr, 2.99 + unsigned long size) 2.100 +{ 2.101 + uint8_t *img = image; 2.102 + int i; 2.103 + int rc = 0; 2.104 + 2.105 + if (paddr & ~PAGE_MASK) { 2.106 + printf("*** unaligned address\n"); 2.107 + return -1; 2.108 + } 2.109 + 2.110 + for (i = 0; i < size; i += PAGE_SIZE) { 2.111 + void *page = img + i; 2.112 + xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT; 2.113 + xen_pfn_t mfn = page_array[pfn]; 2.114 + 2.115 + rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page); 2.116 + if (rc < 0) { 2.117 + perror("xc_copy_to_domain_page"); 2.118 + break; 2.119 + } 2.120 + } 2.121 + return rc; 2.122 +} 2.123 + 2.124 +void *load_file(const char *path, unsigned long *filesize) 2.125 +{ 2.126 + void *img; 2.127 + ssize_t size; 2.128 + int fd; 2.129 + 2.130 + DPRINTF("load_file(%s)\n", path); 2.131 + 2.132 + fd = open(path, O_RDONLY); 2.133 + if (fd < 0) { 2.134 + perror(path); 2.135 + return NULL; 2.136 + } 2.137 + 2.138 + size = lseek(fd, 0, SEEK_END); 2.139 + if (size < 0) { 2.140 + perror(path); 2.141 + close(fd); 2.142 + return NULL; 2.143 + } 2.144 + lseek(fd, 0, SEEK_SET); 2.145 + 2.146 + img = malloc(size); 2.147 + if (img == NULL) { 2.148 + perror(path); 2.149 + close(fd); 2.150 + return NULL; 2.151 + } 2.152 + 2.153 + size = read(fd, img, size); 2.154 + if (size <= 0) { 2.155 + perror(path); 2.156 + close(fd); 2.157 + free(img); 2.158 + return NULL; 2.159 + } 2.160 + 2.161 + if (filesize) 2.162 + *filesize = size; 2.163 + close(fd); 2.164 + return img; 2.165 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tools/libxc/powerpc64/utils.h Wed Oct 18 09:01:37 2006 -0400 3.3 @@ -0,0 +1,38 @@ 3.4 +/* 3.5 + * This program is free software; you can redistribute it and/or modify 3.6 + * it under the terms of the GNU General Public License as published by 3.7 + * the Free Software Foundation; either version 2 of the License, or 3.8 + * (at your option) any later version. 3.9 + * 3.10 + * This program is distributed in the hope that it will be useful, 3.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.13 + * GNU General Public License for more details. 3.14 + * 3.15 + * You should have received a copy of the GNU General Public License 3.16 + * along with this program; if not, write to the Free Software 3.17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 3.18 + * 3.19 + * Copyright (C) IBM Corporation 2006 3.20 + * 3.21 + * Authors: Hollis Blanchard <hollisb@us.ibm.com> 3.22 + * Jimi Xenidis <jimix@watson.ibm.com> 3.23 + */ 3.24 + 3.25 +extern unsigned long get_rma_pages(void *devtree); 3.26 +extern int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array, 3.27 + unsigned long nr_pages); 3.28 +extern int install_image(int xc_handle, int domid, xen_pfn_t *page_array, 3.29 + void *image, unsigned long paddr, unsigned long size); 3.30 +extern void *load_file(const char *path, unsigned long *filesize); 3.31 +extern int load_elf_kernel(int xc_handle, int domid, const char *kernel_path, 3.32 + struct domain_setup_info *dsi, 3.33 + xen_pfn_t *page_array); 3.34 + 3.35 +#define ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 3.36 + 3.37 +#define max(x,y) ({ \ 3.38 + const typeof(x) _x = (x); \ 3.39 + const typeof(y) _y = (y); \ 3.40 + (void) (&_x == &_y); \ 3.41 + _x > _y ? _x : _y; })
4.1 --- a/tools/libxc/powerpc64/xc_linux_build.c Wed Oct 18 06:50:35 2006 -0400 4.2 +++ b/tools/libxc/powerpc64/xc_linux_build.c Wed Oct 18 09:01:37 2006 -0400 4.3 @@ -35,61 +35,11 @@ 4.4 4.5 #include "flatdevtree_env.h" 4.6 #include "flatdevtree.h" 4.7 +#include "utils.h" 4.8 4.9 #define INITRD_ADDR (24UL << 20) 4.10 #define DEVTREE_ADDR (16UL << 20) 4.11 4.12 -#define ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 4.13 - 4.14 -#define max(x,y) ({ \ 4.15 - const typeof(x) _x = (x); \ 4.16 - const typeof(y) _y = (y); \ 4.17 - (void) (&_x == &_y); \ 4.18 - _x > _y ? _x : _y; }) 4.19 - 4.20 -static void *load_file(const char *path, unsigned long *filesize) 4.21 -{ 4.22 - void *img; 4.23 - ssize_t size; 4.24 - int fd; 4.25 - 4.26 - DPRINTF("load_file(%s)\n", path); 4.27 - 4.28 - fd = open(path, O_RDONLY); 4.29 - if (fd < 0) { 4.30 - perror(path); 4.31 - return NULL; 4.32 - } 4.33 - 4.34 - size = lseek(fd, 0, SEEK_END); 4.35 - if (size < 0) { 4.36 - perror(path); 4.37 - close(fd); 4.38 - return NULL; 4.39 - } 4.40 - lseek(fd, 0, SEEK_SET); 4.41 - 4.42 - img = malloc(size); 4.43 - if (img == NULL) { 4.44 - perror(path); 4.45 - close(fd); 4.46 - return NULL; 4.47 - } 4.48 - 4.49 - size = read(fd, img, size); 4.50 - if (size <= 0) { 4.51 - perror(path); 4.52 - close(fd); 4.53 - free(img); 4.54 - return NULL; 4.55 - } 4.56 - 4.57 - if (filesize) 4.58 - *filesize = size; 4.59 - close(fd); 4.60 - return img; 4.61 -} 4.62 - 4.63 static int init_boot_vcpu( 4.64 int xc_handle, 4.65 int domid, 4.66 @@ -128,37 +78,6 @@ static int init_boot_vcpu( 4.67 return rc; 4.68 } 4.69 4.70 -static int install_image( 4.71 - int xc_handle, 4.72 - int domid, 4.73 - xen_pfn_t *page_array, 4.74 - void *image, 4.75 - unsigned long paddr, 4.76 - unsigned long size) 4.77 -{ 4.78 - uint8_t *img = image; 4.79 - int i; 4.80 - int rc = 0; 4.81 - 4.82 - if (paddr & ~PAGE_MASK) { 4.83 - printf("*** unaligned address\n"); 4.84 - return -1; 4.85 - } 4.86 - 4.87 - for (i = 0; i < size; i += PAGE_SIZE) { 4.88 - void *page = img + i; 4.89 - xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT; 4.90 - xen_pfn_t mfn = page_array[pfn]; 4.91 - 4.92 - rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page); 4.93 - if (rc < 0) { 4.94 - perror("xc_copy_to_domain_page"); 4.95 - break; 4.96 - } 4.97 - } 4.98 - return rc; 4.99 -} 4.100 - 4.101 static int load_devtree( 4.102 int xc_handle, 4.103 int domid, 4.104 @@ -223,87 +142,6 @@ static int load_devtree( 4.105 devtree_size); 4.106 } 4.107 4.108 -unsigned long spin_list[] = { 4.109 -#if 0 4.110 - 0x100, 4.111 - 0x200, 4.112 - 0x300, 4.113 - 0x380, 4.114 - 0x400, 4.115 - 0x480, 4.116 - 0x500, 4.117 - 0x700, 4.118 - 0x900, 4.119 - 0xc00, 4.120 -#endif 4.121 - 0 4.122 -}; 4.123 - 4.124 -/* XXX yes, this is a hack */ 4.125 -static void hack_kernel_img(char *img) 4.126 -{ 4.127 - const off_t file_offset = 0x10000; 4.128 - unsigned long *addr = spin_list; 4.129 - 4.130 - while (*addr) { 4.131 - uint32_t *instruction = (uint32_t *)(img + *addr + file_offset); 4.132 - printf("installing spin loop at %lx (%x)\n", *addr, *instruction); 4.133 - *instruction = 0x48000000; 4.134 - addr++; 4.135 - } 4.136 -} 4.137 - 4.138 -static int load_kernel( 4.139 - int xc_handle, 4.140 - int domid, 4.141 - const char *kernel_path, 4.142 - struct domain_setup_info *dsi, 4.143 - xen_pfn_t *page_array) 4.144 -{ 4.145 - struct load_funcs load_funcs; 4.146 - char *kernel_img; 4.147 - unsigned long kernel_size; 4.148 - int rc; 4.149 - 4.150 - /* load the kernel ELF file */ 4.151 - kernel_img = load_file(kernel_path, &kernel_size); 4.152 - if (kernel_img == NULL) { 4.153 - rc = -1; 4.154 - goto out; 4.155 - } 4.156 - 4.157 - hack_kernel_img(kernel_img); 4.158 - 4.159 - DPRINTF("probe_elf\n"); 4.160 - rc = probe_elf(kernel_img, kernel_size, &load_funcs); 4.161 - if (rc < 0) { 4.162 - rc = -1; 4.163 - printf("%s is not an ELF file\n", kernel_path); 4.164 - goto out; 4.165 - } 4.166 - 4.167 - DPRINTF("parseimage\n"); 4.168 - rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi); 4.169 - if (rc < 0) { 4.170 - rc = -1; 4.171 - goto out; 4.172 - } 4.173 - 4.174 - DPRINTF("loadimage\n"); 4.175 - (load_funcs.loadimage)(kernel_img, kernel_size, xc_handle, domid, 4.176 - page_array, dsi); 4.177 - 4.178 - DPRINTF(" v_start %016"PRIx64"\n", dsi->v_start); 4.179 - DPRINTF(" v_end %016"PRIx64"\n", dsi->v_end); 4.180 - DPRINTF(" v_kernstart %016"PRIx64"\n", dsi->v_kernstart); 4.181 - DPRINTF(" v_kernend %016"PRIx64"\n", dsi->v_kernend); 4.182 - DPRINTF(" v_kernentry %016"PRIx64"\n", dsi->v_kernentry); 4.183 - 4.184 -out: 4.185 - free(kernel_img); 4.186 - return rc; 4.187 -} 4.188 - 4.189 static int load_initrd( 4.190 int xc_handle, 4.191 int domid, 4.192 @@ -333,9 +171,10 @@ out: 4.193 return rc; 4.194 } 4.195 4.196 -static unsigned long create_start_info(start_info_t *start_info, 4.197 +static unsigned long create_start_info( 4.198 + start_info_t *start_info, 4.199 unsigned int console_evtchn, unsigned int store_evtchn, 4.200 - unsigned long nr_pages) 4.201 + unsigned long nr_pages, unsigned long rma_pages) 4.202 { 4.203 unsigned long start_info_addr; 4.204 4.205 @@ -353,31 +192,6 @@ static unsigned long create_start_info(s 4.206 return start_info_addr; 4.207 } 4.208 4.209 -static int get_page_array(int xc_handle, int domid, xen_pfn_t **page_array, 4.210 - unsigned long *nr_pages) 4.211 -{ 4.212 - int rc; 4.213 - 4.214 - DPRINTF("xc_get_tot_pages\n"); 4.215 - *nr_pages = xc_get_tot_pages(xc_handle, domid); 4.216 - DPRINTF(" 0x%lx\n", *nr_pages); 4.217 - 4.218 - *page_array = malloc(*nr_pages * sizeof(xen_pfn_t)); 4.219 - if (*page_array == NULL) { 4.220 - perror("malloc"); 4.221 - return -1; 4.222 - } 4.223 - 4.224 - DPRINTF("xc_get_pfn_list\n"); 4.225 - rc = xc_get_pfn_list(xc_handle, domid, *page_array, *nr_pages); 4.226 - if (rc != *nr_pages) { 4.227 - perror("Could not get the page frame list"); 4.228 - return -1; 4.229 - } 4.230 - 4.231 - return 0; 4.232 -} 4.233 - 4.234 static void free_page_array(xen_pfn_t *page_array) 4.235 { 4.236 free(page_array); 4.237 @@ -407,17 +221,28 @@ int xc_linux_build(int xc_handle, 4.238 unsigned long initrd_base = 0; 4.239 unsigned long initrd_len = 0; 4.240 unsigned long start_info_addr; 4.241 + unsigned long rma_pages; 4.242 int rc = 0; 4.243 4.244 DPRINTF("%s\n", __func__); 4.245 4.246 - if (get_page_array(xc_handle, domid, &page_array, &nr_pages)) { 4.247 + DPRINTF("xc_get_tot_pages\n"); 4.248 + nr_pages = xc_get_tot_pages(xc_handle, domid); 4.249 + DPRINTF("nr_pages 0x%lx\n", nr_pages); 4.250 + 4.251 + rma_pages = get_rma_pages(devtree); 4.252 + if (rma_pages == 0) { 4.253 + rc = -1; 4.254 + goto out; 4.255 + } 4.256 + 4.257 + if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) { 4.258 rc = -1; 4.259 goto out; 4.260 } 4.261 4.262 DPRINTF("loading image '%s'\n", image_name); 4.263 - if (load_kernel(xc_handle, domid, image_name, &dsi, page_array)) { 4.264 + if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) { 4.265 rc = -1; 4.266 goto out; 4.267 } 4.268 @@ -434,7 +259,7 @@ int xc_linux_build(int xc_handle, 4.269 4.270 /* start_info stuff: about to be removed */ 4.271 start_info_addr = create_start_info(&start_info, console_evtchn, 4.272 - store_evtchn, nr_pages); 4.273 + store_evtchn, nr_pages, rma_pages); 4.274 *console_mfn = page_array[start_info.console.domU.mfn]; 4.275 *store_mfn = page_array[start_info.store_mfn]; 4.276 if (install_image(xc_handle, domid, page_array, &start_info,
5.1 --- a/tools/libxc/powerpc64/xc_prose_build.c Wed Oct 18 06:50:35 2006 -0400 5.2 +++ b/tools/libxc/powerpc64/xc_prose_build.c Wed Oct 18 09:01:37 2006 -0400 5.3 @@ -35,61 +35,11 @@ 5.4 5.5 #include "flatdevtree_env.h" 5.6 #include "flatdevtree.h" 5.7 +#include "utils.h" 5.8 5.9 #define INITRD_ADDR (24UL << 20) 5.10 #define DEVTREE_ADDR (16UL << 20) 5.11 5.12 -#define ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 5.13 - 5.14 -#define max(x,y) ({ \ 5.15 - const typeof(x) _x = (x); \ 5.16 - const typeof(y) _y = (y); \ 5.17 - (void) (&_x == &_y); \ 5.18 - _x > _y ? _x : _y; }) 5.19 - 5.20 -static void *load_file(const char *path, unsigned long *filesize) 5.21 -{ 5.22 - void *img; 5.23 - ssize_t size; 5.24 - int fd; 5.25 - 5.26 - DPRINTF("load_file(%s)\n", path); 5.27 - 5.28 - fd = open(path, O_RDONLY); 5.29 - if (fd < 0) { 5.30 - perror(path); 5.31 - return NULL; 5.32 - } 5.33 - 5.34 - size = lseek(fd, 0, SEEK_END); 5.35 - if (size < 0) { 5.36 - perror(path); 5.37 - close(fd); 5.38 - return NULL; 5.39 - } 5.40 - lseek(fd, 0, SEEK_SET); 5.41 - 5.42 - img = malloc(size); 5.43 - if (img == NULL) { 5.44 - perror(path); 5.45 - close(fd); 5.46 - return NULL; 5.47 - } 5.48 - 5.49 - size = read(fd, img, size); 5.50 - if (size <= 0) { 5.51 - perror(path); 5.52 - close(fd); 5.53 - free(img); 5.54 - return NULL; 5.55 - } 5.56 - 5.57 - if (filesize) 5.58 - *filesize = size; 5.59 - close(fd); 5.60 - return img; 5.61 -} 5.62 - 5.63 static int init_boot_vcpu( 5.64 int xc_handle, 5.65 int domid, 5.66 @@ -128,37 +78,6 @@ static int init_boot_vcpu( 5.67 return rc; 5.68 } 5.69 5.70 -static int install_image( 5.71 - int xc_handle, 5.72 - int domid, 5.73 - xen_pfn_t *page_array, 5.74 - void *image, 5.75 - unsigned long paddr, 5.76 - unsigned long size) 5.77 -{ 5.78 - uint8_t *img = image; 5.79 - int i; 5.80 - int rc = 0; 5.81 - 5.82 - if (paddr & ~PAGE_MASK) { 5.83 - printf("*** unaligned address\n"); 5.84 - return -1; 5.85 - } 5.86 - 5.87 - for (i = 0; i < size; i += PAGE_SIZE) { 5.88 - void *page = img + i; 5.89 - xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT; 5.90 - xen_pfn_t mfn = page_array[pfn]; 5.91 - 5.92 - rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page); 5.93 - if (rc < 0) { 5.94 - perror("xc_copy_to_domain_page"); 5.95 - break; 5.96 - } 5.97 - } 5.98 - return rc; 5.99 -} 5.100 - 5.101 static int load_devtree( 5.102 int xc_handle, 5.103 int domid, 5.104 @@ -238,55 +157,6 @@ static int load_devtree( 5.105 devtree_size); 5.106 } 5.107 5.108 -static int load_kernel( 5.109 - int xc_handle, 5.110 - int domid, 5.111 - const char *kernel_path, 5.112 - struct domain_setup_info *dsi, 5.113 - xen_pfn_t *page_array) 5.114 -{ 5.115 - struct load_funcs load_funcs; 5.116 - char *kernel_img; 5.117 - unsigned long kernel_size; 5.118 - int rc; 5.119 - 5.120 - /* load the kernel ELF file */ 5.121 - kernel_img = load_file(kernel_path, &kernel_size); 5.122 - if (kernel_img == NULL) { 5.123 - rc = -1; 5.124 - goto out; 5.125 - } 5.126 - 5.127 - DPRINTF("probe_elf\n"); 5.128 - rc = probe_elf(kernel_img, kernel_size, &load_funcs); 5.129 - if (rc < 0) { 5.130 - rc = -1; 5.131 - printf("%s is not an ELF file\n", kernel_path); 5.132 - goto out; 5.133 - } 5.134 - 5.135 - DPRINTF("parseimage\n"); 5.136 - rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi); 5.137 - if (rc < 0) { 5.138 - rc = -1; 5.139 - goto out; 5.140 - } 5.141 - 5.142 - DPRINTF("loadimage\n"); 5.143 - (load_funcs.loadimage)(kernel_img, kernel_size, xc_handle, domid, 5.144 - page_array, dsi); 5.145 - 5.146 - DPRINTF(" v_start %016"PRIx64"\n", dsi->v_start); 5.147 - DPRINTF(" v_end %016"PRIx64"\n", dsi->v_end); 5.148 - DPRINTF(" v_kernstart %016"PRIx64"\n", dsi->v_kernstart); 5.149 - DPRINTF(" v_kernend %016"PRIx64"\n", dsi->v_kernend); 5.150 - DPRINTF(" v_kernentry %016"PRIx64"\n", dsi->v_kernentry); 5.151 - 5.152 -out: 5.153 - free(kernel_img); 5.154 - return rc; 5.155 -} 5.156 - 5.157 static int load_initrd( 5.158 int xc_handle, 5.159 int domid, 5.160 @@ -316,13 +186,12 @@ out: 5.161 return rc; 5.162 } 5.163 5.164 -static unsigned long create_start_info(void *devtree, start_info_t *start_info, 5.165 +static unsigned long create_start_info( 5.166 + void *devtree, start_info_t *start_info, 5.167 unsigned int console_evtchn, unsigned int store_evtchn, 5.168 - unsigned long nr_pages, const char *cmdline) 5.169 + unsigned long nr_pages, unsigned long rma_pages, const char *cmdline) 5.170 { 5.171 - void *rma; 5.172 unsigned long start_info_addr; 5.173 - uint64_t rma_reg[2]; 5.174 uint64_t rma_top; 5.175 int rc; 5.176 5.177 @@ -330,17 +199,7 @@ static unsigned long create_start_info(v 5.178 snprintf(start_info->magic, sizeof(start_info->magic), 5.179 "xen-%d.%d-powerpc64HV", 3, 0); 5.180 5.181 - rma = ft_find_node(devtree, "/memory@0"); 5.182 - if (rma == NULL) { 5.183 - DPRINTF("couldn't find /memory@0\n"); 5.184 - return ~0UL; 5.185 - } 5.186 - rc = ft_get_prop(devtree, rma, "reg", rma_reg, sizeof(rma_reg)); 5.187 - if (rc < 0) { 5.188 - DPRINTF("couldn't get /memory@0/reg\n"); 5.189 - return ~0UL; 5.190 - } 5.191 - rma_top = rma_reg[0] + rma_reg[1]; 5.192 + rma_top = rma_pages << PAGE_SHIFT; 5.193 DPRINTF("RMA top = 0x%"PRIX64"\n", rma_top); 5.194 5.195 start_info->nr_pages = nr_pages; 5.196 @@ -361,38 +220,12 @@ static unsigned long create_start_info(v 5.197 return start_info_addr; 5.198 } 5.199 5.200 -static int get_page_array(int xc_handle, int domid, xen_pfn_t **page_array, 5.201 - unsigned long *nr_pages) 5.202 -{ 5.203 - int rc; 5.204 - 5.205 - DPRINTF("xc_get_tot_pages\n"); 5.206 - *nr_pages = xc_get_tot_pages(xc_handle, domid); 5.207 - DPRINTF(" 0x%lx\n", *nr_pages); 5.208 - 5.209 - *page_array = malloc(*nr_pages * sizeof(xen_pfn_t)); 5.210 - if (*page_array == NULL) { 5.211 - perror("malloc"); 5.212 - return -1; 5.213 - } 5.214 - 5.215 - DPRINTF("xc_get_pfn_list\n"); 5.216 - rc = xc_get_pfn_list(xc_handle, domid, *page_array, *nr_pages); 5.217 - if (rc != *nr_pages) { 5.218 - perror("Could not get the page frame list"); 5.219 - return -1; 5.220 - } 5.221 - 5.222 - return 0; 5.223 -} 5.224 5.225 static void free_page_array(xen_pfn_t *page_array) 5.226 { 5.227 free(page_array); 5.228 } 5.229 5.230 - 5.231 - 5.232 int xc_prose_build(int xc_handle, 5.233 uint32_t domid, 5.234 const char *image_name, 5.235 @@ -415,19 +248,30 @@ int xc_prose_build(int xc_handle, 5.236 unsigned long initrd_base = 0; 5.237 unsigned long initrd_len = 0; 5.238 unsigned long start_info_addr; 5.239 + unsigned long rma_pages; 5.240 int rc = 0; 5.241 5.242 DPRINTF("%s\n", __func__); 5.243 5.244 DPRINTF("cmdline=%s\n", cmdline); 5.245 5.246 - if (get_page_array(xc_handle, domid, &page_array, &nr_pages)) { 5.247 + DPRINTF("xc_get_tot_pages\n"); 5.248 + nr_pages = xc_get_tot_pages(xc_handle, domid); 5.249 + DPRINTF("nr_pages 0x%lx\n", nr_pages); 5.250 + 5.251 + rma_pages = get_rma_pages(devtree); 5.252 + if (rma_pages == 0) { 5.253 + rc = -1; 5.254 + goto out; 5.255 + } 5.256 + 5.257 + if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) { 5.258 rc = -1; 5.259 goto out; 5.260 } 5.261 5.262 DPRINTF("loading image '%s'\n", image_name); 5.263 - if (load_kernel(xc_handle, domid, image_name, &dsi, page_array)) { 5.264 + if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) { 5.265 rc = -1; 5.266 goto out; 5.267 } 5.268 @@ -444,7 +288,8 @@ int xc_prose_build(int xc_handle, 5.269 5.270 /* start_info stuff: about to be removed */ 5.271 start_info_addr = create_start_info(devtree, &start_info, console_evtchn, 5.272 - store_evtchn, nr_pages, cmdline); 5.273 + store_evtchn, nr_pages, 5.274 + rma_pages, cmdline); 5.275 *console_mfn = page_array[start_info.console.domU.mfn]; 5.276 *store_mfn = page_array[start_info.store_mfn]; 5.277 if (install_image(xc_handle, domid, page_array, &start_info,