pci_psycho.c

来自「linux 内核源代码」· C语言 代码 · 共 1,074 行 · 第 1/3 页

C
1,074
字号
/* pci_psycho.c: PSYCHO/U2P specific PCI controller support. * * Copyright (C) 1997, 1998, 1999, 2007 David S. Miller (davem@davemloft.net) * Copyright (C) 1998, 1999 Eddie C. Dost   (ecd@skynet.be) * Copyright (C) 1999 Jakub Jelinek   (jakub@redhat.com) */#include <linux/kernel.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <asm/iommu.h>#include <asm/irq.h>#include <asm/starfire.h>#include <asm/prom.h>#include <asm/of_device.h>#include <asm/oplib.h>#include "pci_impl.h"#include "iommu_common.h"/* All PSYCHO registers are 64-bits.  The following accessor * routines are how they are accessed.  The REG parameter * is a physical address. */#define psycho_read(__reg) \({	u64 __ret; \	__asm__ __volatile__("ldxa [%1] %2, %0" \			     : "=r" (__ret) \			     : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \			     : "memory"); \	__ret; \})#define psycho_write(__reg, __val) \	__asm__ __volatile__("stxa %0, [%1] %2" \			     : /* no outputs */ \			     : "r" (__val), "r" (__reg), \			       "i" (ASI_PHYS_BYPASS_EC_E) \			     : "memory")/* Misc. PSYCHO PCI controller register offsets and definitions. */#define PSYCHO_CONTROL		0x0010UL#define  PSYCHO_CONTROL_IMPL	 0xf000000000000000UL /* Implementation of this PSYCHO*/#define  PSYCHO_CONTROL_VER	 0x0f00000000000000UL /* Version of this PSYCHO       */#define  PSYCHO_CONTROL_MID	 0x00f8000000000000UL /* UPA Module ID of PSYCHO      */#define  PSYCHO_CONTROL_IGN	 0x0007c00000000000UL /* Interrupt Group Number       */#define  PSYCHO_CONTROL_RESV     0x00003ffffffffff0UL /* Reserved                     */#define  PSYCHO_CONTROL_APCKEN	 0x0000000000000008UL /* Address Parity Check Enable  */#define  PSYCHO_CONTROL_APERR	 0x0000000000000004UL /* Incoming System Addr Parerr  */#define  PSYCHO_CONTROL_IAP	 0x0000000000000002UL /* Invert UPA Parity            */#define  PSYCHO_CONTROL_MODE	 0x0000000000000001UL /* PSYCHO clock mode            */#define PSYCHO_PCIA_CTRL	0x2000UL#define PSYCHO_PCIB_CTRL	0x4000UL#define  PSYCHO_PCICTRL_RESV1	 0xfffffff000000000UL /* Reserved                     */#define  PSYCHO_PCICTRL_SBH_ERR	 0x0000000800000000UL /* Streaming byte hole error    */#define  PSYCHO_PCICTRL_SERR	 0x0000000400000000UL /* SERR signal asserted         */#define  PSYCHO_PCICTRL_SPEED	 0x0000000200000000UL /* PCI speed (1 is U2P clock)   */#define  PSYCHO_PCICTRL_RESV2	 0x00000001ffc00000UL /* Reserved                     */#define  PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking      */#define  PSYCHO_PCICTRL_RESV3	 0x00000000001ff800UL /* Reserved                     */#define  PSYCHO_PCICTRL_SBH_INT	 0x0000000000000400UL /* Streaming byte hole int enab */#define  PSYCHO_PCICTRL_WEN	 0x0000000000000200UL /* Power Mgmt Wake Enable       */#define  PSYCHO_PCICTRL_EEN	 0x0000000000000100UL /* PCI Error Interrupt Enable   */#define  PSYCHO_PCICTRL_RESV4	 0x00000000000000c0UL /* Reserved                     */#define  PSYCHO_PCICTRL_AEN	 0x000000000000003fUL /* PCI DVMA Arbitration Enable  *//* U2P Programmer's Manual, page 13-55, configuration space * address format: *  *  32             24 23 16 15    11 10       8 7   2  1 0 * --------------------------------------------------------- * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 | * --------------------------------------------------------- */#define PSYCHO_CONFIG_BASE(PBM)	\	((PBM)->config_space | (1UL << 24))#define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG)	\	(((unsigned long)(BUS)   << 16) |	\	 ((unsigned long)(DEVFN) << 8)  |	\	 ((unsigned long)(REG)))static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,				      unsigned char bus,				      unsigned int devfn,				      int where){	if (!pbm)		return NULL;	return (void *)		(PSYCHO_CONFIG_BASE(pbm) |		 PSYCHO_CONFIG_ENCODE(bus, devfn, where));}/* PSYCHO error handling support. */enum psycho_error_type {	UE_ERR, CE_ERR, PCI_ERR};/* Helper function of IOMMU error checking, which checks out * the state of the streaming buffers.  The IOMMU lock is * held when this is called. * * For the PCI error case we know which PBM (and thus which * streaming buffer) caused the error, but for the uncorrectable * error case we do not.  So we always check both streaming caches. */#define PSYCHO_STRBUF_CONTROL_A 0x2800UL#define PSYCHO_STRBUF_CONTROL_B 0x4800UL#define  PSYCHO_STRBUF_CTRL_LPTR    0x00000000000000f0UL /* LRU Lock Pointer */#define  PSYCHO_STRBUF_CTRL_LENAB   0x0000000000000008UL /* LRU Lock Enable */#define  PSYCHO_STRBUF_CTRL_RRDIS   0x0000000000000004UL /* Rerun Disable */#define  PSYCHO_STRBUF_CTRL_DENAB   0x0000000000000002UL /* Diagnostic Mode Enable */#define  PSYCHO_STRBUF_CTRL_ENAB    0x0000000000000001UL /* Streaming Buffer Enable */#define PSYCHO_STRBUF_FLUSH_A   0x2808UL#define PSYCHO_STRBUF_FLUSH_B   0x4808UL#define PSYCHO_STRBUF_FSYNC_A   0x2810UL#define PSYCHO_STRBUF_FSYNC_B   0x4810UL#define PSYCHO_STC_DATA_A	0xb000UL#define PSYCHO_STC_DATA_B	0xc000UL#define PSYCHO_STC_ERR_A	0xb400UL#define PSYCHO_STC_ERR_B	0xc400UL#define  PSYCHO_STCERR_WRITE	 0x0000000000000002UL	/* Write Error */#define  PSYCHO_STCERR_READ	 0x0000000000000001UL	/* Read Error */#define PSYCHO_STC_TAG_A	0xb800UL#define PSYCHO_STC_TAG_B	0xc800UL#define  PSYCHO_STCTAG_PPN	 0x0fffffff00000000UL	/* Physical Page Number */#define  PSYCHO_STCTAG_VPN	 0x00000000ffffe000UL	/* Virtual Page Number */#define  PSYCHO_STCTAG_VALID	 0x0000000000000002UL	/* Valid */#define  PSYCHO_STCTAG_WRITE	 0x0000000000000001UL	/* Writable */#define PSYCHO_STC_LINE_A	0xb900UL#define PSYCHO_STC_LINE_B	0xc900UL#define  PSYCHO_STCLINE_LINDX	 0x0000000001e00000UL	/* LRU Index */#define  PSYCHO_STCLINE_SPTR	 0x00000000001f8000UL	/* Dirty Data Start Pointer */#define  PSYCHO_STCLINE_LADDR	 0x0000000000007f00UL	/* Line Address */#define  PSYCHO_STCLINE_EPTR	 0x00000000000000fcUL	/* Dirty Data End Pointer */#define  PSYCHO_STCLINE_VALID	 0x0000000000000002UL	/* Valid */#define  PSYCHO_STCLINE_FOFN	 0x0000000000000001UL	/* Fetch Outstanding / Flush Necessary */static DEFINE_SPINLOCK(stc_buf_lock);static unsigned long stc_error_buf[128];static unsigned long stc_tag_buf[16];static unsigned long stc_line_buf[16];static void __psycho_check_one_stc(struct pci_pbm_info *pbm,				   int is_pbm_a){	struct strbuf *strbuf = &pbm->stc;	unsigned long regbase = pbm->controller_regs;	unsigned long err_base, tag_base, line_base;	u64 control;	int i;	if (is_pbm_a) {		err_base = regbase + PSYCHO_STC_ERR_A;		tag_base = regbase + PSYCHO_STC_TAG_A;		line_base = regbase + PSYCHO_STC_LINE_A;	} else {		err_base = regbase + PSYCHO_STC_ERR_B;		tag_base = regbase + PSYCHO_STC_TAG_B;		line_base = regbase + PSYCHO_STC_LINE_B;	}	spin_lock(&stc_buf_lock);	/* This is __REALLY__ dangerous.  When we put the	 * streaming buffer into diagnostic mode to probe	 * it's tags and error status, we _must_ clear all	 * of the line tag valid bits before re-enabling	 * the streaming buffer.  If any dirty data lives	 * in the STC when we do this, we will end up	 * invalidating it before it has a chance to reach	 * main memory.	 */	control = psycho_read(strbuf->strbuf_control);	psycho_write(strbuf->strbuf_control,		     (control | PSYCHO_STRBUF_CTRL_DENAB));	for (i = 0; i < 128; i++) {		unsigned long val;		val = psycho_read(err_base + (i * 8UL));		psycho_write(err_base + (i * 8UL), 0UL);		stc_error_buf[i] = val;	}	for (i = 0; i < 16; i++) {		stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));		stc_line_buf[i] = psycho_read(line_base + (i * 8UL));		psycho_write(tag_base + (i * 8UL), 0UL);		psycho_write(line_base + (i * 8UL), 0UL);	}	/* OK, state is logged, exit diagnostic mode. */	psycho_write(strbuf->strbuf_control, control);	for (i = 0; i < 16; i++) {		int j, saw_error, first, last;		saw_error = 0;		first = i * 8;		last = first + 8;		for (j = first; j < last; j++) {			unsigned long errval = stc_error_buf[j];			if (errval != 0) {				saw_error++;				printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",				       pbm->name,				       j,				       (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,				       (errval & PSYCHO_STCERR_READ) ? 1 : 0);			}		}		if (saw_error != 0) {			unsigned long tagval = stc_tag_buf[i];			unsigned long lineval = stc_line_buf[i];			printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",			       pbm->name,			       i,			       ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),			       (tagval & PSYCHO_STCTAG_VPN),			       ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),			       ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));			printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"			       "V(%d)FOFN(%d)]\n",			       pbm->name,			       i,			       ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),			       ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),			       ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),			       ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),			       ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),			       ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));		}	}	spin_unlock(&stc_buf_lock);}static void __psycho_check_stc_error(struct pci_pbm_info *pbm,				     unsigned long afsr,				     unsigned long afar,				     enum psycho_error_type type){	__psycho_check_one_stc(pbm,			       (pbm == &pbm->parent->pbm_A));}/* When an Uncorrectable Error or a PCI Error happens, we * interrogate the IOMMU state to see if it is the cause. */#define PSYCHO_IOMMU_CONTROL	0x0200UL#define  PSYCHO_IOMMU_CTRL_RESV     0xfffffffff9000000UL /* Reserved                      */#define  PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status      */#define  PSYCHO_IOMMU_CTRL_XLTEERR  0x0000000001000000UL /* Translation Error encountered */#define  PSYCHO_IOMMU_CTRL_LCKEN    0x0000000000800000UL /* Enable translation locking    */#define  PSYCHO_IOMMU_CTRL_LCKPTR   0x0000000000780000UL /* Translation lock pointer      */#define  PSYCHO_IOMMU_CTRL_TSBSZ    0x0000000000070000UL /* TSB Size                      */#define  PSYCHO_IOMMU_TSBSZ_1K      0x0000000000000000UL /* TSB Table 1024 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_2K      0x0000000000010000UL /* TSB Table 2048 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_4K      0x0000000000020000UL /* TSB Table 4096 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_8K      0x0000000000030000UL /* TSB Table 8192 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_16K     0x0000000000040000UL /* TSB Table 16k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_32K     0x0000000000050000UL /* TSB Table 32k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_64K     0x0000000000060000UL /* TSB Table 64k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_128K    0x0000000000070000UL /* TSB Table 128k 8-byte entries */#define  PSYCHO_IOMMU_CTRL_RESV2    0x000000000000fff8UL /* Reserved                      */#define  PSYCHO_IOMMU_CTRL_TBWSZ    0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */#define  PSYCHO_IOMMU_CTRL_DENAB    0x0000000000000002UL /* Diagnostic mode enable        */#define  PSYCHO_IOMMU_CTRL_ENAB     0x0000000000000001UL /* IOMMU Enable                  */#define PSYCHO_IOMMU_TSBBASE	0x0208UL#define PSYCHO_IOMMU_FLUSH	0x0210UL#define PSYCHO_IOMMU_TAG	0xa580UL#define  PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)#define  PSYCHO_IOMMU_TAG_ERR	 (0x1UL << 22UL)#define  PSYCHO_IOMMU_TAG_WRITE	 (0x1UL << 21UL)#define  PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)#define  PSYCHO_IOMMU_TAG_SIZE	 (0x1UL << 19UL)#define  PSYCHO_IOMMU_TAG_VPAGE	 0x7ffffUL#define PSYCHO_IOMMU_DATA	0xa600UL#define  PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)#define  PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)#define  PSYCHO_IOMMU_DATA_PPAGE 0xfffffffULstatic void psycho_check_iommu_error(struct pci_pbm_info *pbm,				     unsigned long afsr,				     unsigned long afar,				     enum psycho_error_type type){	struct iommu *iommu = pbm->iommu;	unsigned long iommu_tag[16];	unsigned long iommu_data[16];	unsigned long flags;	u64 control;	int i;	spin_lock_irqsave(&iommu->lock, flags);	control = psycho_read(iommu->iommu_control);	if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {		char *type_string;		/* Clear the error encountered bit. */		control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;		psycho_write(iommu->iommu_control, control);		switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {		case 0:			type_string = "Protection Error";			break;		case 1:			type_string = "Invalid Error";			break;		case 2:			type_string = "TimeOut Error";			break;		case 3:		default:			type_string = "ECC Error";			break;		};		printk("%s: IOMMU Error, type[%s]\n",		       pbm->name, type_string);		/* Put the IOMMU into diagnostic mode and probe		 * it's TLB for entries with error status.		 *		 * It is very possible for another DVMA to occur		 * while we do this probe, and corrupt the system		 * further.  But we are so screwed at this point		 * that we are likely to crash hard anyways, so		 * get as much diagnostic information to the		 * console as we can.		 */		psycho_write(iommu->iommu_control,			     control | PSYCHO_IOMMU_CTRL_DENAB);		for (i = 0; i < 16; i++) {			unsigned long base = pbm->controller_regs;			iommu_tag[i] =				psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));			iommu_data[i] =				psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));			/* Now clear out the entry. */			psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);			psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);		}		/* Leave diagnostic mode. */		psycho_write(iommu->iommu_control, control);		for (i = 0; i < 16; i++) {			unsigned long tag, data;			tag = iommu_tag[i];			if (!(tag & PSYCHO_IOMMU_TAG_ERR))				continue;			data = iommu_data[i];

⌨️ 快捷键说明

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