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

📄 core_marvel.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		*value = *(vuip)addr;		break;	default:		return PCIBIOS_FUNC_NOT_SUPPORTED;	}	return PCIBIOS_SUCCESSFUL;}static intmarvel_write_config(struct pci_bus *bus, unsigned int devfn, int where,		    int size, u32 value){	unsigned long addr;		if (0 == (addr = mk_conf_addr(bus, devfn, where)))		return PCIBIOS_DEVICE_NOT_FOUND;	switch (size) {	case 1:		__kernel_stb(value, *(vucp)addr);		mb();		__kernel_ldbu(*(vucp)addr);		break;	case 2:		__kernel_stw(value, *(vusp)addr);		mb();		__kernel_ldwu(*(vusp)addr);		break;	case 4:		*(vuip)addr = value;		mb();		*(vuip)addr;		break;	default:		return PCIBIOS_FUNC_NOT_SUPPORTED;	}	return PCIBIOS_SUCCESSFUL;}struct pci_ops marvel_pci_ops ={	.read =		marvel_read_config,	.write = 	marvel_write_config,};/* * Other PCI helper functions. */voidmarvel_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end){	io7_ioport_csrs *csrs = ((struct io7_port *)hose->sysdata)->csrs;	wmb();	csrs->POx_SG_TBIA.csr = 0;	mb();	csrs->POx_SG_TBIA.csr;}/* * IO map support. */unsigned longmarvel_ioremap(unsigned long addr, unsigned long size){	struct pci_controller *hose;	unsigned long baddr, last;	struct vm_struct *area;	unsigned long vaddr;	unsigned long *ptes;	unsigned long pfn;	/*	 * Adjust the addr.	 */ #ifdef CONFIG_VGA_HOSE	if (pci_vga_hose && __marvel_is_mem_vga(addr)) {		addr += pci_vga_hose->mem_space->start;	}#endif	if (!marvel_is_ioaddr(addr)) return 0UL;	/*	 * Find the hose.	 */	for (hose = hose_head; hose; hose = hose->next) {		if ((addr >> 32) == (hose->mem_space->start >> 32))			break; 	}	if (!hose)		return 0UL;	/*	 * We have the hose - calculate the bus limits.	 */	baddr = addr - hose->mem_space->start;	last = baddr + size - 1;	/*	 * Is it direct-mapped?	 */	if ((baddr >= __direct_map_base) && 	    ((baddr + size - 1) < __direct_map_base + __direct_map_size)) 		return IDENT_ADDR | (baddr - __direct_map_base);	/* 	 * Check the scatter-gather arena.	 */	if (hose->sg_pci &&	    baddr >= (unsigned long)hose->sg_pci->dma_base &&	    last < (unsigned long)hose->sg_pci->dma_base + hose->sg_pci->size){		/*		 * Adjust the limits (mappings must be page aligned)		 */		baddr -= hose->sg_pci->dma_base;		last -= hose->sg_pci->dma_base;		baddr &= PAGE_MASK;		size = PAGE_ALIGN(last) - baddr;		/*		 * Map it.		 */		area = get_vm_area(size, VM_IOREMAP);		if (!area) return (unsigned long)NULL;		ptes = hose->sg_pci->ptes;		for (vaddr = (unsigned long)area->addr; 		    baddr <= last; 		    baddr += PAGE_SIZE, vaddr += PAGE_SIZE) {			pfn = ptes[baddr >> PAGE_SHIFT];			if (!(pfn & 1)) {				printk("ioremap failed... pte not valid...\n");				vfree(area->addr);				return 0UL;			}			pfn >>= 1;	/* make it a true pfn */						if (__alpha_remap_area_pages(vaddr,						     pfn << PAGE_SHIFT, 						     PAGE_SIZE, 0)) {				printk("FAILED to map...\n");				vfree(area->addr);				return 0UL;			}		}		flush_tlb_all();		vaddr = (unsigned long)area->addr + (addr & ~PAGE_MASK);		return vaddr;	}	/*	 * Not found - assume legacy ioremap.	 */	return addr;}voidmarvel_iounmap(unsigned long addr){	if (((long)addr >> 41) == -2)		return;	/* kseg map, nothing to do */	if (addr)		vfree((void *)(PAGE_MASK & addr)); }#ifndef CONFIG_ALPHA_GENERICEXPORT_SYMBOL(marvel_ioremap);EXPORT_SYMBOL(marvel_iounmap);#endif/* * RTC Support */struct marvel_rtc_access_info {	unsigned long function;	unsigned long index;	unsigned long data;};static void__marvel_access_rtc(void *info){	struct marvel_rtc_access_info *rtc_access = info;	register unsigned long __r0 __asm__("$0");	register unsigned long __r16 __asm__("$16") = rtc_access->function;	register unsigned long __r17 __asm__("$17") = rtc_access->index;	register unsigned long __r18 __asm__("$18") = rtc_access->data;		__asm__ __volatile__(		"call_pal %4 # cserve rtc"		: "=r"(__r16), "=r"(__r17), "=r"(__r18), "=r"(__r0)		: "i"(PAL_cserve), "0"(__r16), "1"(__r17), "2"(__r18)		: "$1", "$22", "$23", "$24", "$25");	rtc_access->data = __r0;}u8__marvel_rtc_io(int write, u8 b, unsigned long addr){	struct marvel_rtc_access_info rtc_access = {0, };	static u8 index = 0;	u8 ret = 0;	switch(addr) {	case 0x70:					/* RTC_PORT(0) */		if (write) index = b;		ret = index;		break;	case 0x71:					/* RTC_PORT(1) */		rtc_access.index = index;		rtc_access.data = BCD_TO_BIN(b);		rtc_access.function = 0x49;		/* GET_TOY */		if (write) rtc_access.function = 0x48;	/* PUT_TOY */#ifdef CONFIG_SMP		if (smp_processor_id() != boot_cpuid)			smp_call_function_on_cpu(__marvel_access_rtc,						 &rtc_access,						 1,	/* retry */						 1,	/* wait  */						 1UL << boot_cpuid);		else			__marvel_access_rtc(&rtc_access);#else		__marvel_access_rtc(&rtc_access);#endif		ret = BIN_TO_BCD(rtc_access.data);				break;	default:		printk(KERN_WARNING "Illegal RTC port %lx\n", addr);		break;	}	return ret;}/* * NUMA Support *//********** * FIXME - for now each cpu is a node by itself  *              -- no real support for striped mode  ********** */intmarvel_pa_to_nid(unsigned long pa){	int cpuid;	if ((pa >> 43) & 1) 	/* I/O */ 		cpuid = (~(pa >> 35) & 0xff);	else			/* mem */		cpuid = ((pa >> 34) & 0x3) | ((pa >> (37 - 2)) & (0x1f << 2));	return marvel_cpuid_to_nid(cpuid);}intmarvel_cpuid_to_nid(int cpuid){	return cpuid;}unsigned longmarvel_node_mem_start(int nid){	unsigned long pa;	pa = (nid & 0x3) | ((nid & (0x1f << 2)) << 1);	pa <<= 34;	return pa;}unsigned longmarvel_node_mem_size(int nid){	return 16UL * 1024 * 1024 * 1024; /* 16GB */}/*  * AGP GART Support. */#include <linux/agp_backend.h>#include <asm/agp_backend.h>#include <linux/slab.h>#include <linux/delay.h>struct marvel_agp_aperture {	struct pci_iommu_arena *arena;	long pg_start;	long pg_count;};static intmarvel_agp_setup(alpha_agp_info *agp){	struct marvel_agp_aperture *aper;	if (!alpha_agpgart_size)		return -ENOMEM;	aper = kmalloc(sizeof(*aper), GFP_KERNEL);	if (aper == NULL) return -ENOMEM;	aper->arena = agp->hose->sg_pci;	aper->pg_count = alpha_agpgart_size / PAGE_SIZE;	aper->pg_start = iommu_reserve(aper->arena, aper->pg_count,				       aper->pg_count - 1);	if (aper->pg_start < 0) {		printk(KERN_ERR "Failed to reserve AGP memory\n");		kfree(aper);		return -ENOMEM;	}	agp->aperture.bus_base = 		aper->arena->dma_base + aper->pg_start * PAGE_SIZE;	agp->aperture.size = aper->pg_count * PAGE_SIZE;	agp->aperture.sysdata = aper;	return 0;}static voidmarvel_agp_cleanup(alpha_agp_info *agp){	struct marvel_agp_aperture *aper = agp->aperture.sysdata;	int status;	status = iommu_release(aper->arena, aper->pg_start, aper->pg_count);	if (status == -EBUSY) {		printk(KERN_WARNING		       "Attempted to release bound AGP memory - unbinding\n");		iommu_unbind(aper->arena, aper->pg_start, aper->pg_count);		status = iommu_release(aper->arena, aper->pg_start, 				       aper->pg_count);	}	if (status < 0)		printk(KERN_ERR "Failed to release AGP memory\n");	kfree(aper);	kfree(agp);}static intmarvel_agp_configure(alpha_agp_info *agp){	io7_ioport_csrs *csrs = ((struct io7_port *)agp->hose->sysdata)->csrs;	struct io7 *io7 = ((struct io7_port *)agp->hose->sysdata)->io7;	unsigned int new_rate = 0;	unsigned long agp_pll;	/*	 * Check the requested mode against the PLL setting.	 * The agpgart_be code has not programmed the card yet,	 * so we can still tweak mode here.	 */	agp_pll = io7->csrs->POx_RST[IO7_AGP_PORT].csr;	switch(IO7_PLL_RNGB(agp_pll)) {	case 0x4:				/* 2x only */		/* 		 * The PLL is only programmed for 2x, so adjust the		 * rate to 2x, if necessary.		 */		if (agp->mode.bits.rate != 2) 			new_rate = 2;		break;	case 0x6:				/* 1x / 4x */		/*		 * The PLL is programmed for 1x or 4x.  Don't go faster		 * than requested, so if the requested rate is 2x, use 1x.		 */		if (agp->mode.bits.rate == 2) 			new_rate = 1;		break;	default:				/* ??????? */		/*		 * Don't know what this PLL setting is, take the requested		 * rate, but warn the user.		 */		printk("%s: unknown PLL setting RNGB=%lx (PLL6_CTL=%016lx)\n",		       __FUNCTION__, IO7_PLL_RNGB(agp_pll), agp_pll);		break;	}	/*	 * Set the new rate, if necessary.	 */	if (new_rate) {		printk("Requested AGP Rate %dX not compatible "		       "with PLL setting - using %dX\n",		       agp->mode.bits.rate,		       new_rate);		agp->mode.bits.rate = new_rate;	}			printk("Enabling AGP on hose %d: %dX%s RQ %d\n", 	       agp->hose->index, agp->mode.bits.rate, 	       agp->mode.bits.sba ? " - SBA" : "", agp->mode.bits.rq);	csrs->AGP_CMD.csr = agp->mode.lw;	return 0;}static int marvel_agp_bind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *mem){	struct marvel_agp_aperture *aper = agp->aperture.sysdata;	return iommu_bind(aper->arena, aper->pg_start + pg_start, 			  mem->page_count, mem->memory);}static int marvel_agp_unbind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *mem){	struct marvel_agp_aperture *aper = agp->aperture.sysdata;	return iommu_unbind(aper->arena, aper->pg_start + pg_start,			    mem->page_count);}static unsigned longmarvel_agp_translate(alpha_agp_info *agp, dma_addr_t addr){	struct marvel_agp_aperture *aper = agp->aperture.sysdata;	unsigned long baddr = addr - aper->arena->dma_base;	unsigned long pte;	if (addr < agp->aperture.bus_base ||	    addr >= agp->aperture.bus_base + agp->aperture.size) {		printk("%s: addr out of range\n", __FUNCTION__);		return -EINVAL;	}	pte = aper->arena->ptes[baddr >> PAGE_SHIFT];	if (!(pte & 1)) {		printk("%s: pte not valid\n", __FUNCTION__);		return -EINVAL;	} 	return (pte >> 1) << PAGE_SHIFT;}struct alpha_agp_ops marvel_agp_ops ={	.setup		= marvel_agp_setup,	.cleanup	= marvel_agp_cleanup,	.configure	= marvel_agp_configure,	.bind		= marvel_agp_bind_memory,	.unbind		= marvel_agp_unbind_memory,	.translate	= marvel_agp_translate};alpha_agp_info *marvel_agp_info(void){	struct pci_controller *hose;	io7_ioport_csrs *csrs;	alpha_agp_info *agp;	struct io7 *io7;	/*	 * Find the first IO7 with an AGP card.	 *	 * FIXME -- there should be a better way (we want to be able to	 * specify and what if the agp card is not video???)	 */	hose = NULL;	for (io7 = NULL; (io7 = marvel_next_io7(io7)) != NULL; ) {		struct pci_controller *h;		vuip addr;		if (!io7->ports[IO7_AGP_PORT].enabled)			continue;		h = io7->ports[IO7_AGP_PORT].hose;		addr = (vuip)build_conf_addr(h, 0, PCI_DEVFN(5, 0), 0);		if (*addr != 0xffffffffu) {			hose = h;			break;		}	}	if (!hose || !hose->sg_pci)		return NULL;	printk("MARVEL - using hose %d as AGP\n", hose->index);	/* 	 * Get the csrs from the hose.	 */	csrs = ((struct io7_port *)hose->sysdata)->csrs;	/*	 * Allocate the info structure.	 */	agp = kmalloc(sizeof(*agp), GFP_KERNEL);	/*	 * Fill it in.	 */	agp->hose = hose;	agp->private = NULL;	agp->ops = &marvel_agp_ops;	/*	 * Aperture - not configured until ops.setup().	 */	agp->aperture.bus_base = 0;	agp->aperture.size = 0;	agp->aperture.sysdata = NULL;	/*	 * Capabilities.	 *	 * NOTE: IO7 reports through AGP_STAT that it can support a read queue	 *       depth of 17 (rq = 0x10). It actually only supports a depth of	 * 	 16 (rq = 0xf).	 */	agp->capability.lw = csrs->AGP_STAT.csr;	agp->capability.bits.rq = 0xf;		/*	 * Mode.	 */	agp->mode.lw = csrs->AGP_CMD.csr;	return agp;}

⌨️ 快捷键说明

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