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

📄 pci_psycho.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* Now build the IRQ bucket. */	pil = psycho_ino_to_pil(pdev, ino);	imap = p->controller_regs + imap_off;	imap += 4;	iclr_off = psycho_iclr_offset(ino);	iclr = p->controller_regs + iclr_off;	iclr += 4;	if ((ino & 0x20) == 0)		inofixup = ino & 0x03;	bucket = __bucket(build_irq(pil, inofixup, iclr, imap));	bucket->flags |= IBF_PCI;	return __irq(bucket);}/* 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    0x00000000000000f0 /* LRU Lock Pointer */#define  PSYCHO_STRBUF_CTRL_LENAB   0x0000000000000008 /* LRU Lock Enable */#define  PSYCHO_STRBUF_CTRL_RRDIS   0x0000000000000004 /* Rerun Disable */#define  PSYCHO_STRBUF_CTRL_DENAB   0x0000000000000002 /* Diagnostic Mode Enable */#define  PSYCHO_STRBUF_CTRL_ENAB    0x0000000000000001 /* 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	 0x0000000000000002	/* Write Error */#define  PSYCHO_STCERR_READ	 0x0000000000000001	/* Read Error */#define PSYCHO_STC_TAG_A	0xb800UL#define PSYCHO_STC_TAG_B	0xc800UL#define  PSYCHO_STCTAG_PPN	 0x0fffffff00000000	/* Physical Page Number */#define  PSYCHO_STCTAG_VPN	 0x00000000ffffe000	/* Virtual Page Number */#define  PSYCHO_STCTAG_VALID	 0x0000000000000002	/* Valid */#define  PSYCHO_STCTAG_WRITE	 0x0000000000000001	/* Writable */#define PSYCHO_STC_LINE_A	0xb900UL#define PSYCHO_STC_LINE_B	0xc900UL#define  PSYCHO_STCLINE_LINDX	 0x0000000001e00000	/* LRU Index */#define  PSYCHO_STCLINE_SPTR	 0x00000000001f8000	/* Dirty Data Start Pointer */#define  PSYCHO_STCLINE_LADDR	 0x0000000000007f00	/* Line Address */#define  PSYCHO_STCLINE_EPTR	 0x00000000000000fc	/* Dirty Data End Pointer */#define  PSYCHO_STCLINE_VALID	 0x0000000000000002	/* Valid */#define  PSYCHO_STCLINE_FOFN	 0x0000000000000001	/* Fetch Outstanding / Flush Necessary */static spinlock_t stc_buf_lock = SPIN_LOCK_UNLOCKED;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_controller_info *p,				   struct pci_pbm_info *pbm,				   int is_pbm_a){	struct pci_strbuf *strbuf = &pbm->stc;	unsigned long regbase = p->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_A;		tag_base = regbase + PSYCHO_STC_TAG_A;		line_base = regbase + PSYCHO_STC_LINE_A;	}	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("PSYCHO%d(PBM%c): STC_ERR(%d)[wr(%d)rd(%d)]\n",				       p->index,				       (is_pbm_a ? 'A' : 'B'),				       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("PSYCHO%d(PBM%c): STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",			       p->index,			       (is_pbm_a ? 'A' : 'B'),			       i,			       ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),			       (tagval & PSYCHO_STCTAG_VPN),			       ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),			       ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));			printk("PSYCHO%d(PBM%c): STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"			       "V(%d)FOFN(%d)]\n",			       p->index,			       (is_pbm_a ? 'A' : 'B'),			       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_controller_info *p,				     unsigned long afsr,				     unsigned long afar,				     enum psycho_error_type type){	struct pci_pbm_info *pbm;	pbm = &p->pbm_A;	if (pbm->stc.strbuf_enabled)		__psycho_check_one_stc(p, pbm, 1);	pbm = &p->pbm_B;	if (pbm->stc.strbuf_enabled)		__psycho_check_one_stc(p, pbm, 0);}/* 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     0xfffffffff9000000 /* Reserved                      */#define  PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000 /* Translation Error Status      */#define  PSYCHO_IOMMU_CTRL_XLTEERR  0x0000000001000000 /* Translation Error encountered */#define  PSYCHO_IOMMU_CTRL_LCKEN    0x0000000000800000 /* Enable translation locking    */#define  PSYCHO_IOMMU_CTRL_LCKPTR   0x0000000000780000 /* Translation lock pointer      */#define  PSYCHO_IOMMU_CTRL_TSBSZ    0x0000000000070000 /* TSB Size                      */#define  PSYCHO_IOMMU_TSBSZ_1K      0x0000000000000000 /* TSB Table 1024 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_2K      0x0000000000010000 /* TSB Table 2048 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_4K      0x0000000000020000 /* TSB Table 4096 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_8K      0x0000000000030000 /* TSB Table 8192 8-byte entries */#define  PSYCHO_IOMMU_TSBSZ_16K     0x0000000000040000 /* TSB Table 16k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_32K     0x0000000000050000 /* TSB Table 32k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_64K     0x0000000000060000 /* TSB Table 64k 8-byte entries  */#define  PSYCHO_IOMMU_TSBSZ_128K    0x0000000000070000 /* TSB Table 128k 8-byte entries */#define  PSYCHO_IOMMU_CTRL_RESV2    0x000000000000fff8 /* Reserved                      */#define  PSYCHO_IOMMU_CTRL_TBWSZ    0x0000000000000004 /* Assumed page size, 0=8k 1=64k */#define  PSYCHO_IOMMU_CTRL_DENAB    0x0000000000000002 /* Diagnostic mode enable        */#define  PSYCHO_IOMMU_CTRL_ENAB     0x0000000000000001 /* 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_controller_info *p,				     unsigned long afsr,				     unsigned long afar,				     enum psycho_error_type type){	struct pci_iommu *iommu = p->pbm_A.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("PSYCHO%d: IOMMU Error, type[%s]\n",		       p->index, 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 = p->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];			switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {			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("PSYCHO%d: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",			       p->index, i, type_string,			       ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),			       ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),			       ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),			       (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);			printk("PSYCHO%d: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",			       p->index, i,			       ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),			       ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),			       (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);		}	}	__psycho_check_stc_error(p, afsr, afar, type);	spin_unlock_irqrestore(&iommu->lock, flags);}/* Uncorrectable Errors.  Cause of the error and the address are * recorded in the UE_AFSR and UE_AFAR of PSYCHO.  They are errors * relating to UPA interface transactions. */#define PSYCHO_UE_AFSR	0x0030UL#define  PSYCHO_UEAFSR_PPIO	0x8000000000000000 /* Primary PIO is cause         */#define  PSYCHO_UEAFSR_PDRD	0x4000000000000000 /* Primary DVMA read is cause   */#define  PSYCHO_UEAFSR_PDWR	0x2000000000000000 /* Primary DVMA write is cause  */#define  PSYCHO_UEAFSR_SPIO	0x1000000000000000 /* Secondary PIO is cause       */#define  PSYCHO_UEAFSR_SDRD	0x0800000000000000 /* Secondary DVMA read is cause */#define  PSYCHO_UEAFSR_SDWR	0x0400000000000000 /* Secondary DVMA write is cause*/#define  PSYCHO_UEAFSR_RESV1	0x03ff000000000000 /* Reserved                     */#define  PSYCHO_UEAFSR_BMSK	0x0000ffff00000000 /* Bytemask of failed transfer  */#define  PSYCHO_UEAFSR_DOFF	0x00000000e0000000 /* Doubleword Offset            */#define  PSYCHO_UEAFSR_MID	0x000000001f000000 /* UPA MID causing the fault    */#define  PSYCHO_UEAFSR_BLK	0x0000000000800000 /* Trans was block operation    */#define  PSYCHO_UEAFSR_RESV2	0x00000000007fffff /* Reserved                     */#define PSYCHO_UE_AFAR	0x0038ULstatic void psycho_ue_intr(int irq, void *dev_id, struct pt_regs *regs){	struct pci_controller_info *p = dev_id;	unsigned long afsr_reg = p->controller_regs + PSYCHO_UE_AFSR;	unsigned long afar_reg = p->controller_regs + PSYCHO_UE_AFAR;	unsigned long afsr, afar, error_bits;	int reported;	/* Latch uncorrectable error status. */	afar = psycho_read(afar_reg);	afsr = psycho_read(afsr_reg);	/* Clear the primary/secondary error status bits. */	error_bits = afsr &		(PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |		 PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);	if (!error_bits)		return;	psycho_write(afsr_reg, error_bits);	/* Log the error. */	printk("PSYCHO%d: Uncorrectable Error, primary error type[%s]\n",	       p->index,	       (((error_bits & PSYCHO_UEAFSR_PPIO) ?		 "PIO" :		 ((error_bits & PSYCHO_UEAFSR_PDRD) ?		  "DMA Read" :		  ((error_bits & PSYCHO_UEAFSR_PDWR) ?		   "DMA Write" : "???")))));	printk("PSYCHO%d: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",	       p->index,	       (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,	       (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,	       (afsr & PSYCHO_UEAFSR_MID) >> 24UL,	       ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));	printk("PSYCHO%d: UE AFAR [%016lx]\n", p->index, afar);	printk("PSYCHO%d: UE Secondary errors [", p->index);	reported = 0;	if (afsr & PSYCHO_UEAFSR_SPIO) {		reported++;		printk("(PIO)");	}	if (afsr & PSYCHO_UEAFSR_SDRD) {		reported++;		printk("(DMA Read)");	}	if (afsr & PSYCHO_UEAFSR_SDWR) {		reported++;		printk("(DMA Write)");	}	if (!reported)		printk("(none)");	printk("]\n");	/* Interrogate IOMMU for error status. */	psycho_check_iommu_error(p, afsr, afar, UE_ERR);}/* Correctable Errors. */#define PSYCHO_CE_AFSR	0x0040UL#define  PSYCHO_CEAFSR_PPIO	0x8000000000000000 /* Primary PIO is cause         */#define  PSYCHO_CEAFSR_PDRD	0x4000000000000000 /* Primary DVMA read is cause   */#define  PSYCHO_CEAFSR_PDWR	0x2000000000000000 /* Primary DVMA write is cause  */#define  PSYCHO_CEAFSR_SPIO	0x1000000000000000 /* Secondary PIO is cause       */#define  PSYCHO_CEAFSR_SDRD	0x0800000000000000 /* Secondary DVMA read is cause */

⌨️ 快捷键说明

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