Module Name: src Committed By: dyoung Date: Wed Aug 17 00:59:48 UTC 2011
Modified Files: src/sys/arch/powerpc/booke/pci: pq3pci.c src/sys/arch/x86/pci: pci_intr_machdep.c src/sys/dev/pci: pci_subr.c pcireg.h ppb.c Log Message: Redefine PCI_MSI_* and PCI_PCIE_* constants in terms of bits(3). Use named constants and more conventional variable names in pci_msi_establish() and pci_msi_disestablish(). Fix a couple of bugs: pci_msi_establish() returned a pointer to the struct intrhand instead of to the struct msi_hdl as it was intended to, and pci_msi_disestablish() did not free(9) the msi_hdl. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/arch/powerpc/booke/pci/pq3pci.c cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x86/pci/pci_intr_machdep.c cvs rdiff -u -r1.87 -r1.88 src/sys/dev/pci/pci_subr.c cvs rdiff -u -r1.72 -r1.73 src/sys/dev/pci/pcireg.h cvs rdiff -u -r1.45 -r1.46 src/sys/dev/pci/ppb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/powerpc/booke/pci/pq3pci.c diff -u src/sys/arch/powerpc/booke/pci/pq3pci.c:1.8 src/sys/arch/powerpc/booke/pci/pq3pci.c:1.9 --- src/sys/arch/powerpc/booke/pci/pq3pci.c:1.8 Wed Jun 22 18:06:34 2011 +++ src/sys/arch/powerpc/booke/pci/pq3pci.c Wed Aug 17 00:59:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pq3pci.c,v 1.8 2011/06/22 18:06:34 matt Exp $ */ +/* $NetBSD: pq3pci.c,v 1.9 2011/08/17 00:59:47 dyoung Exp $ */ /*- * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. * All rights reserved. @@ -44,7 +44,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.8 2011/06/22 18:06:34 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.9 2011/08/17 00:59:47 dyoung Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -1179,8 +1179,8 @@ break; msictl = pci_conf_read(pa->pa_pc, pa->pa_tag, msioff); msictl &= ~PCI_MSI_CTL_MSI_ENABLE; - msictl &= ~(PCI_MSI_CTL_MME_MASK << PCI_MSI_CTL_MME_SHIFT); - int rmsi = (msictl >> PCI_MSI_CTL_MMC_SHIFT) & PCI_MSI_CTL_MMC_MASK; + msictl &= ~PCI_MSI_CTL_MME_MASK; + int rmsi = __SHIFTOUT(msictl, PCI_MSI_CTL_MMC_MASK); pci_conf_write(pa->pa_pc, pa->pa_tag, msioff, msictl); pci_intr_handle_t handle = pq3pci_msi_alloc(IPL_VM, rmsi); struct pq3pci_msihand * const msih = pq3pci_msi_lookup(handle); Index: src/sys/arch/x86/pci/pci_intr_machdep.c diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.20 src/sys/arch/x86/pci/pci_intr_machdep.c:1.21 --- src/sys/arch/x86/pci/pci_intr_machdep.c:1.20 Mon Aug 1 11:08:03 2011 +++ src/sys/arch/x86/pci/pci_intr_machdep.c Wed Aug 17 00:59:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_intr_machdep.c,v 1.20 2011/08/01 11:08:03 drochner Exp $ */ +/* $NetBSD: pci_intr_machdep.c,v 1.21 2011/08/17 00:59:47 dyoung Exp $ */ /*- * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.20 2011/08/01 11:08:03 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.21 2011/08/17 00:59:47 dyoung Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -371,18 +371,17 @@ int (*func)(void *), void *arg) { int co; - void *ih; + struct intrhand *ih; struct msi_hdl *msih; struct cpu_info *ci; - struct intrsource *s; - u_int32_t cr; + struct intrsource *is; + pcireg_t reg; if (!pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSI, &co, 0)) return NULL; - ih = intr_establish(-1, &msi_pic, -1, IST_EDGE, level, - func, arg, 0); - if (!ih) + ih = intr_establish(-1, &msi_pic, -1, IST_EDGE, level, func, arg, 0); + if (ih == NULL) return NULL; msih = malloc(sizeof(*msih), M_DEVBUF, M_WAITOK); @@ -391,20 +390,23 @@ msih->tag = pa->pa_tag; msih->co = co; - ci = msih->ih->ih_cpu; - s = ci->ci_isources[msih->ih->ih_slot]; - cr = pci_conf_read(pa->pa_pc, pa->pa_tag, co); - pci_conf_write(pa->pa_pc, pa->pa_tag, co + 4, + ci = ih->ih_cpu; + is = ci->ci_isources[ih->ih_slot]; + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, co + PCI_MSI_CTL); + /* 0xfee00000 == IOAPIC_??? */ + pci_conf_write(pa->pa_pc, pa->pa_tag, co + PCI_MSI_MADDR64_LO, 0xfee00000 | ci->ci_cpuid << 12); - if (cr & 0x800000) { - pci_conf_write(pa->pa_pc, pa->pa_tag, co + 8, 0); - pci_conf_write(pa->pa_pc, pa->pa_tag, co + 12, - s->is_idtvec | 0x4000); + if (reg & PCI_MSI_CTL_64BIT_ADDR) { + pci_conf_write(pa->pa_pc, pa->pa_tag, co + PCI_MSI_MADDR64_HI, + 0); + pci_conf_write(pa->pa_pc, pa->pa_tag, co + PCI_MSI_MDATA64, + is->is_idtvec | 0x4000); } else - pci_conf_write(pa->pa_pc, pa->pa_tag, co + 8, - s->is_idtvec | 0x4000); - pci_conf_write(pa->pa_pc, pa->pa_tag, co, 0x10000); - return ih; + pci_conf_write(pa->pa_pc, pa->pa_tag, co + PCI_MSI_MDATA, + is->is_idtvec | 0x4000); + pci_conf_write(pa->pa_pc, pa->pa_tag, co + PCI_MSI_CTL, + PCI_MSI_CTL_MSI_ENABLE); + return msih; } void @@ -412,7 +414,8 @@ { struct msi_hdl *msih = ih; - pci_conf_write(msih->pc, msih->tag, msih->co, 0); + pci_conf_write(msih->pc, msih->tag, msih->co + PCI_MSI_CTL, 0); intr_disestablish(msih->ih); + free(msih, M_DEVBUF); } #endif Index: src/sys/dev/pci/pci_subr.c diff -u src/sys/dev/pci/pci_subr.c:1.87 src/sys/dev/pci/pci_subr.c:1.88 --- src/sys/dev/pci/pci_subr.c:1.87 Mon Jun 6 18:27:12 2011 +++ src/sys/dev/pci/pci_subr.c Wed Aug 17 00:59:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_subr.c,v 1.87 2011/06/06 18:27:12 msaitoh Exp $ */ +/* $NetBSD: pci_subr.c,v 1.88 2011/08/17 00:59:47 dyoung Exp $ */ /* * Copyright (c) 1997 Zubin D. Dittia. All rights reserved. @@ -40,7 +40,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.87 2011/06/06 18:27:12 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.88 2011/08/17 00:59:47 dyoung Exp $"); #ifdef _KERNEL_OPT #include "opt_pci.h" @@ -965,8 +965,8 @@ regs += o2i(capoff); ctl = *regs++; - mmc = (ctl >> PCI_MSI_CTL_MMC_SHIFT) & PCI_MSI_CTL_MMC_MASK; - mme = (ctl >> PCI_MSI_CTL_MME_SHIFT) & PCI_MSI_CTL_MME_MASK; + mmc = __SHIFTOUT(ctl, PCI_MSI_CTL_MMC_MASK); + mme = __SHIFTOUT(ctl, PCI_MSI_CTL_MME_MASK); printf("\n PCI Message Signaled Interrupt\n"); Index: src/sys/dev/pci/pcireg.h diff -u src/sys/dev/pci/pcireg.h:1.72 src/sys/dev/pci/pcireg.h:1.73 --- src/sys/dev/pci/pcireg.h:1.72 Mon Jun 6 18:27:12 2011 +++ src/sys/dev/pci/pcireg.h Wed Aug 17 00:59:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pcireg.h,v 1.72 2011/06/06 18:27:12 msaitoh Exp $ */ +/* $NetBSD: pcireg.h,v 1.73 2011/08/17 00:59:47 dyoung Exp $ */ /* * Copyright (c) 1995, 1996, 1999, 2000 @@ -479,15 +479,28 @@ #define PCI_VPD_DATAREG(ofs) ((ofs) + 4) #define PCI_VPD_OPFLAG 0x80000000 -#define PCI_MSI_CTL_PERVEC_MASK 0x01000000 -#define PCI_MSI_CTL_64BIT_ADDR 0x00800000 -#define PCI_MSI_CTL_MME_MASK 0x7 -#define PCI_MSI_CTL_MME_SHIFT 20 -#define PCI_MSI_CTL_MME(ofs) (((ofs) & PCI_MSI_CTL_MME_MASK) << PCI_MSI_CTL_MME_SHIFT) -#define PCI_MSI_CTL_MMC_MASK 0x7 -#define PCI_MSI_CTL_MMC_SHIFT 17 -#define PCI_MSI_CTL_MMC(ofs) (((ofs) >> PCI_MSI_CTL_MME_SHIFT) & PCI_MSI_CTL_MME_MASK) -#define PCI_MSI_CTL_MSI_ENABLE 0x00010000 +#define PCI_MSI_CTL 0x0 /* Message Control Register offset */ +#define PCI_MSI_MADDR 0x4 /* Message Address Register (least + * significant bits) offset + */ +#define PCI_MSI_MADDR64_LO 0x4 /* 64-bit Message Address Register + * (least significant bits) offset + */ +#define PCI_MSI_MADDR64_HI 0x8 /* 64-bit Message Address Register + * (most significant bits) offset + */ +#define PCI_MSI_MDATA 0x8 /* Message Data Register offset */ +#define PCI_MSI_MDATA64 0xC /* 64-bit Message Data Register + * offset + */ + +#define PCI_MSI_CTL_MASK __BITS(31, 16) +#define PCI_MSI_CTL_PERVEC_MASK __SHIFTIN(__BIT(8), PCI_MSI_CTL_MASK) +#define PCI_MSI_CTL_64BIT_ADDR __SHIFTIN(__BIT(7), PCI_MSI_CTL_MASK) +#define PCI_MSI_CTL_MME_MASK __SHIFTIN(__BITS(6, 4), PCI_MSI_CTL_MASK) +#define PCI_MSI_CTL_MMC_MASK __SHIFTIN(__BITS(3, 1), PCI_MSI_CTL_MASK) +#define PCI_MSI_CTL_MSI_ENABLE __SHIFTIN(__BIT(0), PCI_MSI_CTL_MASK) + /* * MSI Message Address is at offset 4. * MSI Message Upper Address (if 64bit) is at offset 8. @@ -614,54 +627,60 @@ /* * PCI Express; access via capability pointer. */ -#define PCI_PCIE_XCAP 0x00 -#define PCI_PCIE_XCAP_VER_MASK 0x000f0000 -#define PCI_PCIE_XCAP_VER_1_0 0x00010000 -#define PCI_PCIE_XCAP_VER_2_0 0x00020000 -#define PCI_PCIE_XCAP_TYPE_MASK 0x00f00000 -#define PCI_PCIE_XCAP_TYPE_PCIE_DEV 0x00000000 -#define PCI_PCIE_XCAP_TYPE_PCI_DEV 0x00100000 -#define PCI_PCIE_XCAP_TYPE_ROOT 0x00400000 -#define PCI_PCIE_XCAP_TYPE_UP 0x00500000 -#define PCI_PCIE_XCAP_TYPE_DOWN 0x00600000 -#define PCI_PCIE_XCAP_TYPE_PCIE2PCI 0x00700000 -#define PCI_PCIE_XCAP_TYPE_PCI2PCIE 0x00800000 -#define PCI_PCIE_XCAP_SI 0x01000000 -#define PCI_PCIE_DCAP 0x04 -#define PCI_PCIE_DCSR 0x08 -#define PCI_PCIE_DCSR_MAX_READ_REQ 0x7000 -#define PCI_PCIE_DCSR_ENA_NO_SNOOP 0x00000800 -#define PCI_PCIE_DCSR_CED 0x00010000 -#define PCI_PCIE_DCSR_NFED 0x00020000 -#define PCI_PCIE_DCSR_FED 0x00040000 -#define PCI_PCIE_DCSR_URD 0x00080000 +#define PCI_PCIE_XCAP 0x00 /* Capability List & Capabilities + * Register + */ +#define PCI_PCIE_XCAP_MASK __BITS(31, 16) +/* Capability Version */ +#define PCI_PCIE_XCAP_VER_MASK __SHIFTIN(__BITS(3, 0), PCI_PCIE_XCAP_MASK) +#define PCI_PCIE_XCAP_VER_1_0 __SHIFTIN(1, PCI_PCIE_XCAP_VER_MASK) +#define PCI_PCIE_XCAP_VER_2_0 __SHIFTIN(2, PCI_PCIE_XCAP_VER_MASK) +#define PCI_PCIE_XCAP_TYPE_MASK __SHIFTIN(__BITS(7, 4), PCI_PCIE_XCAP_MASK) +#define PCI_PCIE_XCAP_TYPE_PCIE_DEV __SHIFTIN(0x0, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_PCI_DEV __SHIFTIN(0x1, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_ROOT __SHIFTIN(0x4, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_UP __SHIFTIN(0x5, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_DOWN __SHIFTIN(0x6, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_PCIE2PCI __SHIFTIN(0x7, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_TYPE_PCI2PCIE __SHIFTIN(0x8, PCI_PCIE_XCAP_TYPE_MASK) +#define PCI_PCIE_XCAP_SI __SHIFTIN(__BIT(8), PCI_PCIE_XCAP_MASK) /* Slot Implemented */ +#define PCI_PCIE_DCAP 0x04 /* Device Capabilities Register */ +#define PCI_PCIE_DCSR 0x08 /* Device Control & Status Register */ +#define PCI_PCIE_DCSR_MAX_READ_REQ __BITS(14, 12) +#define PCI_PCIE_DCSR_ENA_NO_SNOOP __BIT(11) +#define PCI_PCIE_DCSR_CED __BIT(0 + 16) +#define PCI_PCIE_DCSR_NFED __BIT(1 + 16) +#define PCI_PCIE_DCSR_FED __BIT(2 + 16) +#define PCI_PCIE_DCSR_URD __BIT(3 + 16) #define PCI_PCIE_LCAP 0x0c -#define PCI_PCIE_LCSR 0x10 -#define PCI_PCIE_LCSR_ASPM_L0S 0x00000001 -#define PCI_PCIE_LCSR_ASPM_L1 0x00000002 -#define PCI_PCIE_SLCAP 0x14 -#define PCI_PCIE_SLCAP_ABP 0x00000001 -#define PCI_PCIE_SLCAP_PCP 0x00000002 -#define PCI_PCIE_SLCAP_MSP 0x00000004 -#define PCI_PCIE_SLCAP_AIP 0x00000008 -#define PCI_PCIE_SLCAP_PIP 0x00000010 -#define PCI_PCIE_SLCAP_HPS 0x00000020 -#define PCI_PCIE_SLCAP_HPC 0x00000040 +#define PCI_PCIE_LCSR 0x10 /* Link Control & Status Register */ +#define PCI_PCIE_LCSR_ASPM_L0S __BIT(0) +#define PCI_PCIE_LCSR_ASPM_L1 __BIT(1) +#define PCI_PCIE_SLCAP 0x14 /* Slot Capabilities Register */ +#define PCI_PCIE_SLCAP_ABP __BIT(0) /* Attention Button Present */ +#define PCI_PCIE_SLCAP_PCP __BIT(1) /* Power Controller Present */ +#define PCI_PCIE_SLCAP_MSP __BIT(2) /* MRL Sensor Present */ +#define PCI_PCIE_SLCAP_AIP __BIT(3) /* Attention Indicator + * Present + */ +#define PCI_PCIE_SLCAP_PIP __BIT(4) /* Power Indicator Present */ +#define PCI_PCIE_SLCAP_HPS __BIT(5) /* Hot-Plug Surprise */ +#define PCI_PCIE_SLCAP_HPC __BIT(6) /* Hot-Plug Capable */ #define PCI_PCIE_SLCSR 0x18 -#define PCI_PCIE_SLCSR_ABE 0x00000001 -#define PCI_PCIE_SLCSR_PFE 0x00000002 -#define PCI_PCIE_SLCSR_MSE 0x00000004 -#define PCI_PCIE_SLCSR_PDE 0x00000008 -#define PCI_PCIE_SLCSR_CCE 0x00000010 -#define PCI_PCIE_SLCSR_HPE 0x00000020 -#define PCI_PCIE_SLCSR_ABP 0x00010000 -#define PCI_PCIE_SLCSR_PFD 0x00020000 -#define PCI_PCIE_SLCSR_MSC 0x00040000 -#define PCI_PCIE_SLCSR_PDC 0x00080000 -#define PCI_PCIE_SLCSR_CC 0x00100000 -#define PCI_PCIE_SLCSR_MS 0x00200000 -#define PCI_PCIE_SLCSR_PDS 0x00400000 -#define PCI_PCIE_SLCSR_LACS 0x01000000 +#define PCI_PCIE_SLCSR_ABE __BIT(0) +#define PCI_PCIE_SLCSR_PFE __BIT(1) +#define PCI_PCIE_SLCSR_MSE __BIT(2) +#define PCI_PCIE_SLCSR_PDE __BIT(3) +#define PCI_PCIE_SLCSR_CCE __BIT(4) +#define PCI_PCIE_SLCSR_HPE __BIT(5) +#define PCI_PCIE_SLCSR_ABP __BIT(0 + 16) +#define PCI_PCIE_SLCSR_PFD __BIT(1 + 16) +#define PCI_PCIE_SLCSR_MSC __BIT(2 + 16) +#define PCI_PCIE_SLCSR_PDC __BIT(3 + 16) +#define PCI_PCIE_SLCSR_CC __BIT(4 + 16) +#define PCI_PCIE_SLCSR_MS __BIT(5 + 16) +#define PCI_PCIE_SLCSR_PDS __BIT(6 + 16) +#define PCI_PCIE_SLCSR_LACS __BIT(8 + 16) #define PCI_PCIE_RCR 0x1c #define PCI_PCIE_RSR 0x20 #define PCI_PCIE_DCAP2 0x24 Index: src/sys/dev/pci/ppb.c diff -u src/sys/dev/pci/ppb.c:1.45 src/sys/dev/pci/ppb.c:1.46 --- src/sys/dev/pci/ppb.c:1.45 Mon Jan 10 14:19:36 2011 +++ src/sys/dev/pci/ppb.c Wed Aug 17 00:59:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ppb.c,v 1.45 2011/01/10 14:19:36 cegger Exp $ */ +/* $NetBSD: ppb.c,v 1.46 2011/08/17 00:59:47 dyoung Exp $ */ /* * Copyright (c) 1996, 1998 Christopher G. Demetriou. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.45 2011/01/10 14:19:36 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.46 2011/08/17 00:59:47 dyoung Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -106,8 +106,9 @@ aprint_normal("2.0"); break; default: - aprint_normal_dev(self, "version unsupported (0x%x)\n", - (reg & PCI_PCIE_XCAP_VER_MASK) >> 16); + aprint_normal_dev(self, + "version unsupported (0x%" PRIxMAX ")\n", + __SHIFTOUT(reg, PCI_PCIE_XCAP_VER_MASK)); return; } aprint_normal(" <"); @@ -134,8 +135,8 @@ aprint_normal("PCI/PCI-X to PCI-E Bridge"); break; default: - aprint_normal("Device/Port Type 0x%x", - (reg & PCI_PCIE_XCAP_TYPE_MASK) >> 20); + aprint_normal("Device/Port Type 0x%" PRIxMAX, + __SHIFTOUT(reg, PCI_PCIE_XCAP_TYPE_MASK)); break; } aprint_normal(">\n");