⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prom_init.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 4 页
字号:
 * Early parsing of the command line passed to the kernel, used for * "mem=x" and the options that affect the iommu */static void __init early_cmdline_parse(void){	struct prom_t *_prom = &RELOC(prom);	char *opt, *p;	int l = 0;	RELOC(prom_cmd_line[0]) = 0;	p = RELOC(prom_cmd_line);	if ((long)_prom->chosen > 0)		l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1);#ifdef CONFIG_CMDLINE	if (l == 0) /* dbl check */		strlcpy(RELOC(prom_cmd_line),			RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));#endif /* CONFIG_CMDLINE */	prom_printf("command line: %s\n", RELOC(prom_cmd_line));#ifdef CONFIG_PPC64	opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));	if (opt) {		prom_printf("iommu opt is: %s\n", opt);		opt += 6;		while (*opt && *opt == ' ')			opt++;		if (!strncmp(opt, RELOC("off"), 3))			RELOC(ppc64_iommu_off) = 1;		else if (!strncmp(opt, RELOC("force"), 5))			RELOC(iommu_force_on) = 1;	}#endif	opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));	if (opt) {		opt += 4;		RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);#ifdef CONFIG_PPC64		/* Align to 16 MB == size of ppc64 large page */		RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);#endif	}}#ifdef CONFIG_PPC_PSERIES/* * To tell the firmware what our capabilities are, we have to pass * it a fake 32-bit ELF header containing a couple of PT_NOTE sections * that contain structures that contain the actual values. */static struct fake_elf {	Elf32_Ehdr	elfhdr;	Elf32_Phdr	phdr[2];	struct chrpnote {		u32	namesz;		u32	descsz;		u32	type;		char	name[8];	/* "PowerPC" */		struct chrpdesc {			u32	real_mode;			u32	real_base;			u32	real_size;			u32	virt_base;			u32	virt_size;			u32	load_base;		} chrpdesc;	} chrpnote;	struct rpanote {		u32	namesz;		u32	descsz;		u32	type;		char	name[24];	/* "IBM,RPA-Client-Config" */		struct rpadesc {			u32	lpar_affinity;			u32	min_rmo_size;			u32	min_rmo_percent;			u32	max_pft_size;			u32	splpar;			u32	min_load;			u32	new_mem_def;			u32	ignore_me;		} rpadesc;	} rpanote;} fake_elf = {	.elfhdr = {		.e_ident = { 0x7f, 'E', 'L', 'F',			     ELFCLASS32, ELFDATA2MSB, EV_CURRENT },		.e_type = ET_EXEC,	/* yeah right */		.e_machine = EM_PPC,		.e_version = EV_CURRENT,		.e_phoff = offsetof(struct fake_elf, phdr),		.e_phentsize = sizeof(Elf32_Phdr),		.e_phnum = 2	},	.phdr = {		[0] = {			.p_type = PT_NOTE,			.p_offset = offsetof(struct fake_elf, chrpnote),			.p_filesz = sizeof(struct chrpnote)		}, [1] = {			.p_type = PT_NOTE,			.p_offset = offsetof(struct fake_elf, rpanote),			.p_filesz = sizeof(struct rpanote)		}	},	.chrpnote = {		.namesz = sizeof("PowerPC"),		.descsz = sizeof(struct chrpdesc),		.type = 0x1275,		.name = "PowerPC",		.chrpdesc = {			.real_mode = ~0U,	/* ~0 means "don't care" */			.real_base = ~0U,			.real_size = ~0U,			.virt_base = ~0U,			.virt_size = ~0U,			.load_base = ~0U		},	},	.rpanote = {		.namesz = sizeof("IBM,RPA-Client-Config"),		.descsz = sizeof(struct rpadesc),		.type = 0x12759999,		.name = "IBM,RPA-Client-Config",		.rpadesc = {			.lpar_affinity = 0,			.min_rmo_size = 64,	/* in megabytes */			.min_rmo_percent = 0,			.max_pft_size = 48,	/* 2^48 bytes max PFT size */			.splpar = 1,			.min_load = ~0U,			.new_mem_def = 0		}	}};static void __init prom_send_capabilities(void){	ihandle elfloader;	elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader"));	if (elfloader == 0) {		prom_printf("couldn't open /packages/elf-loader\n");		return;	}	call_prom("call-method", 3, 1, ADDR("process-elf-header"),			elfloader, ADDR(&fake_elf));	call_prom("close", 1, 0, elfloader);}#endif/* * Memory allocation strategy... our layout is normally: * *  at 14Mb or more we have vmlinux, then a gap and initrd.  In some *  rare cases, initrd might end up being before the kernel though. *  We assume this won't override the final kernel at 0, we have no *  provision to handle that in this version, but it should hopefully *  never happen. * *  alloc_top is set to the top of RMO, eventually shrink down if the *  TCEs overlap * *  alloc_bottom is set to the top of kernel/initrd * *  from there, allocations are done this way : rtas is allocated *  topmost, and the device-tree is allocated from the bottom. We try *  to grow the device-tree allocation as we progress. If we can't, *  then we fail, we don't currently have a facility to restart *  elsewhere, but that shouldn't be necessary. * *  Note that calls to reserve_mem have to be done explicitly, memory *  allocated with either alloc_up or alloc_down isn't automatically *  reserved. *//* * Allocates memory in the RMO upward from the kernel/initrd * * When align is 0, this is a special case, it means to allocate in place * at the current location of alloc_bottom or fail (that is basically * extending the previous allocation). Used for the device-tree flattening */static unsigned long __init alloc_up(unsigned long size, unsigned long align){	unsigned long base = RELOC(alloc_bottom);	unsigned long addr = 0;	if (align)		base = _ALIGN_UP(base, align);	prom_debug("alloc_up(%x, %x)\n", size, align);	if (RELOC(ram_top) == 0)		prom_panic("alloc_up() called with mem not initialized\n");	if (align)		base = _ALIGN_UP(RELOC(alloc_bottom), align);	else		base = RELOC(alloc_bottom);	for(; (base + size) <= RELOC(alloc_top); 	    base = _ALIGN_UP(base + 0x100000, align)) {		prom_debug("    trying: 0x%x\n\r", base);		addr = (unsigned long)prom_claim(base, size, 0);		if (addr != PROM_ERROR && addr != 0)			break;		addr = 0;		if (align == 0)			break;	}	if (addr == 0)		return 0;	RELOC(alloc_bottom) = addr;	prom_debug(" -> %x\n", addr);	prom_debug("  alloc_bottom : %x\n", RELOC(alloc_bottom));	prom_debug("  alloc_top    : %x\n", RELOC(alloc_top));	prom_debug("  alloc_top_hi : %x\n", RELOC(alloc_top_high));	prom_debug("  rmo_top      : %x\n", RELOC(rmo_top));	prom_debug("  ram_top      : %x\n", RELOC(ram_top));	return addr;}/* * Allocates memory downward, either from top of RMO, or if highmem * is set, from the top of RAM.  Note that this one doesn't handle * failures.  It does claim memory if highmem is not set. */static unsigned long __init alloc_down(unsigned long size, unsigned long align,				       int highmem){	unsigned long base, addr = 0;	prom_debug("alloc_down(%x, %x, %s)\n", size, align,		   highmem ? RELOC("(high)") : RELOC("(low)"));	if (RELOC(ram_top) == 0)		prom_panic("alloc_down() called with mem not initialized\n");	if (highmem) {		/* Carve out storage for the TCE table. */		addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);		if (addr <= RELOC(alloc_bottom))			return 0;		/* Will we bump into the RMO ? If yes, check out that we		 * didn't overlap existing allocations there, if we did,		 * we are dead, we must be the first in town !		 */		if (addr < RELOC(rmo_top)) {			/* Good, we are first */			if (RELOC(alloc_top) == RELOC(rmo_top))				RELOC(alloc_top) = RELOC(rmo_top) = addr;			else				return 0;		}		RELOC(alloc_top_high) = addr;		goto bail;	}	base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);	for (; base > RELOC(alloc_bottom);	     base = _ALIGN_DOWN(base - 0x100000, align))  {		prom_debug("    trying: 0x%x\n\r", base);		addr = (unsigned long)prom_claim(base, size, 0);		if (addr != PROM_ERROR && addr != 0)			break;		addr = 0;	}	if (addr == 0)		return 0;	RELOC(alloc_top) = addr; bail:	prom_debug(" -> %x\n", addr);	prom_debug("  alloc_bottom : %x\n", RELOC(alloc_bottom));	prom_debug("  alloc_top    : %x\n", RELOC(alloc_top));	prom_debug("  alloc_top_hi : %x\n", RELOC(alloc_top_high));	prom_debug("  rmo_top      : %x\n", RELOC(rmo_top));	prom_debug("  ram_top      : %x\n", RELOC(ram_top));	return addr;}/* * Parse a "reg" cell */static unsigned long __init prom_next_cell(int s, cell_t **cellp){	cell_t *p = *cellp;	unsigned long r = 0;	/* Ignore more than 2 cells */	while (s > sizeof(unsigned long) / 4) {		p++;		s--;	}	r = *p++;#ifdef CONFIG_PPC64	if (s > 1) {		r <<= 32;		r |= *(p++);	}#endif	*cellp = p;	return r;}/* * Very dumb function for adding to the memory reserve list, but * we don't need anything smarter at this point * * XXX Eventually check for collisions.  They should NEVER happen. * If problems seem to show up, it would be a good start to track * them down. */static void reserve_mem(unsigned long base, unsigned long size){	unsigned long top = base + size;	unsigned long cnt = RELOC(mem_reserve_cnt);	if (size == 0)		return;	/* We need to always keep one empty entry so that we	 * have our terminator with "size" set to 0 since we are	 * dumb and just copy this entire array to the boot params	 */	base = _ALIGN_DOWN(base, PAGE_SIZE);	top = _ALIGN_UP(top, PAGE_SIZE);	size = top - base;	if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))		prom_panic("Memory reserve map exhausted !\n");	RELOC(mem_reserve_map)[cnt].base = base;	RELOC(mem_reserve_map)[cnt].size = size;	RELOC(mem_reserve_cnt) = cnt + 1;}/* * Initialize memory allocation mecanism, parse "memory" nodes and * obtain that way the top of memory and RMO to setup out local allocator */static void __init prom_init_mem(void){	phandle node;	char *path, type[64];	unsigned int plen;	cell_t *p, *endp;	struct prom_t *_prom = &RELOC(prom);	u32 rac, rsc;	/*	 * We iterate the memory nodes to find	 * 1) top of RMO (first node)	 * 2) top of memory	 */	rac = 2;	prom_getprop(_prom->root, "#address-cells", &rac, sizeof(rac));	rsc = 1;	prom_getprop(_prom->root, "#size-cells", &rsc, sizeof(rsc));	prom_debug("root_addr_cells: %x\n", (unsigned long) rac);	prom_debug("root_size_cells: %x\n", (unsigned long) rsc);	prom_debug("scanning memory:\n");	path = RELOC(prom_scratch);	for (node = 0; prom_next_node(&node); ) {		type[0] = 0;		prom_getprop(node, "device_type", type, sizeof(type));		if (type[0] == 0) {			/*			 * CHRP Longtrail machines have no device_type			 * on the memory node, so check the name instead...			 */			prom_getprop(node, "name", type, sizeof(type));		}		if (strcmp(type, RELOC("memory")))			continue;		plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));		if (plen > sizeof(regbuf)) {			prom_printf("memory node too large for buffer !\n");			plen = sizeof(regbuf);		}		p = RELOC(regbuf);		endp = p + (plen / sizeof(cell_t));#ifdef DEBUG_PROM		memset(path, 0, PROM_SCRATCH_SIZE);		call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);		prom_debug("  node %s :\n", path);#endif /* DEBUG_PROM */		while ((endp - p) >= (rac + rsc)) {			unsigned long base, size;			base = prom_next_cell(rac, &p);			size = prom_next_cell(rsc, &p);			if (size == 0)				continue;			prom_debug("    %x %x\n", base, size);			if (base == 0)				RELOC(rmo_top) = size;			if ((base + size) > RELOC(ram_top))				RELOC(ram_top) = base + size;		}	}	RELOC(alloc_bottom) = PAGE_ALIGN((unsigned long)&RELOC(_end) + 0x4000);	/* Check if we have an initrd after the kernel, if we do move our bottom	 * point to after it	 */	if (RELOC(prom_initrd_start)) {		if (RELOC(prom_initrd_end) > RELOC(alloc_bottom))			RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));	}	/*	 * If prom_memory_limit is set we reduce the upper limits *except* for	 * alloc_top_high. This must be the real top of RAM so we can put	 * TCE's up there.	 */	RELOC(alloc_top_high) = RELOC(ram_top);	if (RELOC(prom_memory_limit)) {		if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {			prom_printf("Ignoring mem=%x <= alloc_bottom.\n",				RELOC(prom_memory_limit));			RELOC(prom_memory_limit) = 0;		} else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {			prom_printf("Ignoring mem=%x >= ram_top.\n",				RELOC(prom_memory_limit));			RELOC(prom_memory_limit) = 0;		} else {			RELOC(ram_top) = RELOC(prom_memory_limit);			RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));		}	}	/*	 * Setup our top alloc point, that is top of RMO or top of	 * segment 0 when running non-LPAR.	 * Some RS64 machines have buggy firmware where claims up at	 * 1GB fail.  Cap at 768MB as a workaround.	 * Since 768MB is plenty of room, and we need to cap to something	 * reasonable on 32-bit, cap at 768MB on all machines.	 */	if (!RELOC(rmo_top))		RELOC(rmo_top) = RELOC(ram_top);	RELOC(rmo_top) = min(0x30000000ul, RELOC(rmo_top));	RELOC(alloc_top) = RELOC(rmo_top);	prom_printf("memory layout at init:\n");	prom_printf("  memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));	prom_printf("  alloc_bottom : %x\n", RELOC(alloc_bottom));	prom_printf("  alloc_top    : %x\n", RELOC(alloc_top));	prom_printf("  alloc_top_hi : %x\n", RELOC(alloc_top_high));	prom_printf("  rmo_top      : %x\n", RELOC(rmo_top));	prom_printf("  ram_top      : %x\n", RELOC(ram_top));}/* * Allocate room for and instantiate RTAS */static void __init prom_instantiate_rtas(void){	phandle rtas_node;	ihandle rtas_inst;	u32 base, entry = 0;	u32 size = 0;	prom_debug("prom_instantiate_rtas: start...\n");	rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas"));	prom_debug("rtas_node: %x\n", rtas_node);	if (!PHANDLE_VALID(rtas_node))		return;	prom_getprop(rtas_node, "rtas-size", &size, sizeof(size));	if (size == 0)		return;	base = alloc_down(size, PAGE_SIZE, 0);	if (base == 0) {		prom_printf("RTAS allocation failed !\n");		return;	}	rtas_inst = call_prom("open", 1, 1, ADDR("/rtas"));	if (!IHANDLE_VALID(rtas_inst)) {		prom_printf("opening rtas package failed (%x)\n", rtas_inst);		return;	}	prom_printf("instantiating rtas at 0x%x ...", base);	if (call_prom_ret("call-method", 3, 2, &entry,			  ADDR("instantiate-rtas"),			  rtas_inst, base) != 0	    || entry == 0) {		prom_printf(" failed\n");		return;	}	prom_printf(" done\n");	reserve_mem(base, size);	prom_setprop(rtas_node, "/rtas", "linux,rtas-base",		     &base, sizeof(base));	prom_setprop(rtas_node, "/rtas", "linux,rtas-entry",		     &entry, sizeof(entry));	prom_debug("rtas base     = 0x%x\n", base);	prom_debug("rtas entry    = 0x%x\n", entry);	prom_debug("rtas size     = 0x%x\n", (long)size);	prom_debug("prom_instantiate_rtas: end...\n");}#ifdef CONFIG_PPC64/* * Allocate room for and initialize TCE tables */static void __init prom_initialize_tce_table(void){	phandle node;	ihandle phb_node;	char compatible[64], type[64], model[64];	char *path = RELOC(prom_scratch);	u64 base, align;	u32 minalign, minsize;	u64 tce_entry, *tce_entryp;	u64 local_alloc_top, local_alloc_bottom;	u64 i;	if (RELOC(ppc64_iommu_off))		return;	prom_debug("starting prom_initialize_tce_table\n");	/* Cache current top of allocs so we reserve a single block */	local_alloc_top = RELOC(alloc_top_high);	local_alloc_bottom = local_alloc_top;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -