Changeset 36153 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Mar 3, 2011 4:14:59 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Bus/DevPciIch9.cpp
r36138 r36153 248 248 PDMBOTHCBDECL(int) ich9pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb) 249 249 { 250 Log (("ich9pciIOPortAddressWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb));250 LogFlow(("ich9pciIOPortAddressWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb)); 251 251 NOREF(pvUser); 252 252 if (cb == 4) … … 282 282 *pu32 = pThis->uConfigReg; 283 283 PCI_UNLOCK(pDevIns); 284 Log (("pciIOPortAddressRead: Port=%#x cb=%d -> %#x\n", Port, cb, *pu32));284 LogFlow(("pciIOPortAddressRead: Port=%#x cb=%d -> %#x\n", Port, cb, *pu32)); 285 285 return VINF_SUCCESS; 286 286 } … … 329 329 #ifdef IN_RING3 330 330 R3PTRTYPE(PCIDevice *) aDev = pGlobals->aPciBus.apDevices[pAddr->iDeviceFunc]; 331 Log(("ich9pciConfigWrite: %s: addr=%02x val=%08x len=%d\n", aDev->name, pAddr->iRegister, val, cb));332 331 aDev->Int.s.pfnConfigWrite(aDev, pAddr->iRegister, val, cb); 333 332 #else … … 383 382 PDMBOTHCBDECL(int) ich9pciIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb) 384 383 { 385 Log (("pciIOPortDataWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb));384 LogFlow(("pciIOPortDataWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb)); 386 385 NOREF(pvUser); 387 386 int rc = VINF_SUCCESS; … … 437 436 R3PTRTYPE(PCIDevice *) aDev = pGlobals->aPciBus.apDevices[pPciAddr->iDeviceFunc]; 438 437 *pu32 = aDev->Int.s.pfnConfigRead(aDev, pPciAddr->iRegister, cb); 439 Log(("ich9pciDataReadAddr: %s: addr=%02x val=%08x len=%d\n", aDev->name, pPciAddr->iRegister, *pu32, cb));440 438 #else 441 439 rc = rcReschedule; … … 448 446 449 447 out: 450 Log 2(("ich9pciDataReadAddr: %02x:%02x:%02x reg %x(%d) gave %x %Rrc\n",448 Log3(("ich9pciDataReadAddr: %02x:%02x:%02x reg %x(%d) gave %x %Rrc\n", 451 449 pPciAddr->iBus, pPciAddr->iDeviceFunc >> 3, pPciAddr->iDeviceFunc & 0x7, pPciAddr->iRegister, 452 450 cb, *pu32, rc)); … … 494 492 int rc = ich9pciDataRead(PDMINS_2_DATA(pDevIns, PPCIGLOBALS), Port, cb, pu32); 495 493 PCI_UNLOCK(pDevIns); 496 Log (("pciIOPortDataRead: Port=%#x cb=%#x -> %#x (%Rrc)\n", Port, cb, *pu32, rc));494 LogFlow(("pciIOPortDataRead: Port=%#x cb=%#x -> %#x (%Rrc)\n", Port, cb, *pu32, rc)); 497 495 return rc; 498 496 } … … 701 699 uint32_t uSecondary = PCIDevGetByte(pBridge, VBOX_PCI_SECONDARY_BUS); 702 700 uint32_t uSubordinate = PCIDevGetByte(pBridge, VBOX_PCI_SUBORDINATE_BUS); 703 Log 2(("ich9pciFindBridge on bus %p, bridge %d: %d in %d..%d\n", pBus, iBridge, iBus, uSecondary, uSubordinate));701 Log3(("ich9pciFindBridge on bus %p, bridge %d: %d in %d..%d\n", pBus, iBridge, iBus, uSecondary, uSubordinate)); 704 702 if (iBus >= uSecondary && iBus <= uSubordinate) 705 703 return pBridge; … … 708 706 /* Nothing found. */ 709 707 return NULL; 708 } 709 710 static uint32_t ich9pciGetCfg(PCIDevice* aDev, int32_t iRegister, int cb) 711 { 712 return aDev->Int.s.pfnConfigRead(aDev, iRegister, cb); 713 } 714 715 static uint8_t ich9pciGetByte(PCIDevice* aDev, int32_t iRegister) 716 { 717 return (uint8_t)ich9pciGetCfg(aDev, iRegister, 1); 718 } 719 720 static uint16_t ich9pciGetWord(PCIDevice* aDev, int32_t iRegister) 721 { 722 return (uint16_t)ich9pciGetCfg(aDev, iRegister, 2); 723 } 724 725 static uint32_t ich9pciGetDWord(PCIDevice* aDev, int32_t iRegister) 726 { 727 return (uint32_t)ich9pciGetCfg(aDev, iRegister, 4); 710 728 } 711 729 … … 757 775 { 758 776 PPCIBUS pBus = pDev->Int.s.CTX_SUFF(pBus); 759 uint 32_t uLast, uNew;760 761 int iCmd = PCIDevGetCommand(pDev);777 uint64_t uLast, uNew; 778 779 int iCmd = ich9pciGetWord(pDev, VBOX_PCI_COMMAND); 762 780 for (int iRegion = 0; iRegion < PCI_NUM_REGIONS; iRegion++) 763 781 { 764 782 PCIIORegion* pRegion = &pDev->Int.s.aIORegions[iRegion]; 765 uint32_t uConfigReg = ich9pciGetRegionReg(iRegion);766 int 32_t iRegionSize = pRegion->size;783 uint32_t uConfigReg = ich9pciGetRegionReg(iRegion); 784 int64_t iRegionSize = pRegion->size; 767 785 int rc; 768 786 … … 770 788 continue; 771 789 772 AssertMsg((pRegion->type & PCI_ADDRESS_SPACE_BAR64) == 0, ("64-bit BARs not yet implemented\n"));790 bool f64Bit = (pRegion->type & PCI_ADDRESS_SPACE_BAR64) != 0; 773 791 774 792 if (pRegion->type & PCI_ADDRESS_SPACE_IO) … … 778 796 { 779 797 /* IO access allowed */ 780 uNew = ich9pci ConfigReadDev(pDev, uConfigReg, 4);798 uNew = ich9pciGetDWord(pDev, uConfigReg); 781 799 uNew &= ~(iRegionSize - 1); 782 800 uLast = uNew + iRegionSize - 1; … … 792 810 if (iCmd & PCI_COMMAND_MEMACCESS) 793 811 { 794 uNew = ich9pciConfigReadDev(pDev, uConfigReg, 4); 812 uNew = ich9pciGetDWord(pDev, uConfigReg); 813 814 if (f64Bit) 815 { 816 uNew |= ((uint64_t)ich9pciGetDWord(pDev, uConfigReg+4)) << 32; 817 if (uNew > UINT64_C(0x0000010000000000)) 818 { 819 /* Workaround for REM being unhapping with mapping very lange 64-bit addresses */ 820 Log(("Ignoring too 64-bit BAR: %llx\n", uNew)); 821 uNew = INVALID_PCI_ADDRESS; 822 } 823 } 824 795 825 /* the ROM slot has a specific enable bit */ 796 826 if (iRegion == PCI_ROM_SLOT && !(uNew & 1)) … … 819 849 if (pRegion->addr != INVALID_PCI_ADDRESS) 820 850 { 851 821 852 /* finally, map the region */ 822 853 rc = pRegion->map_func(pDev, iRegion, … … 1512 1543 } 1513 1544 1514 static void ich9pciSetRegionAddress(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDevFn, int iRegion, uint 32_t addr)1545 static void ich9pciSetRegionAddress(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDevFn, int iRegion, uint64_t addr) 1515 1546 { 1516 1547 uint32_t uReg = ich9pciGetRegionReg(iRegion); … … 1520 1551 /* Read command register. */ 1521 1552 uint16_t uCmd = ich9pciConfigRead(pGlobals, uBus, uDevFn, VBOX_PCI_COMMAND, 2); 1553 1554 Log(("Set region address: %02x:%02x.%d region %d address=%lld\n", 1555 uBus, uDevFn>>3, uDevFn&7, addr)); 1522 1556 1523 1557 if ( iRegion == PCI_ROM_SLOT ) … … 1528 1562 uCmd |= PCI_COMMAND_MEMACCESS; /* Enable MMIO access. */ 1529 1563 1564 bool f64Bit = (uResourceType & PCI_ADDRESS_SPACE_BAR64) != 0; 1565 1530 1566 /* Write address of the device. */ 1531 ich9pciConfigWrite(pGlobals, uBus, uDevFn, uReg, addr, 4); 1567 ich9pciConfigWrite(pGlobals, uBus, uDevFn, uReg, (uint32_t)addr, 4); 1568 if (f64Bit) 1569 ich9pciConfigWrite(pGlobals, uBus, uDevFn, uReg + 4, (uint32_t)(addr >> 32), 4); 1532 1570 1533 1571 /* enable memory mappings */ … … 1604 1642 static void ich9pciBiosInitDevice(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDevFn) 1605 1643 { 1606 uint32_t *paddr;1607 1644 uint16_t uDevClass, uVendor, uDevice; 1608 1645 uint8_t uCmd; 1609 1646 1610 1647 uDevClass = ich9pciConfigRead(pGlobals, uBus, uDevFn, VBOX_PCI_CLASS_DEVICE, 2); 1611 1648 uVendor = ich9pciConfigRead(pGlobals, uBus, uDevFn, VBOX_PCI_VENDOR_ID, 2); … … 1662 1699 are cleared. . */ 1663 1700 uint8_t u8ResourceType = ich9pciConfigRead(pGlobals, uBus, uDevFn, u32Address, 1); 1664 ich9pciConfigWrite(pGlobals, uBus, uDevFn, u32Address, UINT32_C(0xffffffff), 4); 1665 uint32_t u32Size = ich9pciConfigRead(pGlobals, uBus, uDevFn, u32Address, 4); 1666 /* Clear resource information depending on resource type. */ 1667 if ((u8ResourceType & PCI_COMMAND_IOACCESS) == PCI_COMMAND_IOACCESS) /* I/O */ 1668 u32Size &= ~(0x01); 1669 else /* MMIO */ 1670 u32Size &= ~(0x0f); 1671 1701 1702 bool f64bit = (u8ResourceType & PCI_ADDRESS_SPACE_BAR64) != 0; 1672 1703 bool fIsPio = ((u8ResourceType & PCI_COMMAND_IOACCESS) == PCI_COMMAND_IOACCESS); 1673 /* 1674 * Invert all bits and add 1 to get size of the region. 1675 * (From PCI implementation note) 1676 */ 1677 if (fIsPio && (u32Size & UINT32_C(0xffff0000)) == 0) 1678 u32Size = (~(u32Size | UINT32_C(0xffff0000))) + 1; 1704 uint64_t cbRegSize64 = 0; 1705 1706 if (f64bit) 1707 { 1708 ich9pciConfigWrite(pGlobals, uBus, uDevFn, u32Address, UINT32_C(0xffffffff), 4); 1709 ich9pciConfigWrite(pGlobals, uBus, uDevFn, u32Address+4, UINT32_C(0xffffffff), 4); 1710 cbRegSize64 = ich9pciConfigRead(pGlobals, uBus, uDevFn, u32Address, 4); 1711 cbRegSize64 |= ((uint64_t)ich9pciConfigRead(pGlobals, uBus, uDevFn, u32Address+4, 4) << 32); 1712 cbRegSize64 &= ~UINT64_C(0x0f); 1713 cbRegSize64 = (~cbRegSize64) + 1; 1714 1715 /* No 64-bit PIO regions possible. */ 1716 Assert((u8ResourceType & PCI_COMMAND_IOACCESS) == 0); 1717 } 1679 1718 else 1680 u32Size = (~u32Size) + 1;1681 1682 Log(("%s: Size of region %u for device %d on bus %d is %u\n", __FUNCTION__, iRegion, uDevFn, uBus, u32Size));1683 1684 if (u32Size)1685 1719 { 1686 paddr = fIsPio ? &pGlobals->uPciBiosIo : &pGlobals->uPciBiosMmio; 1687 *paddr = (*paddr + u32Size - 1) & ~(u32Size - 1); 1720 uint32_t cbRegSize32; 1721 ich9pciConfigWrite(pGlobals, uBus, uDevFn, u32Address, UINT32_C(0xffffffff), 4); 1722 cbRegSize32 = ich9pciConfigRead(pGlobals, uBus, uDevFn, u32Address, 4); 1723 1724 /* Clear resource information depending on resource type. */ 1725 if (fIsPio) /* PIO */ 1726 cbRegSize32 &= ~UINT32_C(0x01); 1727 else /* MMIO */ 1728 cbRegSize32 &= ~UINT32_C(0x0f); 1729 1730 /* 1731 * Invert all bits and add 1 to get size of the region. 1732 * (From PCI implementation note) 1733 */ 1734 if (fIsPio && (cbRegSize32 & UINT32_C(0xffff0000)) == 0) 1735 cbRegSize32 = (~(cbRegSize32 | UINT32_C(0xffff0000))) + 1; 1736 else 1737 cbRegSize32 = (~cbRegSize32) + 1; 1738 1739 cbRegSize64 = cbRegSize32; 1740 } 1741 Assert(cbRegSize64 == (uint32_t)cbRegSize64); 1742 Log2(("%s: Size of region %u for device %d on bus %d is %lld\n", __FUNCTION__, iRegion, uDevFn, uBus, cbRegSize64)); 1743 1744 if (cbRegSize64) 1745 { 1746 uint32_t cbRegSize32 = (uint32_t)cbRegSize64; 1747 uint32_t* paddr = fIsPio ? &pGlobals->uPciBiosIo : &pGlobals->uPciBiosMmio; 1748 *paddr = (*paddr + cbRegSize32 - 1) & ~(cbRegSize32 - 1); 1688 1749 Log(("%s: Start address of %s region %u is %#x\n", __FUNCTION__, (fIsPio ? "I/O" : "MMIO"), iRegion, *paddr)); 1689 1750 ich9pciSetRegionAddress(pGlobals, uBus, uDevFn, iRegion, *paddr); 1690 *paddr += u32Size; 1691 Log(("%s: New address is %#x\n", __FUNCTION__, *paddr)); 1751 *paddr += cbRegSize32; 1752 Log2(("%s: New address is %#x\n", __FUNCTION__, *paddr)); 1753 1754 if (f64bit) 1755 iRegion++; /* skip next region */ 1692 1756 } 1693 1757 } … … 1916 1980 1917 1981 uint32_t addr = u32Address; 1918 bool fUpdateMappings = false; 1919 bool fP2PBridge = false; 1982 bool fUpdateMappings = false; 1983 bool fP2PBridge = false; 1984 bool fPassthrough = pciDevIsPassthrough(aDev); 1985 uint8_t u8HeaderType = ich9pciGetByte(aDev, VBOX_PCI_HEADER_TYPE); 1986 1920 1987 for (uint32_t i = 0; i < len; i++) 1921 1988 { 1922 1989 bool fWritable = false; 1923 1990 bool fRom = false; 1924 switch ( PCIDevGetHeaderType(aDev))1991 switch (u8HeaderType) 1925 1992 { 1926 1993 case 0x00: /* normal device */ … … 1981 2048 case VBOX_PCI_COMMAND: /* Command register, bits 0-7. */ 1982 2049 fUpdateMappings = true; 1983 PCIDevSetByte(aDev, addr, u8Val); 1984 break; 2050 goto default_case; 1985 2051 case VBOX_PCI_COMMAND+1: /* Command register, bits 8-15. */ 1986 2052 /* don't change reserved bits (11-15) */ 1987 2053 u8Val &= UINT32_C(~0xf8); 1988 2054 fUpdateMappings = true; 1989 PCIDevSetByte(aDev, addr, u8Val); 1990 break; 2055 goto default_case; 1991 2056 case VBOX_PCI_STATUS: /* Status register, bits 0-7. */ 1992 2057 /* don't change read-only bits => actually all lower bits are read-only */ 1993 2058 u8Val &= UINT32_C(~0xff); 1994 2059 /* status register, low part: clear bits by writing a '1' to the corresponding bit */ 1995 aDev->config[addr] &= ~u8Val; 2060 if (!fPassthrough) 2061 aDev->config[addr] &= ~u8Val; 1996 2062 break; 1997 2063 case VBOX_PCI_STATUS+1: /* Status register, bits 8-15. */ … … 1999 2065 u8Val &= UINT32_C(~0x06); 2000 2066 /* status register, high part: clear bits by writing a '1' to the corresponding bit */ 2001 aDev->config[addr] &= ~u8Val; 2067 if (!fPassthrough) 2068 aDev->config[addr] &= ~u8Val; 2002 2069 break; 2003 2070 case VBOX_PCI_ROM_ADDRESS: case VBOX_PCI_ROM_ADDRESS +1: case VBOX_PCI_ROM_ADDRESS +2: case VBOX_PCI_ROM_ADDRESS +3: … … 2017 2084 int iRegion = fRom ? VBOX_PCI_ROM_SLOT : (addr - VBOX_PCI_BASE_ADDRESS_0) >> 2; 2018 2085 int iOffset = addr & 0x3; 2019 ich9pciWriteBarByte(aDev, iRegion, iOffset, u8Val); 2086 if (!fPassthrough) 2087 ich9pciWriteBarByte(aDev, iRegion, iOffset, u8Val); 2020 2088 fUpdateMappings = true; 2021 2089 } … … 2024 2092 default: 2025 2093 default_case: 2026 if (fWritable )2094 if (fWritable && !fPassthrough) 2027 2095 PCIDevSetByte(aDev, addr, u8Val); 2028 2096 } … … 2199 2267 pHlp->pfnPrintf(pHlp, " "); 2200 2268 } 2201 }2202 static uint32_t ich9pciGetCfg(PCIDevice* aDev, int32_t iRegister, int cb)2203 {2204 return aDev->Int.s.pfnConfigRead(aDev, iRegister, cb);2205 }2206 2207 static uint8_t ich9pciGetByte(PCIDevice* aDev, int32_t iRegister)2208 {2209 return (uint8_t)ich9pciGetCfg(aDev, iRegister, 1);2210 }2211 2212 static uint16_t ich9pciGetWord(PCIDevice* aDev, int32_t iRegister)2213 {2214 return (uint16_t)ich9pciGetCfg(aDev, iRegister, 2);2215 }2216 2217 static uint32_t ich9pciGetDWord(PCIDevice* aDev, int32_t iRegister)2218 {2219 return (uint32_t)ich9pciGetCfg(aDev, iRegister, 4);2220 2269 } 2221 2270 … … 2258 2307 2259 2308 uint32_t u32Addr = ich9pciGetDWord(pPciDev, ich9pciGetRegionReg(iRegion)); 2260 const char * szDesc; 2261 2309 const char * pszDesc; 2310 char szDescBuf[128]; 2311 2312 bool f64Bit = (pRegion->type & PCI_ADDRESS_SPACE_BAR64); 2262 2313 if (pRegion->type & PCI_ADDRESS_SPACE_IO) 2263 2314 { 2264 szDesc = "IO";2315 pszDesc = "IO"; 2265 2316 u32Addr &= ~0x3; 2266 2317 } 2267 2318 else 2268 2319 { 2269 szDesc = "MMIO"; 2320 RTStrPrintf(szDescBuf, sizeof(szDescBuf), "MMIO%s%s", 2321 f64Bit ? "64" : "32", 2322 (pRegion->type & PCI_ADDRESS_SPACE_MEM_PREFETCH) ? " PREFETCH" : ""); 2323 pszDesc = szDescBuf; 2270 2324 u32Addr &= ~0xf; 2271 2325 } … … 2273 2327 printIndent(pHlp, iIndent + 2); 2274 2328 pHlp->pfnPrintf(pHlp, " %s region #%d: %x..%x\n", 2275 szDesc, iRegion, u32Addr, u32Addr+iRegionSize); 2329 pszDesc, iRegion, u32Addr, u32Addr+iRegionSize); 2330 if (f64Bit) 2331 iRegion++; 2276 2332 } 2277 2333 }
Note:
See TracChangeset
for help on using the changeset viewer.