unicore32 machine related files: pci bus handling
Subsystems (2)
PATCH 10/12 unicore32 machine related files: pci bus handling
Message-Id: <1fd2d1cdc402636e090d573cb56b85a0b492ccac.1297842537.git.gxt@mprc.pku.edu.cn>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: GuanXuetao <[email protected]>
Date: Sat, 15 Jan 2011 18:25:14 +0800
This patch implements arch-specific pci bus driver.
--- arch/unicore32/include/asm/pci.h | 46 +++++ arch/unicore32/kernel/pci.c | 404 ++++++++++++++++++++++++++++++++++++++ drivers/pci/Makefile | 1 + 3 files changed, 451 insertions(+), 0 deletions(-) create mode 100644 arch/unicore32/include/asm/pci.h create mode 100644 arch/unicore32/kernel/pci.c
arch/unicore32/include/asm/pci.h new file +46 -0
@@ -0,0 +1,46 @@ +/* +* linux/arch/unicore32/include/asm/pci.h +* +* Code specific to PKUnity SoC and UniCore ISA +* +* Copyright (C) 2001-2010 GUAN Xue-tao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef __UNICORE_PCI_H__ +#define __UNICORE_PCI_H__ + +#ifdef __KERNEL__ +#include <asm-generic/pci-dma-compat.h> +#include <asm-generic/pci.h> +#include <mach/hardware.h> /* for PCIBIOS_MIN_* */ + +static inline void pcibios_set_master (struct pci_dev *dev) +{ +/* No special bus mastering setup handling */ +} + +static inline void pcibios_penalize_isa_irq (int irq,int active) +{ +/* We don't do dynamic PCI IRQ allocation */ +} + +#ifdef CONFIG_PCI +static inline void pci_dma_burst_advice (struct pci_dev *pdev, +enum pci_dma_burst_strategy *strat, +unsigned long *strategy_parameter) +{ + *strat =PCI_DMA_BURST_INFINITY ; + *strategy_parameter = ~0UL ; +} +#endif + +#define HAVE_PCI_MMAP +extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +enum pci_mmap_state mmap_state,int write_combine); + +#endif /* __KERNEL__ */ + +#endif
arch/unicore32/kernel/pci.c new file +404 -0
404 lines not on this page · raw message
drivers/pci/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_PCI_IOV) += iov.o obj-$(CONFIG_X86) += setup-bus.o obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o +obj-$(CONFIG_UNICORE32) += setup-bus.o setup-irq.o obj-$(CONFIG_PARISC) += setup-bus.o obj-$(CONFIG_SUPERH) += setup-bus.o setup-irq.o obj-$(CONFIG_PPC) += setup-bus.o
Signature · 1 line
1.6.2.2
Arnd Bergmann
maintainerarch/unicore32/kernel/pci.c line 38
Quoted 7 lines · Guan Xuetao
arch/unicore32/kernel/pci.c new file +7
-0+{ +PCICFG_ADDR =CONFIG_CMD (bus, devfn, where); +switch (size) { +case 1 : + *value = (PCICFG_DATA >> ((where &3 ) *8 )) &0xFF ; +break ; +case 2 :
It took me a while to figure out what this actually does. PCICFG_ADDR and PCICFG_DATA are pointers to MMIO registers, which you should not simply dereference. A lot of things can go wrong there, especially if future machines move to weakly ordered I/O subsystem or have multiple CPUs, but even for the simple case, the compiler has a lot of ways to mess this up.
As explained in my reply to the "hardware registers" patch, all these pointers should be marked as __iomem, so that sparse warns about dangerous accesses such as the one here.
The code above should be written as
{
writel(CONFIG_CMD(bus, devfn, where), PCICFG_ADDR);
switch (size) {
case 1:
*value = readl(PCICFG_DATA >> ((where & 3) * 8)) & 0xFF;
break;
case 2:
ArndQuoted 31 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 1:20 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 10/12] unicore32 machine related files: pci bus handlingReview
Quoted 7 lines · Guan Xuetao
(quoted diff) +7
-0+{ + PCICFG_ADDR = CONFIG_CMD(bus, devfn, where); + switch (size) { + case 1: + *value = (PCICFG_DATA >> ((where & 3) * 8)) & 0xFF; + break; + case 2:It took me a while to figure out what this actually does.
PCICFG_ADDRandPCICFG_DATAare pointers to MMIO registers, which you should not simply dereference. A lot of things can go wrong there, especially if future machines move to weakly ordered I/O subsystem or have multiple CPUs, but even for the simple case, the compiler has a lot of ways to mess this up.As explained in my reply to the "hardware registers" patch, all these pointers should be marked as
__iomem, so that sparse warns about dangerous accesses such as the one here.The code above should be written as
Quoted 7 lines
{
writel(CONFIG_CMD(bus, devfn, where), PCICFG_ADDR);
switch (size) {
case 1:
*value = readl(PCICFG_DATA >> ((where & 3) * 8)) & 0xFF;
break;
case 2:Please see following patch:arch/unicore32/kernel/pci.c | 58 +++++++++++++++++++++---------------------
1 files changed, 29 insertions(+), 29 deletions(-)
arch/unicore32/kernel/pci.c +29 -29
@@ -30,16 +30,16 @@ static int puv3_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value) { -PCICFG_ADDR =CONFIG_CMD (bus, devfn, where); +writel (CONFIG_CMD(bus ,devfn ,where ), PCICFG_ADDR);switch (size) {case 1 : - *value = (PCICFG_DATA >> ((where &3 ) *8 )) &0xFF ; + *value = (readl (PCICFG_DATA ) >> ((where &3 ) *8 )) &0xFF ;break ;case 2 : - *value = (PCICFG_DATA >> ((where &2 ) *8 )) &0xFFFF ; + *value = (readl (PCICFG_DATA ) >> ((where &2 ) *8 )) &0xFFFF ;break ;case 4 : - *value =PCICFG_DATA ; + *value =readl (PCICFG_DATA );break ; }return PCIBIOS_SUCCESSFUL ;
@@ -49,18 +49,18 @@ static int puv3_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value) { -PCICFG_ADDR =CONFIG_CMD (bus, devfn, where); +writel (CONFIG_CMD(bus ,devfn ,where ), PCICFG_ADDR);switch (size) {case 1 : -PCICFG_DATA = (PCICFG_DATA & ~FMASK (8 , (where&3 )*8 )) - |FIELD (value,8 , (where&3 )*8 ); +writel ((readl (PCICFG_DATA ) & ~FMASK (8 , (where&3 )*8 )) + |FIELD (value,8 , (where&3 )*8 ),PCICFG_DATA );break ;case 2 : -PCICFG_DATA = (PCICFG_DATA & ~FMASK (16 , (where&2 )*8 )) - |FIELD (value,16 , (where&2 )*8 ); +writel ((readl (PCICFG_DATA ) & ~FMASK (16 , (where&2 )*8 )) + |FIELD (value,16 , (where&2 )*8 ),PCICFG_DATA );break ;case 4 : -PCICFG_DATA = value; +writel (value,PCICFG_DATA );break ; }return PCIBIOS_SUCCESSFUL ;
@@ -75,31 +75,31 @@ void pci_puv3_preinit(void) {printk (KERN_DEBUG "PCI: PKUnity PCI Controller Initializing ...\n" );/* config PCI bridge base */ -PCICFG_BRIBASE =PKUNITY_PCIBRI_BASE ; +writel (PKUNITY_PCIBRI_BASE ,PCICFG_BRIBASE ); -PCIBRI_AHBCTL0 =0 ; -PCIBRI_AHBBAR0 =PKUNITY_PCIBRI_BASE | PCIBRI_BARx_MEM; -PCIBRI_AHBAMR0 =0xFFFF0000 ; -PCIBRI_AHBTAR0 =0 ; +writel (0 ,PCIBRI_AHBCTL0 ); +writel (PKUNITY_PCIBRI_BASE | PCIBRI_BARx_MEM,PCIBRI_AHBBAR0 ); +writel (0xFFFF0000 ,PCIBRI_AHBAMR0 ); +writel (0 ,PCIBRI_AHBTAR0 ); -PCIBRI_AHBCTL1 = PCIBRI_CTLx_AT; -PCIBRI_AHBBAR1 =PKUNITY_PCILIO_BASE | PCIBRI_BARx_IO; -PCIBRI_AHBAMR1 =0xFFFF0000 ; -PCIBRI_AHBTAR1 =0x00000000 ; +writel (PCIBRI_CTLx_AT,PCIBRI_AHBCTL1 ); +writel (PKUNITY_PCILIO_BASE | PCIBRI_BARx_IO,PCIBRI_AHBBAR1 ); +writel (0xFFFF0000 ,PCIBRI_AHBAMR1 ); +writel (0x00000000 ,PCIBRI_AHBTAR1 ); -PCIBRI_AHBCTL2 = PCIBRI_CTLx_PREF; -PCIBRI_AHBBAR2 =PKUNITY_PCIMEM_BASE | PCIBRI_BARx_MEM; -PCIBRI_AHBAMR2 =0xF8000000 ; -PCIBRI_AHBTAR2 =0 ; +writel (PCIBRI_CTLx_PREF,PCIBRI_AHBCTL2 ); +writel (PKUNITY_PCIMEM_BASE | PCIBRI_BARx_MEM,PCIBRI_AHBBAR2 ); +writel (0xF8000000 ,PCIBRI_AHBAMR2 ); +writel (0 ,PCIBRI_AHBTAR2 ); -PCIBRI_BAR1 =PKUNITY_PCIAHB_BASE | PCIBRI_BARx_MEM; +writel (PKUNITY_PCIAHB_BASE | PCIBRI_BARx_MEM,PCIBRI_BAR1 ); -PCIBRI_PCICTL0 = PCIBRI_CTLx_AT | PCIBRI_CTLx_PREF; -PCIBRI_PCIBAR0 =PKUNITY_PCIAHB_BASE | PCIBRI_BARx_MEM; -PCIBRI_PCIAMR0 =0xF8000000 ; -PCIBRI_PCITAR0 =PKUNITY_SDRAM_BASE ; +writel (PCIBRI_CTLx_AT | PCIBRI_CTLx_PREF,PCIBRI_PCICTL0 ); +writel (PKUNITY_PCIAHB_BASE | PCIBRI_BARx_MEM,PCIBRI_PCIBAR0 ); +writel (0xF8000000 ,PCIBRI_PCIAMR0 ); +writel (PKUNITY_SDRAM_BASE ,PCIBRI_PCITAR0 ); -PCIBRI_CMD =PCIBRI_CMD |PCIBRI_CMD_IO |PCIBRI_CMD_MEM ; +writel (readl (PCIBRI_CMD ) |PCIBRI_CMD_IO |PCIBRI_CMD_MEM ,PCIBRI_CMD ); }static int __init pci_puv3_map_irq (struct pci_dev *dev,u8 slot,u8 pin)
---
PCI_CFG_DATA must be read/write with 32bit in PKUnity-v3 pci controller.
Quoted 2 lines
Arnd
Thanks & Regards.
Guan Xuetao
Quoted 3 lines · Guan Xuetao
Please see following patch:
arch/unicore32/kernel/pci.c| 58 +++++++++++++++++++++---------------------1 files changed, 29 insertions(+), 29 deletions(-)
Looks good to me.
Arnd