ia64/xen-unstable

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