aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32F1xx/GPT/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'testhal/STM32F1xx/GPT/main.c')
0 files changed, 0 insertions, 0 deletions
'#n35'>35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
/******************************************************************************
 *
 * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
 *                    VA Linux Systems Japan K.K.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*
 *  Xen domain firmware emulation support
 *  Copyright (C) 2004 Hewlett-Packard Co.
 *       Dan Magenheimer (dan.magenheimer@hp.com)
 */

#ifdef __XEN__
#include <xen/sched.h>
#include <asm/dom_fw_utils.h>
#include <linux/sort.h>
#define xen_ia64_dom_fw_map(d, mpaddr)  domain_mpa_to_imva((d), (mpaddr))
#define xen_ia64_dom_fw_unmap(d, vaddr)  do { } while (0)
#else
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <inttypes.h>

#include <xen/arch-ia64.h>

#include "xg_private.h"
#include "xc_dom.h"
#include "ia64/xc_dom_ia64_util.h"
#endif

#include <asm/dom_fw.h>
#include <asm/dom_fw_domu.h>

void efi_systable_init_domu(struct fw_tables *tables)
{
	int i = 1;

	printk(XENLOG_GUEST XENLOG_INFO "DomainU EFI build up:");

	tables->efi_tables[i].guid = ACPI_20_TABLE_GUID;
	tables->efi_tables[i].table = FW_ACPI_BASE_PADDR;
	printk(" ACPI 2.0=0x%lx", tables->efi_tables[i].table);
	i++;
	printk("\n");
	BUG_ON(i > NUM_EFI_SYS_TABLES);
}

int
complete_domu_memmap(domain_t * d,
		     struct fw_tables *tables,
		     unsigned long maxmem,
		     unsigned long memmap_info_pfn,
		     unsigned long memmap_info_num_pages)
{
	efi_memory_desc_t *md;
	int create_memmap = 0;
	xen_ia64_memmap_info_t *memmap_info;
	unsigned long memmap_info_size;
	unsigned long paddr_start;
	unsigned long paddr_end;
	void *p;
	void *memmap_start;
	void *memmap_end;

	if (memmap_info_pfn == 0 || memmap_info_num_pages == 0) {
		/* old domain builder which doesn't setup
		 * memory map. create it for compatibility */
		memmap_info_pfn = (maxmem >> PAGE_SHIFT) - 1;
		memmap_info_num_pages = 1;
		create_memmap = 1;
	}

	memmap_info_size = memmap_info_num_pages << PAGE_SHIFT;
	paddr_start = memmap_info_pfn << PAGE_SHIFT;
	/* 3 = start info page, xenstore page and console page */
	paddr_end = paddr_start + memmap_info_size + 3 * PAGE_SIZE;
	memmap_info = xen_ia64_dom_fw_map(d, paddr_start);

	if (memmap_info->efi_memmap_size == 0) {
		create_memmap = 1;
	} else if (memmap_info->efi_memdesc_size != sizeof(md[0]) ||
		   memmap_info->efi_memdesc_version !=
		   EFI_MEMORY_DESCRIPTOR_VERSION) {
		printk(XENLOG_WARNING
		       "%s: Warning: unknown memory map "
		       "memmap size %" PRIu64 " "
		       "memdesc size %" PRIu64 " "
		       "version %" PRIu32 "\n",
		       __func__,
		       memmap_info->efi_memmap_size,
		       memmap_info->efi_memdesc_size,
		       memmap_info->efi_memdesc_version);
		create_memmap = 1;
	} else if (memmap_info_size < memmap_info->efi_memmap_size) {
		printk(XENLOG_WARNING
		       "%s: Warning: too short memmap info size %" PRIu64 "\n",
		       __func__, memmap_info_size);
		xen_ia64_dom_fw_unmap(d, memmap_info);
		return -EINVAL;
	} else if (memmap_info->efi_memmap_size >
		   PAGE_SIZE - sizeof(*memmap_info)) {
		/*
		 * curently memmap spanning more than single page isn't
		 * supported.
		 */
		printk(XENLOG_WARNING
		       "%s: Warning: too large efi_memmap_size %" PRIu64 "\n",
		       __func__, memmap_info->efi_memmap_size);
		xen_ia64_dom_fw_unmap(d, memmap_info);
		return -ENOSYS;
	}

	if (create_memmap) {
		/*
		 * old domain builder which doesn't setup
		 * memory map. create it for compatibility
		 */
		memmap_info->efi_memdesc_size = sizeof(md[0]);
		memmap_info->efi_memdesc_version =
		    EFI_MEMORY_DESCRIPTOR_VERSION;
		memmap_info->efi_memmap_size = 1 * sizeof(md[0]);

		md = (efi_memory_desc_t *) & memmap_info->memdesc;
		md->type = EFI_CONVENTIONAL_MEMORY;
		md->pad = 0;
		md->phys_addr = 0;
		md->virt_addr = 0;
		md->num_pages = maxmem >> EFI_PAGE_SHIFT;
		md->attribute = EFI_MEMORY_WB;
	}

	memmap_start = &memmap_info->memdesc;
	memmap_end = memmap_start + memmap_info->efi_memmap_size;

	/* XXX Currently the table must be in a single page. */
	if ((unsigned long)memmap_end > (unsigned long)memmap_info + PAGE_SIZE) {
		xen_ia64_dom_fw_unmap(d, memmap_info);
		return -EINVAL;
	}

	/* sort it bofore use
	 * XXX: this is created by user space domain builder so that
	 * we should check its integrity */
	sort(&memmap_info->memdesc,
	     memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size,
	     memmap_info->efi_memdesc_size, efi_mdt_cmp, NULL);

	for (p = memmap_start; p < memmap_end;
	     p += memmap_info->efi_memdesc_size) {
		unsigned long start;
		unsigned long end;

		md = p;
		start = md->phys_addr;
		end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);

		if (start < tables->fw_end_paddr)
			start = tables->fw_end_paddr;
		if (end <= start)
			continue;

		/* exclude [paddr_start, paddr_end) */
		if (paddr_end <= start || end <= paddr_start) {
			xen_ia64_efi_make_md(&tables->
					     efi_memmap[tables->num_mds],
					     EFI_CONVENTIONAL_MEMORY,
					     EFI_MEMORY_WB, start, end);
			tables->num_mds++;
		} else if (paddr_start <= start && paddr_end < end) {
			xen_ia64_efi_make_md(&tables->
					     efi_memmap[tables->num_mds],
					     EFI_CONVENTIONAL_MEMORY,
					     EFI_MEMORY_WB, paddr_end, end);
			tables->num_mds++;
		} else if (start < paddr_start && end <= paddr_end) {
			xen_ia64_efi_make_md(&tables->
					     efi_memmap[tables->num_mds],
					     EFI_CONVENTIONAL_MEMORY,
					     EFI_MEMORY_WB, start, paddr_start);
			tables->num_mds++;
		} else {
			xen_ia64_efi_make_md(&tables->
					     efi_memmap[tables->num_mds],
					     EFI_CONVENTIONAL_MEMORY,
					     EFI_MEMORY_WB, start, paddr_start);
			tables->num_mds++;
			xen_ia64_efi_make_md(&tables->
					     efi_memmap[tables->num_mds],
					     EFI_CONVENTIONAL_MEMORY,
					     EFI_MEMORY_WB, paddr_end, end);
			tables->num_mds++;
		}
	}

	/* memmap info page. */
	xen_ia64_efi_make_md(&tables->efi_memmap[tables->num_mds],
			     EFI_RUNTIME_SERVICES_DATA, EFI_MEMORY_WB,
			     paddr_start, paddr_end);
	tables->num_mds++;

	/* Create an entry for IO ports.  */
	xen_ia64_efi_make_md(&tables->efi_memmap[tables->num_mds],
			     EFI_MEMORY_MAPPED_IO_PORT_SPACE, EFI_MEMORY_UC,
			     IO_PORTS_PADDR, IO_PORTS_PADDR + IO_PORTS_SIZE);
	tables->num_mds++;

	sort(tables->efi_memmap, tables->num_mds, sizeof(efi_memory_desc_t),
	     efi_mdt_cmp, NULL);

	xen_ia64_dom_fw_unmap(d, memmap_info);
	return tables->num_mds;
}

/*
 * Local variables:
 * mode: C
 * c-set-style: "linux"
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 */