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

📄 prep_setup.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/arch/ppc/kernel/setup.c * *  Copyright (C) 1995  Linus Torvalds *  Adapted from 'alpha' version by Gary Thomas *  Modified by Cort Dougan (cort@cs.nmt.edu) *//* * bootup setup stuff.. */#include <linux/config.h>#include <linux/module.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/stddef.h>#include <linux/unistd.h>#include <linux/ptrace.h>#include <linux/malloc.h>#include <linux/user.h>#include <linux/a.out.h>#include <linux/tty.h>#include <linux/major.h>#include <linux/interrupt.h>#include <linux/reboot.h>#include <linux/init.h>#include <linux/blk.h>#include <linux/ioport.h>#include <linux/console.h>#include <linux/timex.h>#include <linux/pci.h>#include <linux/openpic.h>#include <linux/ide.h>#include <asm/init.h>#include <asm/mmu.h>#include <asm/processor.h>#include <asm/residual.h>#include <asm/io.h>#include <asm/pgtable.h>#include <asm/cache.h>#include <asm/dma.h>#include <asm/machdep.h>#include <asm/mk48t59.h>#include <asm/prep_nvram.h>#include <asm/raven.h>#include <asm/keyboard.h>#include <asm/time.h>#include "local_irq.h"#include "i8259.h"#include "open_pic.h"#if defined(CONFIG_SOUND) || defined(CONFIG_SOUND_MODULE)#include <../drivers/sound/sound_config.h>#include <../drivers/sound/dev_table.h>#endifunsigned char ucSystemType;unsigned char ucBoardRev;unsigned char ucBoardRevMaj, ucBoardRevMin;extern unsigned long mc146818_get_rtc_time(void);extern int mc146818_set_rtc_time(unsigned long nowtime);extern unsigned long mk48t59_get_rtc_time(void);extern int mk48t59_set_rtc_time(unsigned long nowtime);extern unsigned char prep_nvram_read_val(int addr);extern void prep_nvram_write_val(int addr,				 unsigned char val);extern unsigned char rs_nvram_read_val(int addr);extern void rs_nvram_write_val(int addr,				 unsigned char val);extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);extern int pckbd_getkeycode(unsigned int scancode);extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,			   char raw_mode);extern char pckbd_unexpected_up(unsigned char keycode);extern void pckbd_leds(unsigned char leds);extern void pckbd_init_hw(void);extern unsigned char pckbd_sysrq_xlate[128];extern void prep_setup_pci_ptrs(void);extern char saved_command_line[256];int _prep_type;#define cached_21	(((char *)(ppc_cached_irq_mask))[3])#define cached_A1	(((char *)(ppc_cached_irq_mask))[2])/* for the mac fs */kdev_t boot_dev;/* used in nasty hack for sound - see prep_setup_arch() -- Cort */long ppc_cs4232_dma, ppc_cs4232_dma2;unsigned long empty_zero_page[1024];extern PTE *Hash, *Hash_end;extern unsigned long Hash_size, Hash_mask;extern int probingmem;extern unsigned long loops_per_sec;#ifdef CONFIG_BLK_DEV_RAMextern int rd_doload;		/* 1 = load ramdisk, 0 = don't load */extern int rd_prompt;		/* 1 = prompt for ramdisk, 0 = don't prompt */extern int rd_image_start;	/* starting block # of image */#endif#ifdef CONFIG_VGA_CONSOLEunsigned long vgacon_remap_base;#endifint __prepprep_get_cpuinfo(char *buffer){	extern char *Motherboard_map_name;	int len, i;  #ifdef CONFIG_SMP#define CD(X)		(cpu_data[n].X)  #else#define CD(X) (X)#endif  	len = sprintf(buffer,"machine\t\t: PReP %s\n",Motherboard_map_name);		switch ( _prep_type )	{	case _PREP_IBM:		if ((*(unsigned char *)0x8000080c) & (1<<6))			len += sprintf(buffer+len,"Upgrade CPU\n");		len += sprintf(buffer+len,"L2\t\t: ");		if ((*(unsigned char *)0x8000080c) & (1<<7))		{			len += sprintf(buffer+len,"not present\n");			goto no_l2;		}		len += sprintf(buffer+len,"%sKb,",			       (((*(unsigned char *)0x8000080d)>>2)&1)?"512":"256");		len += sprintf(buffer+len,"%sync\n",			       ((*(unsigned char *)0x8000080d)>>7) ? "":"a");		break;	case _PREP_Motorola:		len += sprintf(buffer+len,"L2\t\t: ");		switch(*((unsigned char *)CACHECRBA) & L2CACHE_MASK)		{		case L2CACHE_512KB:			len += sprintf(buffer+len,"512Kb");			break;		case L2CACHE_256KB:			len += sprintf(buffer+len,"256Kb");			break;		case L2CACHE_1MB:			len += sprintf(buffer+len,"1MB");			break;		case L2CACHE_NONE:			len += sprintf(buffer+len,"none\n");			goto no_l2;			break;		default:			len += sprintf(buffer+len, "%x\n",				       *((unsigned char *)CACHECRBA));		}				len += sprintf(buffer+len,",parity %s",			       (*((unsigned char *)CACHECRBA) & L2CACHE_PARITY) ?			       "enabled" : "disabled");				len += sprintf(buffer+len, " SRAM:");				switch ( ((*((unsigned char *)CACHECRBA) & 0xf0) >> 4) & ~(0x3) )		{		case 1: len += sprintf(buffer+len,				       "synchronous,parity,flow-through\n");			break;		case 2: len += sprintf(buffer+len,"asynchronous,no parity\n");			break;		case 3: len += sprintf(buffer+len,"asynchronous,parity\n");			break;		default:len += sprintf(buffer+len,				       "synchronous,pipelined,no parity\n");			break;		}		break;	default:		break;	}		no_l2:		if ( res->ResidualLength == 0 )		return len;		/* print info about SIMMs */	len += sprintf(buffer+len,"simms\t\t: ");	for ( i = 0 ; (res->ActualNumMemories) && (i < MAX_MEMS) ; i++ )	{		if ( res->Memories[i].SIMMSize != 0 )			len += sprintf(buffer+len,"%d:%ldM ",i,				       (res->Memories[i].SIMMSize > 1024) ?				       res->Memories[i].SIMMSize>>20 :				       res->Memories[i].SIMMSize);	}	len += sprintf(buffer+len,"\n");	return len;}void __initprep_setup_arch(void){	extern char cmd_line[];	unsigned char reg;	unsigned char ucMothMemType;	unsigned char ucEquipPres1;	/* init to some ~sane value until calibrate_delay() runs */	loops_per_sec = 50000000;		/* Set up floppy in PS/2 mode */	outb(0x09, SIO_CONFIG_RA);	reg = inb(SIO_CONFIG_RD);	reg = (reg & 0x3F) | 0x40;	outb(reg, SIO_CONFIG_RD);	outb(reg, SIO_CONFIG_RD);	/* Have to write twice to change! */	/*	 * We need to set up the NvRAM access routines early as prep_init	 * has yet to be called	 */	ppc_md.nvram_read_val = prep_nvram_read_val;	ppc_md.nvram_write_val = prep_nvram_write_val;	/* we should determine this according to what we find! -- Cort */	switch ( _prep_type )	{	case _PREP_IBM:		/* Enable L2.  Assume we don't need to flush -- Cort*/		*(unsigned char *)(0x8000081c) |= 3;		ROOT_DEV = to_kdev_t(0x0301); /* hda1 */		break;	case _PREP_Motorola:		/* Enable L2.  Assume we don't need to flush -- Cort*/		*(unsigned char *)(0x8000081c) |= 3;		ROOT_DEV = to_kdev_t(0x0802); /* sda2 */		break;	case _PREP_Radstone:		ROOT_DEV = to_kdev_t(0x0801); /* sda1 */		/*		 * Determine system type		 */		ucMothMemType=inb(0x866);		ucEquipPres1=inb(0x80c);		ucSystemType=((ucMothMemType&0x03)<<1) |			     ((ucEquipPres1&0x80)>>7);		ucSystemType^=7;		/*		 * Determine board revision for use by		 * rev. specific code		 */		ucBoardRev=inb(0x854);		ucBoardRevMaj=ucBoardRev>>5;		ucBoardRevMin=ucBoardRev&0x1f;		/*		 * Most Radstone boards have memory mapped NvRAM		 */		if((ucSystemType==RS_SYS_TYPE_PPC1) && (ucBoardRevMaj<5))		{			ppc_md.nvram_read_val = prep_nvram_read_val;			ppc_md.nvram_write_val = prep_nvram_write_val;		}		else		{			ppc_md.nvram_read_val = rs_nvram_read_val;			ppc_md.nvram_write_val = rs_nvram_write_val;		}		break;	}      /* Read in NVRAM data */       init_prep_nvram();             /* if no bootargs, look in NVRAM */      if ( cmd_line[0] == '\0' ) {              char *bootargs;              bootargs = prep_nvram_get_var("bootargs");              if (bootargs != NULL) {                      strcpy(cmd_line, bootargs);                      /* again.. */                      strcpy(saved_command_line, cmd_line);              }      }	printk("Boot arguments: %s\n", cmd_line);	#ifdef CONFIG_SOUND_CS4232	/*	 * setup proper values for the cs4232 driver so we don't have	 * to recompile for the motorola or ibm workstations sound systems.	 * This is a really nasty hack, but unless we change the driver	 * it's the only way to support both addrs from one binary.	 * -- Cort	 */	if ( _machine == _MACH_prep )	{		extern struct card_info snd_installed_cards[];		struct card_info  *snd_ptr;		for ( snd_ptr = snd_installed_cards; 		      snd_ptr < &snd_installed_cards[num_sound_cards];		      snd_ptr++ )		{			if ( snd_ptr->card_type == SNDCARD_CS4232 )			{				if ( _prep_type == _PREP_Motorola )				{					snd_ptr->config.io_base = 0x830;					snd_ptr->config.irq = 10;					snd_ptr->config.dma = ppc_cs4232_dma = 6;					snd_ptr->config.dma2 = ppc_cs4232_dma2 = 7;				}				if ( _prep_type == _PREP_IBM )				{					snd_ptr->config.io_base = 0x530;					snd_ptr->config.irq =  5;					snd_ptr->config.dma = ppc_cs4232_dma = 1;					/* this is wrong - but leave it for now */					snd_ptr->config.dma2 = ppc_cs4232_dma2 = 7;				}			}		}	}#endif /* CONFIG_SOUND_CS4232 */		/*print_residual_device_info();*/        request_region(0x20,0x20,"pic1");	request_region(0xa0,0x20,"pic2");	request_region(0x00,0x20,"dma1");	request_region(0x40,0x20,"timer");	request_region(0x80,0x10,"dma page reg");	request_region(0xc0,0x20,"dma2");	raven_init();#ifdef CONFIG_VGA_CONSOLE	/* remap the VGA memory */	vgacon_remap_base = 0xf0000000;	/*vgacon_remap_base = ioremap(0xc0000000, 0xba000);*/        conswitchp = &vga_con;#endif}/* * Determine the decrementer frequency from the residual data * This allows for a faster boot as we do not need to calibrate the * decrementer against another clock. This is important for embedded systems. */void __init prep_res_calibrate_decr(void){	unsigned long freq, divisor=4;	freq = res->VitalProductData.ProcessorBusHz;	printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",	       (freq/divisor)/1000000, (freq/divisor)%1000000);	tb_ticks_per_jiffy = freq / HZ / divisor;	tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);}/* * Uses the on-board timer to calibrate the on-chip decrementer register * for prep systems.  On the pmac the OF tells us what the frequency is * but on prep we have to figure it out. * -- Cort *//* Done with 3 interrupts: the first one primes the cache and the * 2 following ones measure the interval. The precision of the method * is still doubtful due to the short interval sampled. */static volatile int calibrate_steps __initdata = 3;static unsigned tbstamp __initdata = 0;void __initprep_calibrate_decr_handler(int            irq,			    void           *dev,			    struct pt_regs *regs){	unsigned long t, freq;	int step=--calibrate_steps;	t = get_tbl();	if (step > 0) {		tbstamp = t;	} else {		freq = (t - tbstamp)*HZ;		printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",		       freq/1000000, freq%1000000);		tb_ticks_per_jiffy = freq / HZ;		tb_to_us = mulhwu_scale_factor(freq, 1000000);	}}void __init prep_calibrate_decr(void){	unsigned long flags;	save_flags(flags);#define TIMER0_COUNT 0x40#define TIMER_CONTROL 0x43	/* set timer to periodic mode */	outb_p(0x34,TIMER_CONTROL);/* binary, mode 2, LSB/MSB, ch 0 */	/* set the clock to ~100 Hz */	outb_p(LATCH & 0xff , TIMER0_COUNT);	/* LSB */	outb(LATCH >> 8 , TIMER0_COUNT);	/* MSB */		if (request_irq(0, prep_calibrate_decr_handler, 0, "timer", NULL) != 0)		panic("Could not allocate timer IRQ!");	__sti();	while ( calibrate_steps ) /* nothing */; /* wait for calibrate */        restore_flags(flags);	free_irq( 0, NULL);}static long __init mk48t59_init(void) {	unsigned char tmp;

⌨️ 快捷键说明

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