/* PCI configuration space access */ /* * Acknowledgements: * Valuable information was obtained from the following drivers * netbsd: (C) Allegro Networks Inc; Wasabi Systems Inc. * linux: (C) MontaVista, Software, Inc; Chris Zankel, Mark A. Greer. * rtems: (C) Brookhaven National Laboratory; K. Feng */ /* * Original file header of libbsp/shared/pci.c where this file is based upon. * * Copyright (C) 1999 valette@crf.canon.fr * * This code is heavily inspired by the public specification of STREAM V2 * that can be found at : * * by following * the STREAM API Specification Document link. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. * * Till Straumann, , 1/2002 * - separated bridge detection code out of this file */ #include #include #include #include #include #include /* set to max so we get early access to hose 0 */ unsigned BSP_pci_hose1_bus_base = (unsigned)-1; #define MV64x60_PCI0_CONFIG_ADDR (BSP_MV64x60_BASE + 0xcf8) #define MV64x60_PCI0_CONFIG_DATA (BSP_MV64x60_BASE + 0xcfc) #define MV64x60_PCI1_CONFIG_ADDR (BSP_MV64x60_BASE + 0xc78) #define MV64x60_PCI1_CONFIG_DATA (BSP_MV64x60_BASE + 0xc7c) #define PCI_BUS2HOSE(bus) (bus 255 ) { rtems_panic("Too many PCI busses in the system"); } /* readjust total number */ ucMaxPCIBus+=BSP_pci_hose1_bus_base; /* install new access functions that can hide the hoses */ BSP_pci_configuration.pci_config_addr = (volatile unsigned char *)0xdeadbeef; BSP_pci_configuration.pci_config_data = (volatile unsigned char *)0xdeadbeef; BSP_pci_configuration.pci_functions = &pci_hosed_indirect_functions; } #define PCI_ERR_BITS 0xf900 #define PCI_STATUS_OK(x) (!((x)&PCI_ERR_BITS)) /* For now, just clear errors in the PCI status reg. * * Returns: (for diagnostic purposes) * original settings (i.e. before applying the clearing * sequence) * (pci_status(hose_1)&0xff00) | ((pci_status(hose_2)>>8)&0xff) */ static unsigned long clear_hose_errors(int bus, int quiet) { unsigned long rval; uint16_t pcistat; int count; int hose = PCI_BUS2HOSE(bus); /* read error status for info return */ pci_read_config_word(bus,0,0,PCI_STATUS,&pcistat); rval = pcistat; count=10; do { /* clear error reporting registers */ /* clear PCI status register */ pci_write_config_word(bus,0,0,PCI_STATUS, PCI_ERR_BITS); /* read new status */ pci_read_config_word(bus,0,0,PCI_STATUS, &pcistat); } while ( ! PCI_STATUS_OK(pcistat) && count-- ); if ( !PCI_STATUS_OK(rval) && !quiet) { printk("Cleared PCI errors at discovery (hose %i): pci_stat was 0x%04lx\n", hose, rval); } if ( !PCI_STATUS_OK(pcistat) ) { printk("Unable to clear PCI errors at discovery (hose %i) still 0x%04x after 10 attempts\n",hose, pcistat); } return rval; } unsigned short (*_BSP_clear_vmebridge_errors)(int) = 0; unsigned long _BSP_clear_hostbridge_errors(int enableMCP, int quiet) { unsigned long rval; /* MCP is not connected */ if ( enableMCP ) return -1; rval = (clear_hose_errors(0, quiet) & PCI_ERR_BITS)>>8; rval |= clear_hose_errors(BSP_pci_hose1_bus_base, quiet) & PCI_ERR_BITS; /* Tsi148 doesn't propagate VME bus errors to PCI status reg. */ if ( _BSP_clear_vmebridge_errors ) rval |= _BSP_clear_vmebridge_errors(quiet)<<16; return rval; }