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

📄 prom_init.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* Search all nodes looking for PHBs. */	for (node = 0; prom_next_node(&node); ) {		compatible[0] = 0;		type[0] = 0;		model[0] = 0;		prom_getprop(node, "compatible",			     compatible, sizeof(compatible));		prom_getprop(node, "device_type", type, sizeof(type));		prom_getprop(node, "model", model, sizeof(model));		if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))			continue;		/* Keep the old logic in tack to avoid regression. */		if (compatible[0] != 0) {			if ((strstr(compatible, RELOC("python")) == NULL) &&			    (strstr(compatible, RELOC("Speedwagon")) == NULL) &&			    (strstr(compatible, RELOC("Winnipeg")) == NULL))				continue;		} else if (model[0] != 0) {			if ((strstr(model, RELOC("ython")) == NULL) &&			    (strstr(model, RELOC("peedwagon")) == NULL) &&			    (strstr(model, RELOC("innipeg")) == NULL))				continue;		}		if (prom_getprop(node, "tce-table-minalign", &minalign,				 sizeof(minalign)) == PROM_ERROR)			minalign = 0;		if (prom_getprop(node, "tce-table-minsize", &minsize,				 sizeof(minsize)) == PROM_ERROR)			minsize = 4UL << 20;		/*		 * Even though we read what OF wants, we just set the table		 * size to 4 MB.  This is enough to map 2GB of PCI DMA space.		 * By doing this, we avoid the pitfalls of trying to DMA to		 * MMIO space and the DMA alias hole.		 *		 * On POWER4, firmware sets the TCE region by assuming		 * each TCE table is 8MB. Using this memory for anything		 * else will impact performance, so we always allocate 8MB.		 * Anton		 */		if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))			minsize = 8UL << 20;		else			minsize = 4UL << 20;		/* Align to the greater of the align or size */		align = max(minalign, minsize);		base = alloc_down(minsize, align, 1);		if (base == 0)			prom_panic("ERROR, cannot find space for TCE table.\n");		if (base < local_alloc_bottom)			local_alloc_bottom = base;		/* It seems OF doesn't null-terminate the path :-( */		memset(path, 0, sizeof(path));		/* Call OF to setup the TCE hardware */		if (call_prom("package-to-path", 3, 1, node,			      path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {			prom_printf("package-to-path failed\n");		}		/* Save away the TCE table attributes for later use. */		prom_setprop(node, path, "linux,tce-base", &base, sizeof(base));		prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize));		prom_debug("TCE table: %s\n", path);		prom_debug("\tnode = 0x%x\n", node);		prom_debug("\tbase = 0x%x\n", base);		prom_debug("\tsize = 0x%x\n", minsize);		/* Initialize the table to have a one-to-one mapping		 * over the allocated size.		 */		tce_entryp = (unsigned long *)base;		for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {			tce_entry = (i << PAGE_SHIFT);			tce_entry |= 0x3;			*tce_entryp = tce_entry;		}		prom_printf("opening PHB %s", path);		phb_node = call_prom("open", 1, 1, path);		if (phb_node == 0)			prom_printf("... failed\n");		else			prom_printf("... done\n");		call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),			  phb_node, -1, minsize,			  (u32) base, (u32) (base >> 32));		call_prom("close", 1, 0, phb_node);	}	reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);	if (RELOC(prom_memory_limit)) {		/*		 * We align the start to a 16MB boundary so we can map		 * the TCE area using large pages if possible.		 * The end should be the top of RAM so no need to align it.		 */		RELOC(prom_tce_alloc_start) = _ALIGN_DOWN(local_alloc_bottom,							  0x1000000);		RELOC(prom_tce_alloc_end) = local_alloc_top;	}	/* Flag the first invalid entry */	prom_debug("ending prom_initialize_tce_table\n");}#endif/* * With CHRP SMP we need to use the OF to start the other processors. * We can't wait until smp_boot_cpus (the OF is trashed by then) * so we have to put the processors into a holding pattern controlled * by the kernel (not OF) before we destroy the OF. * * This uses a chunk of low memory, puts some holding pattern * code there and sends the other processors off to there until * smp_boot_cpus tells them to do something.  The holding pattern * checks that address until its cpu # is there, when it is that * cpu jumps to __secondary_start().  smp_boot_cpus() takes care * of setting those values. * * We also use physical address 0x4 here to tell when a cpu * is in its holding pattern code. * * -- Cort */extern void __secondary_hold(void);extern unsigned long __secondary_hold_spinloop;extern unsigned long __secondary_hold_acknowledge;/* * We want to reference the copy of __secondary_hold_* in the * 0 - 0x100 address range */#define LOW_ADDR(x)	(((unsigned long) &(x)) & 0xff)static void __init prom_hold_cpus(void){	unsigned long i;	unsigned int reg;	phandle node;	char type[64];	int cpuid = 0;	unsigned int interrupt_server[MAX_CPU_THREADS];	unsigned int cpu_threads, hw_cpu_num;	int propsize;	struct prom_t *_prom = &RELOC(prom);	unsigned long *spinloop		= (void *) LOW_ADDR(__secondary_hold_spinloop);	unsigned long *acknowledge		= (void *) LOW_ADDR(__secondary_hold_acknowledge);#ifdef CONFIG_PPC64	/* __secondary_hold is actually a descriptor, not the text address */	unsigned long secondary_hold		= __pa(*PTRRELOC((unsigned long *)__secondary_hold));#else	unsigned long secondary_hold = LOW_ADDR(__secondary_hold);#endif	prom_debug("prom_hold_cpus: start...\n");	prom_debug("    1) spinloop       = 0x%x\n", (unsigned long)spinloop);	prom_debug("    1) *spinloop      = 0x%x\n", *spinloop);	prom_debug("    1) acknowledge    = 0x%x\n",		   (unsigned long)acknowledge);	prom_debug("    1) *acknowledge   = 0x%x\n", *acknowledge);	prom_debug("    1) secondary_hold = 0x%x\n", secondary_hold);	/* Set the common spinloop variable, so all of the secondary cpus	 * will block when they are awakened from their OF spinloop.	 * This must occur for both SMP and non SMP kernels, since OF will	 * be trashed when we move the kernel.	 */	*spinloop = 0;#ifdef CONFIG_HMT	for (i = 0; i < NR_CPUS; i++)		RELOC(hmt_thread_data)[i].pir = 0xdeadbeef;#endif	/* look for cpus */	for (node = 0; prom_next_node(&node); ) {		type[0] = 0;		prom_getprop(node, "device_type", type, sizeof(type));		if (strcmp(type, RELOC("cpu")) != 0)			continue;		/* Skip non-configured cpus. */		if (prom_getprop(node, "status", type, sizeof(type)) > 0)			if (strcmp(type, RELOC("okay")) != 0)				continue;		reg = -1;		prom_getprop(node, "reg", &reg, sizeof(reg));		prom_debug("\ncpuid        = 0x%x\n", cpuid);		prom_debug("cpu hw idx   = 0x%x\n", reg);		/* Init the acknowledge var which will be reset by		 * the secondary cpu when it awakens from its OF		 * spinloop.		 */		*acknowledge = (unsigned long)-1;		propsize = prom_getprop(node, "ibm,ppc-interrupt-server#s",					&interrupt_server,					sizeof(interrupt_server));		if (propsize < 0) {			/* no property.  old hardware has no SMT */			cpu_threads = 1;			interrupt_server[0] = reg; /* fake it with phys id */		} else {			/* We have a threaded processor */			cpu_threads = propsize / sizeof(u32);			if (cpu_threads > MAX_CPU_THREADS) {				prom_printf("SMT: too many threads!\n"					    "SMT: found %x, max is %x\n",					    cpu_threads, MAX_CPU_THREADS);				cpu_threads = 1; /* ToDo: panic? */			}		}		hw_cpu_num = interrupt_server[0];		if (hw_cpu_num != _prom->cpu) {			/* Primary Thread of non-boot cpu */			prom_printf("%x : starting cpu hw idx %x... ", cpuid, reg);			call_prom("start-cpu", 3, 0, node,				  secondary_hold, reg);			for (i = 0; (i < 100000000) && 			     (*acknowledge == ((unsigned long)-1)); i++ )				mb();			if (*acknowledge == reg)				prom_printf("done\n");			else				prom_printf("failed: %x\n", *acknowledge);		}#ifdef CONFIG_SMP		else			prom_printf("%x : boot cpu     %x\n", cpuid, reg);#endif /* CONFIG_SMP */		/* Reserve cpu #s for secondary threads.   They start later. */		cpuid += cpu_threads;	}#ifdef CONFIG_HMT	/* Only enable HMT on processors that provide support. */	if (__is_processor(PV_PULSAR) || 	    __is_processor(PV_ICESTAR) ||	    __is_processor(PV_SSTAR)) {		prom_printf("    starting secondary threads\n");		for (i = 0; i < NR_CPUS; i += 2) {			if (!cpu_online(i))				continue;			if (i == 0) {				unsigned long pir = mfspr(SPRN_PIR);				if (__is_processor(PV_PULSAR)) {					RELOC(hmt_thread_data)[i].pir = 						pir & 0x1f;				} else {					RELOC(hmt_thread_data)[i].pir = 						pir & 0x3ff;				}			}		}	} else {		prom_printf("Processor is not HMT capable\n");	}#endif	if (cpuid > NR_CPUS)		prom_printf("WARNING: maximum CPUs (" __stringify(NR_CPUS)			    ") exceeded: ignoring extras\n");	prom_debug("prom_hold_cpus: end...\n");}static void __init prom_init_client_services(unsigned long pp){	struct prom_t *_prom = &RELOC(prom);	/* Get a handle to the prom entry point before anything else */	RELOC(prom_entry) = pp;	/* get a handle for the stdout device */	_prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));	if (!PHANDLE_VALID(_prom->chosen))		prom_panic("cannot find chosen"); /* msg won't be printed :( */	/* get device tree root */	_prom->root = call_prom("finddevice", 1, 1, ADDR("/"));	if (!PHANDLE_VALID(_prom->root))		prom_panic("cannot find device tree root"); /* msg won't be printed :( */	_prom->mmumap = 0;}#ifdef CONFIG_PPC32/* * For really old powermacs, we need to map things we claim. * For that, we need the ihandle of the mmu. * Also, on the longtrail, we need to work around other bugs. */static void __init prom_find_mmu(void){	struct prom_t *_prom = &RELOC(prom);	phandle oprom;	char version[64];	oprom = call_prom("finddevice", 1, 1, ADDR("/openprom"));	if (!PHANDLE_VALID(oprom))		return;	if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0)		return;	version[sizeof(version) - 1] = 0;	/* XXX might need to add other versions here */	if (strcmp(version, "Open Firmware, 1.0.5") == 0)		of_workarounds = OF_WA_CLAIM;	else if (strncmp(version, "FirmWorks,3.", 12) == 0) {		of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL;		call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim");	} else		return;	_prom->memory = call_prom("open", 1, 1, ADDR("/memory"));	prom_getprop(_prom->chosen, "mmu", &_prom->mmumap,		     sizeof(_prom->mmumap));	if (!IHANDLE_VALID(_prom->memory) || !IHANDLE_VALID(_prom->mmumap))		of_workarounds &= ~OF_WA_CLAIM;		/* hmmm */}#else#define prom_find_mmu()#endifstatic void __init prom_init_stdout(void){	struct prom_t *_prom = &RELOC(prom);	char *path = RELOC(of_stdout_device);	char type[16];	u32 val;	if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)		prom_panic("cannot find stdout");	_prom->stdout = val;	/* Get the full OF pathname of the stdout device */	memset(path, 0, 256);	call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);	val = call_prom("instance-to-package", 1, 1, _prom->stdout);	prom_setprop(_prom->chosen, "/chosen", "linux,stdout-package",		     &val, sizeof(val));	prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));	prom_setprop(_prom->chosen, "/chosen", "linux,stdout-path",		     path, strlen(path) + 1);	/* If it's a display, note it */	memset(type, 0, sizeof(type));	prom_getprop(val, "device_type", type, sizeof(type));	if (strcmp(type, RELOC("display")) == 0)		prom_setprop(val, path, "linux,boot-display", NULL, 0);}static void __init prom_close_stdin(void){	struct prom_t *_prom = &RELOC(prom);	ihandle val;	if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)		call_prom("close", 1, 0, val);}static int __init prom_find_machine_type(void){	struct prom_t *_prom = &RELOC(prom);	char compat[256];	int len, i = 0;#ifdef CONFIG_PPC64	phandle rtas;#endif	len = prom_getprop(_prom->root, "compatible",			   compat, sizeof(compat)-1);	if (len > 0) {		compat[len] = 0;		while (i < len) {			char *p = &compat[i];			int sl = strlen(p);			if (sl == 0)				break;			if (strstr(p, RELOC("Power Macintosh")) ||			    strstr(p, RELOC("MacRISC")))				return PLATFORM_POWERMAC;#ifdef CONFIG_PPC64			if (strstr(p, RELOC("Momentum,Maple")))				return PLATFORM_MAPLE;#endif			i += sl + 1;		}	}#ifdef CONFIG_PPC64	/* Default to pSeries. We need to know if we are running LPAR */	rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));	if (PHANDLE_VALID(rtas)) {		int x = prom_getproplen(rtas, "ibm,hypertas-functions");		if (x != PROM_ERROR) {			prom_printf("Hypertas detected, assuming LPAR !\n");			return PLATFORM_PSERIES_LPAR;		}	}	return PLATFORM_PSERIES;#else	return PLATFORM_CHRP;#endif}static int __init prom_set_color(ihandle ih, int i, int r, int g, int b){	return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);}/* * If we have a display that we don't know how to drive, * we will want to try to execute OF's open method for it * later.  However, OF will probably fall over if we do that * we've taken over the MMU. * So we check whether we will need to open the display, * and if so, open it now. */static void __init prom_check_displays(void){	char type[16], *path;	phandle node;	ihandle ih;	int i;	static unsigned char default_colors[] = {		0x00, 0x00, 0x00,		0x00, 0x00, 0xaa,		0x00, 0xaa, 0x00,		0x00, 0xaa, 0xaa,		0xaa, 0x00, 0x00,		0xaa, 0x00, 0xaa,		0xaa, 0xaa, 0x00,		0xaa, 0xaa, 0xaa,		0x55, 0x55, 0x55,		0x55, 0x55, 0xff,		0x55, 0xff, 0x55,		0x55, 0xff, 0xff,		0xff, 0x55, 0x55,		0xff, 0x55, 0xff,		0xff, 0xff, 0x55,		0xff, 0xff, 0xff	};	const unsigned char *clut;	prom_printf("Looking for displays\n");	for (node = 0; prom_next_node(&node); ) {		memset(type, 0, sizeof(type));		prom_getprop(node, "device_type", type, sizeof(type));		if (strcmp(type, RELOC("display")) != 0)			continue;		/* It seems OF doesn't null-terminate the path :-( */		path = RELOC(prom_scratch);		memset(path, 0, PROM_SCRATCH_SIZE);		/*		 * leave some room at the end of the path for appending extra		 * arguments		 */		if (call_prom("package-to-path", 3, 1, node, path,			      PROM_SCRATCH_SIZE-10) == PROM_ERROR)			continue;		prom_printf("found display   : %s, opening ... ", path);				ih = call_prom("open", 1, 1, path);		if (ih == 0) {			prom_printf("failed\n");			continue;		}		/* Success */		prom_printf("done\n");		prom_setprop(node, path, "linux,opened", NULL, 0);		/* Setup a usable color table when the appropriate		 * method is available. Should update this to set-colors */		clut = RELOC(default_colors);		for (i = 0; i < 32; i++, clut += 3)			if (prom_set_color(ih, i, clut[0], clut[1],					   clut[2]) != 0)				break;#ifdef CONFIG_LOGO_LINUX_CLUT224		clut = PTRRELOC(RELOC(logo_linux_clut224.clut));		for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)			if (prom_set_color(ih, i + 32, clut[0], clut[1],					   clut[2]) != 0)				break;#endif /* CONFIG_LOGO_LINUX_CLUT224 */	}}/* Return (relocated) pointer to this much memory: moves initrd if reqd. */static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,			      unsigned long needed, unsigned long align){	void *ret;	*mem_start = _ALIGN(*mem_start, align);	while ((*mem_start + needed) > *mem_end) {		unsigned long room, chunk;		prom_debug("Chunk exhausted, claiming more at %x...\n",			   RELOC(alloc_bottom));		room = RELOC(alloc_top) - RELOC(alloc_bottom);		if (room > DEVTREE_CHUNK_SIZE)			room = DEVTREE_CHUNK_SIZE;		if (room < PAGE_SIZE)			prom_panic("No memory for flatten_device_tree (no room)");		chunk = alloc_up(room, 0);		if (chunk == 0)			prom_panic("No memory for flatten_device_tree (claim failed)");		*mem_end = RELOC(alloc_top);	}	ret = (void *)*mem_start;	*mem_start += needed;	return ret;}#define dt_push_token(token, mem_start, mem_end) \	do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)static unsigned long __init dt_find_string(char *str){	char *s, *os;

⌨️ 快捷键说明

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