ia64/xen-unstable

changeset 15318:71377eab1874

[IA64] White space cleanup from nvram patch

This file is using space indenting. No functional changes.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Mon Jun 11 14:19:05 2007 -0600 (2007-06-11)
parents 51f5bea7b0d8
children 2d72521fbdfd
files tools/libxc/ia64/xc_ia64_hvm_build.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon Jun 11 13:59:48 2007 -0600
     1.2 +++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon Jun 11 14:19:05 2007 -0600
     1.3 @@ -124,7 +124,7 @@ typedef enum {
     1.4      HOB_TYPE_PAL_VM_INFO,
     1.5      HOB_TYPE_PAL_VM_PAGE_SIZE,
     1.6      HOB_TYPE_NR_VCPU,
     1.7 -	HOB_TYPE_NVRAM,
     1.8 +    HOB_TYPE_NVRAM,
     1.9      HOB_TYPE_MAX
    1.10  } hob_type_t;
    1.11  
    1.12 @@ -135,14 +135,14 @@ static int add_vcpus_hob(void* hob_buf, 
    1.13  static int add_nvram_hob(void* hob_buf, unsigned long nvram_addr);
    1.14  static int build_hob(void* hob_buf, unsigned long hob_buf_size,
    1.15                       unsigned long dom_mem_size, unsigned long vcpus,
    1.16 -					 unsigned long nvram_addr);
    1.17 +                     unsigned long nvram_addr);
    1.18  static int load_hob(int xc_handle,uint32_t dom, void *hob_buf,
    1.19                      unsigned long dom_mem_size);
    1.20  
    1.21  static int
    1.22  xc_ia64_build_hob(int xc_handle, uint32_t dom,
    1.23                    unsigned long memsize, unsigned long vcpus,
    1.24 -				  unsigned long nvram_addr)
    1.25 +                  unsigned long nvram_addr)
    1.26  {
    1.27      char   *hob_buf;
    1.28  
    1.29 @@ -251,7 +251,7 @@ get_hob_size(void* hob_buf)
    1.30  static int
    1.31  build_hob(void* hob_buf, unsigned long hob_buf_size,
    1.32            unsigned long dom_mem_size, unsigned long vcpus,
    1.33 -		  unsigned long nvram_addr)
    1.34 +          unsigned long nvram_addr)
    1.35  {
    1.36      //Init HOB List
    1.37      if (hob_init(hob_buf, hob_buf_size) < 0) {
    1.38 @@ -274,10 +274,10 @@ build_hob(void* hob_buf, unsigned long h
    1.39          goto err_out;
    1.40      }
    1.41  
    1.42 -	if (add_nvram_hob( hob_buf, nvram_addr ) < 0) {
    1.43 -		PERROR("Add nvram hob failed, buffer too small");
    1.44 -		goto err_out;
    1.45 -	}
    1.46 +    if (add_nvram_hob( hob_buf, nvram_addr ) < 0) {
    1.47 +        PERROR("Add nvram hob failed, buffer too small");
    1.48 +        goto err_out;
    1.49 +    }
    1.50  
    1.51      return 0;
    1.52  
    1.53 @@ -342,7 +342,7 @@ add_vcpus_hob(void* hob_buf, unsigned lo
    1.54  static int
    1.55  add_nvram_hob(void *hob_buf, unsigned long nvram_addr)
    1.56  {
    1.57 -	return hob_add(hob_buf, HOB_TYPE_NVRAM, &nvram_addr, sizeof(nvram_addr));
    1.58 +    return hob_add(hob_buf, HOB_TYPE_NVRAM, &nvram_addr, sizeof(nvram_addr));
    1.59  }
    1.60  
    1.61  static const unsigned char config_pal_bus_get_features_data[24] = {
    1.62 @@ -576,49 +576,48 @@ add_pal_hob(void* hob_buf)
    1.63  static uint64_t 
    1.64  nvram_init(const char *nvram_path)
    1.65  {
    1.66 -	uint64_t fd = 0;
    1.67 -	fd = open(nvram_path, O_CREAT|O_RDWR, 0666);
    1.68 +    uint64_t fd = 0;
    1.69 +    fd = open(nvram_path, O_CREAT|O_RDWR, 0666);
    1.70  
    1.71 -	if ( fd < 0 )
    1.72 -	{
    1.73 -		PERROR("Nvram open failed at %s. Guest will boot without"
    1.74 -				" nvram support!\n", nvram_path);	
    1.75 -		return -1;
    1.76 -	}
    1.77 +    if ( fd < 0 )
    1.78 +    {
    1.79 +        PERROR("Nvram open failed at %s. Guest will boot without"
    1.80 +               " nvram support!\n", nvram_path);	
    1.81 +        return -1;
    1.82 +    }
    1.83  
    1.84 -	return VALIDATE_NVRAM_FD(fd);
    1.85 +    return VALIDATE_NVRAM_FD(fd);
    1.86  }
    1.87  
    1.88  static int 
    1.89  copy_from_nvram_to_GFW(int xc_handle, uint32_t dom, int nvram_fd)
    1.90  {
    1.91 -	unsigned int nr_pages = NVRAM_SIZE >> PAGE_SHIFT;
    1.92 -	struct stat file_stat;
    1.93 -	char buf[NVRAM_SIZE] = {0};
    1.94 +    unsigned int nr_pages = NVRAM_SIZE >> PAGE_SHIFT;
    1.95 +    struct stat file_stat;
    1.96 +    char buf[NVRAM_SIZE] = {0};
    1.97  	
    1.98 -	if ( fstat(nvram_fd, &file_stat) < 0 )
    1.99 -	{
   1.100 -		PERROR("Cannot get Nvram file info! Guest will boot without "
   1.101 -			   "nvram support!\n");
   1.102 -		return -1;
   1.103 -	}
   1.104 +    if ( fstat(nvram_fd, &file_stat) < 0 )
   1.105 +    {
   1.106 +        PERROR("Cannot get Nvram file info! Guest will boot without "
   1.107 +               "nvram support!\n");
   1.108 +        return -1;
   1.109 +    }
   1.110  
   1.111 -	if ( 0 == file_stat.st_size )
   1.112 -	{
   1.113 -		DPRINTF("Nvram file create successful!\n");
   1.114 -		return 0;
   1.115 -	}
   1.116 +    if ( 0 == file_stat.st_size )
   1.117 +    {
   1.118 +        DPRINTF("Nvram file create successful!\n");
   1.119 +        return 0;
   1.120 +    }
   1.121  
   1.122 -	if ( read(nvram_fd, buf, NVRAM_SIZE) != NVRAM_SIZE )
   1.123 -	{
   1.124 -		PERROR("Load nvram fail. guest will boot without"
   1.125 -			   " nvram support!\n");
   1.126 -		return -1;
   1.127 -	}
   1.128 +    if ( read(nvram_fd, buf, NVRAM_SIZE) != NVRAM_SIZE )
   1.129 +    {
   1.130 +        PERROR("Load nvram fail. guest will boot without"
   1.131 +               " nvram support!\n");
   1.132 +        return -1;
   1.133 +    }
   1.134  
   1.135 -	return  xc_ia64_copy_to_domain_pages(xc_handle, dom, buf,
   1.136 -											NVRAM_START >> PAGE_SHIFT,
   1.137 -											nr_pages);
   1.138 +    return  xc_ia64_copy_to_domain_pages(xc_handle, dom, buf,
   1.139 +                                         NVRAM_START >> PAGE_SHIFT, nr_pages);
   1.140  }
   1.141  
   1.142  
   1.143 @@ -630,121 +629,120 @@ copy_from_nvram_to_GFW(int xc_handle, ui
   1.144  static int
   1.145  copy_from_GFW_to_nvram(int xc_handle, uint32_t dom, int nvram_fd)
   1.146  {
   1.147 -	xen_pfn_t *pfn_list = NULL;
   1.148 -	char *tmp_ptr = NULL;
   1.149 -	unsigned int nr_pages = 0;
   1.150 -	uint64_t addr_from_GFW_4k_align = 0;
   1.151 -	uint32_t offset = 0;
   1.152 -	uint64_t nvram_base_addr = 0;
   1.153 -	char buf[NVRAM_SIZE] = {0};
   1.154 -	int i;
   1.155 +    xen_pfn_t *pfn_list = NULL;
   1.156 +    char *tmp_ptr = NULL;
   1.157 +    unsigned int nr_pages = 0;
   1.158 +    uint64_t addr_from_GFW_4k_align = 0;
   1.159 +    uint32_t offset = 0;
   1.160 +    uint64_t nvram_base_addr = 0;
   1.161 +    char buf[NVRAM_SIZE] = {0};
   1.162 +    int i;
   1.163  
   1.164 -	
   1.165 -	// map one more page 
   1.166 -	nr_pages = (NVRAM_SIZE + PAGE_SIZE) >> PAGE_SHIFT;
   1.167 -	pfn_list = (xen_pfn_t *)malloc(sizeof(xen_pfn_t) * nr_pages);
   1.168 -	if ( NULL == pfn_list )
   1.169 -	{
   1.170 -		PERROR("Cannot allocate memory for nvram save!\n");
   1.171 -		close(nvram_fd);
   1.172 -		return -1;
   1.173 -	}
   1.174 +    // map one more page 
   1.175 +    nr_pages = (NVRAM_SIZE + PAGE_SIZE) >> PAGE_SHIFT;
   1.176 +    pfn_list = (xen_pfn_t *)malloc(sizeof(xen_pfn_t) * nr_pages);
   1.177 +    if ( NULL == pfn_list )
   1.178 +    {
   1.179 +        PERROR("Cannot allocate memory for nvram save!\n");
   1.180 +        close(nvram_fd);
   1.181 +        return -1;
   1.182 +    }
   1.183  
   1.184 -	/* 
   1.185 -	 * GFW allocate memory dynamicly to save nvram data
   1.186 -	 * and save address of the dynamic memory at NVRAM_START. 
   1.187 -	 * To save nvram data to file, we must get the dynamic
   1.188 -	 * memory address first.
   1.189 -	 */
   1.190 -	pfn_list[0] = NVRAM_START >> PAGE_SHIFT;
   1.191 -	tmp_ptr = (char *)xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   1.192 -			PROT_READ | PROT_WRITE, pfn_list[0]);
   1.193 +    /* 
   1.194 +     * GFW allocate memory dynamicly to save nvram data
   1.195 +     * and save address of the dynamic memory at NVRAM_START. 
   1.196 +     * To save nvram data to file, we must get the dynamic
   1.197 +     * memory address first.
   1.198 +     */
   1.199 +    pfn_list[0] = NVRAM_START >> PAGE_SHIFT;
   1.200 +    tmp_ptr = (char *)xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   1.201 +                                           PROT_READ | PROT_WRITE, pfn_list[0]);
   1.202  
   1.203 -	if ( NULL == tmp_ptr )
   1.204 -	{
   1.205 -		PERROR("Cannot get nvram data from GFW!\n");
   1.206 -		free(pfn_list);
   1.207 -		close(nvram_fd);
   1.208 -		return -1;
   1.209 -	}
   1.210 +    if ( NULL == tmp_ptr )
   1.211 +    {
   1.212 +        PERROR("Cannot get nvram data from GFW!\n");
   1.213 +        free(pfn_list);
   1.214 +        close(nvram_fd);
   1.215 +        return -1;
   1.216 +    }
   1.217  
   1.218 -	addr_from_GFW_4k_align = *((uint64_t *)tmp_ptr);
   1.219 -	munmap(tmp_ptr, PAGE_SIZE);
   1.220 +    addr_from_GFW_4k_align = *((uint64_t *)tmp_ptr);
   1.221 +    munmap(tmp_ptr, PAGE_SIZE);
   1.222  
   1.223 -	// align address to 16k
   1.224 -	offset = addr_from_GFW_4k_align % ( 16 * MEM_K );
   1.225 -	addr_from_GFW_4k_align = addr_from_GFW_4k_align - offset;
   1.226 -	for ( i=0; i<nr_pages; i++ )
   1.227 -		pfn_list[i] = (addr_from_GFW_4k_align >> PAGE_SHIFT) + i;
   1.228 +    // align address to 16k
   1.229 +    offset = addr_from_GFW_4k_align % ( 16 * MEM_K );
   1.230 +    addr_from_GFW_4k_align = addr_from_GFW_4k_align - offset;
   1.231 +    for ( i=0; i<nr_pages; i++ )
   1.232 +        pfn_list[i] = (addr_from_GFW_4k_align >> PAGE_SHIFT) + i;
   1.233  
   1.234 -	tmp_ptr = (char *)xc_map_foreign_batch(xc_handle, dom,
   1.235 -						PROT_READ | PROT_WRITE, pfn_list, nr_pages);
   1.236 -	if ( NULL == tmp_ptr )
   1.237 -	{
   1.238 -		PERROR("Cannot get nvram data from GFW!\n");
   1.239 -		free(pfn_list);
   1.240 -		close(nvram_fd);
   1.241 -		return -1;
   1.242 -	}
   1.243 +    tmp_ptr = (char *)xc_map_foreign_batch(xc_handle, dom,
   1.244 +    PROT_READ | PROT_WRITE, pfn_list, nr_pages);
   1.245 +    if ( NULL == tmp_ptr )
   1.246 +    {
   1.247 +        PERROR("Cannot get nvram data from GFW!\n");
   1.248 +        free(pfn_list);
   1.249 +        close(nvram_fd);
   1.250 +        return -1;
   1.251 +    }
   1.252  
   1.253 -	// calculate nvram data base addrees
   1.254 -	nvram_base_addr = (uint64_t)(tmp_ptr + offset);
   1.255 +    // calculate nvram data base addrees
   1.256 +    nvram_base_addr = (uint64_t)(tmp_ptr + offset);
   1.257  
   1.258 -	memcpy(buf, (void *)nvram_base_addr, NVRAM_SIZE);
   1.259 -	free(pfn_list);
   1.260 -	munmap(tmp_ptr, NVRAM_SIZE + PAGE_SIZE);
   1.261 +    memcpy(buf, (void *)nvram_base_addr, NVRAM_SIZE);
   1.262 +    free(pfn_list);
   1.263 +    munmap(tmp_ptr, NVRAM_SIZE + PAGE_SIZE);
   1.264  
   1.265 -	lseek(nvram_fd, 0, SEEK_SET);
   1.266 -	if ( write(nvram_fd, buf, NVRAM_SIZE) != NVRAM_SIZE )
   1.267 -	{
   1.268 -		PERROR("Save to nvram fail!\n");
   1.269 -		return -1;
   1.270 -	}
   1.271 +    lseek(nvram_fd, 0, SEEK_SET);
   1.272 +    if ( write(nvram_fd, buf, NVRAM_SIZE) != NVRAM_SIZE )
   1.273 +    {
   1.274 +        PERROR("Save to nvram fail!\n");
   1.275 +        return -1;
   1.276 +    }
   1.277  
   1.278 -	close(nvram_fd);
   1.279 +    close(nvram_fd);
   1.280  
   1.281 -	DPRINTF("Nvram save successful!\n");
   1.282 +    DPRINTF("Nvram save successful!\n");
   1.283  
   1.284 -	return 0;
   1.285 +    return 0;
   1.286  }
   1.287  
   1.288  int xc_ia64_save_to_nvram(int xc_handle, uint32_t dom) 
   1.289  {
   1.290 -	uint64_t nvram_fd = 0;
   1.291 -	xc_get_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, &nvram_fd);
   1.292 +    uint64_t nvram_fd = 0;
   1.293 +    xc_get_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, &nvram_fd);
   1.294  
   1.295 -	if ( !IS_VALID_NVRAM_FD(nvram_fd) )
   1.296 -	{
   1.297 -		PERROR("Nvram not be initialized. Nvram save fail!\n");
   1.298 -		return -1;
   1.299 -	}
   1.300 -	return copy_from_GFW_to_nvram(xc_handle, dom, (int)nvram_fd);	
   1.301 +    if ( !IS_VALID_NVRAM_FD(nvram_fd) )
   1.302 +    {
   1.303 +        PERROR("Nvram not be initialized. Nvram save fail!\n");
   1.304 +        return -1;
   1.305 +    }
   1.306 +    return copy_from_GFW_to_nvram(xc_handle, dom, (int)nvram_fd);	
   1.307  }
   1.308  
   1.309  #define NVRAM_FILE_PATH	"/usr/lib/xen/boot/nvram_"
   1.310  int xc_ia64_nvram_init(int xc_handle, char *dom_name, uint32_t dom)
   1.311  {
   1.312 -	int file_path_len = strlen(NVRAM_FILE_PATH);
   1.313 -	uint64_t nvram_fd = 0;
   1.314 -	char nvram_path[100] = {0};
   1.315 +    int file_path_len = strlen(NVRAM_FILE_PATH);
   1.316 +    uint64_t nvram_fd = 0;
   1.317 +    char nvram_path[100] = {0};
   1.318  
   1.319 -	strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
   1.320 -	if ( file_path_len + strlen(dom_name) + 1 > sizeof(nvram_path) )
   1.321 -	{
   1.322 -		PERROR("Nvram file path is too long!\n");
   1.323 -		return -1;
   1.324 -	}
   1.325 -	strcpy(nvram_path + file_path_len, dom_name);
   1.326 +    strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
   1.327 +    if ( file_path_len + strlen(dom_name) + 1 > sizeof(nvram_path) )
   1.328 +    {
   1.329 +        PERROR("Nvram file path is too long!\n");
   1.330 +        return -1;
   1.331 +    }
   1.332 +    strcpy(nvram_path + file_path_len, dom_name);
   1.333  
   1.334 -	nvram_fd = nvram_init(nvram_path);
   1.335 -	if ( nvram_fd == (uint64_t)(-1) )
   1.336 -	{
   1.337 -		xc_set_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, 0);
   1.338 -		return -1;
   1.339 -	}
   1.340 +    nvram_fd = nvram_init(nvram_path);
   1.341 +    if ( nvram_fd == (uint64_t)(-1) )
   1.342 +    {
   1.343 +        xc_set_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, 0);
   1.344 +        return -1;
   1.345 +    }
   1.346  
   1.347 -	xc_set_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, nvram_fd);
   1.348 -	return 0; 
   1.349 +    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_NVRAM_FD, nvram_fd);
   1.350 +    return 0; 
   1.351  }
   1.352  
   1.353  #define GFW_PAGES (GFW_SIZE >> PAGE_SHIFT)