VirtualBox

Changeset 32734 in vbox


Ignore:
Timestamp:
Sep 23, 2010 3:57:28 PM (14 years ago)
Author:
vboxsync
Message:

PCI: better accessors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/pci.h

    r32722 r32734  
    198198#define  VBOX_PCI_STATUS_DETECTED_PARITY     0x8000 /* Set on parity error */
    199199
     200
     201/* Command bitmask */
     202#define  VBOX_PCI_COMMAND_IO           0x1     /* Enable response in I/O space */
     203#define  VBOX_PCI_COMMAND_MEMORY       0x2     /* Enable response in Memory space */
     204#define  VBOX_PCI_COMMAND_MASTER       0x4     /* Enable bus mastering */
     205#define  VBOX_PCI_COMMAND_SPECIAL      0x8     /* Enable response to special cycles */
     206#define  VBOX_PCI_COMMAND_INVALIDATE   0x10    /* Use memory write and invalidate */
     207#define  VBOX_PCI_COMMAND_VGA_PALETTE  0x20    /* Enable palette snooping */
     208#define  VBOX_PCI_COMMAND_PARITY       0x40    /* Enable parity checking */
     209#define  VBOX_PCI_COMMAND_WAIT         0x80    /* Enable address/data stepping */
     210#define  VBOX_PCI_COMMAND_SERR         0x100   /* Enable SERR */
     211#define  VBOX_PCI_COMMAND_FAST_BACK    0x200   /* Enable back-to-back writes */
     212#define  VBOX_PCI_COMMAND_INTX_DISABLE 0x400   /* INTx Emulation Disable */
     213
     214
    200215/* Capability list values (capability offset 0) */
    201216/* Next  value pointer in offset 1, or 0 if none */
     
    218233#define  VBOX_PCI_CAP_ID_AF          0x13    /* PCI Advanced Features */
    219234
    220 /* MSI flags (capability offset 2) */
     235/* Extended Capabilities (PCI-X 2.0 and Express)*/
     236#define  VBOX_PCI_EXT_CAP_ID_ERR     0x01
     237#define  VBOX_PCI_EXT_CAP_ID_VC      0x02
     238#define  VBOX_PCI_EXT_CAP_ID_DSN     0x03
     239#define  VBOX_PCI_EXT_CAP_ID_PWR     0x04
     240#define  VBOX_PCI_EXT_CAP_ID_ARI     0x0e
     241#define  VBOX_PCI_EXT_CAP_ID_ATS     0x0f
     242#define  VBOX_PCI_EXT_CAP_ID_SRIOV   0x10
     243
     244
     245/* MSI flags (2 bytes, capability offset 2) */
    221246#define  VBOX_PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
    222247#define  VBOX_PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured */
     
    225250#define  VBOX_PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
    226251
    227 /* MSI-X flags (capability offset 2) */
    228 #define  VBOX_PCI_MSIX_FLAGS_QSIZE   0x07FF
     252/* MSI-X flags (2 bytes, capability offset 2) */
    229253#define  VBOX_PCI_MSIX_FLAGS_ENABLE  0x8000
    230 #define  PCI_MSIX_FLAGS_MASKALL      0x4000
    231 #define  PCI_MSIX_FLAGS_BIRMASK      0x0007
     254#define  VBOX_PCI_MSIX_FLAGS_MASKALL      0x4000
     255#define  VBOX_PCI_MSIX_FLAGS_BIRMASK      0x0007
    232256
    233257/* Power management flags (2 bytes, capability offset 2) */
     
    351375} PCIDEVICE;
    352376
     377/* @todo: handle extended space access */
     378DECLINLINE(void)     PCIDevSetByte(PPCIDEVICE pPciDev, uint32_t uOffset, uint8_t u8Value)
     379{
     380    pPciDev->config[uOffset]   = u8Value;
     381}
     382
     383DECLINLINE(uint8_t)  PCIDevGetByte(PPCIDEVICE pPciDev, uint32_t uOffset)
     384{
     385    return pPciDev->config[uOffset];
     386}
     387
     388DECLINLINE(void)     PCIDevSetWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint16_t u16Value)
     389{
     390    *(uint16_t*)&pPciDev->config[uOffset] = RT_H2LE_U16(u16Value);
     391}
     392
     393DECLINLINE(uint16_t) PCIDevGetWord(PPCIDEVICE pPciDev, uint32_t uOffset)
     394{
     395    uint16_t u16Value = *(uint16_t*)&pPciDev->config[uOffset];
     396    return RT_H2LE_U16(u16Value);
     397}
     398
     399DECLINLINE(void)     PCIDevSetDWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint32_t u32Value)
     400{
     401    *(uint32_t*)&pPciDev->config[uOffset] = RT_H2LE_U32(u32Value);
     402}
     403
     404DECLINLINE(uint32_t) PCIDevGetDWord(PPCIDEVICE pPciDev, uint32_t uOffset)
     405{
     406    uint32_t u32Value = *(uint32_t*)&pPciDev->config[uOffset];
     407    return RT_H2LE_U32(u32Value);
     408}
     409
     410DECLINLINE(void)     PCIDevSetQWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint64_t u64Value)
     411{
     412    *(uint64_t*)&pPciDev->config[uOffset] = RT_H2LE_U64(u64Value);
     413}
     414
     415DECLINLINE(uint64_t) PCIDevGetQWord(PPCIDEVICE pPciDev, uint32_t uOffset)
     416{
     417    uint64_t u64Value = *(uint64_t*)&pPciDev->config[uOffset];
     418    return RT_H2LE_U64(u64Value);
     419}
    353420
    354421/**
     
    359426DECLINLINE(void) PCIDevSetVendorId(PPCIDEVICE pPciDev, uint16_t u16VendorId)
    360427{
    361     u16VendorId = RT_H2LE_U16(u16VendorId);
    362     pPciDev->config[VBOX_PCI_VENDOR_ID]     = u16VendorId & 0xff;
    363     pPciDev->config[VBOX_PCI_VENDOR_ID + 1] = u16VendorId >> 8;
     428    PCIDevSetWord(pPciDev, VBOX_PCI_VENDOR_ID, u16VendorId);
    364429}
    365430
     
    371436DECLINLINE(uint16_t) PCIDevGetVendorId(PPCIDEVICE pPciDev)
    372437{
    373     return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_VENDOR_ID], pPciDev->config[VBOX_PCI_VENDOR_ID + 1]));
     438    return PCIDevGetWord(pPciDev, VBOX_PCI_VENDOR_ID);
    374439}
    375440
     
    382447DECLINLINE(void) PCIDevSetDeviceId(PPCIDEVICE pPciDev, uint16_t u16DeviceId)
    383448{
    384     u16DeviceId = RT_H2LE_U16(u16DeviceId);
    385     pPciDev->config[VBOX_PCI_DEVICE_ID]     = u16DeviceId & 0xff;
    386     pPciDev->config[VBOX_PCI_DEVICE_ID + 1] = u16DeviceId >> 8;
     449    PCIDevSetWord(pPciDev, VBOX_PCI_DEVICE_ID, u16DeviceId);
    387450}
    388451
     
    394457DECLINLINE(uint16_t) PCIDevGetDeviceId(PPCIDEVICE pPciDev)
    395458{
    396     return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_DEVICE_ID], pPciDev->config[VBOX_PCI_DEVICE_ID + 1]));
    397 }
    398 
     459    return PCIDevGetWord(pPciDev, VBOX_PCI_DEVICE_ID);
     460}
    399461
    400462/**
     
    406468DECLINLINE(void) PCIDevSetCommand(PPCIDEVICE pPciDev, uint16_t u16Command)
    407469{
    408     u16Command = RT_H2LE_U16(u16Command);
    409     pPciDev->config[VBOX_PCI_COMMAND]     = u16Command & 0xff;
    410     pPciDev->config[VBOX_PCI_COMMAND + 1] = u16Command >> 8;
     470    PCIDevSetWord(pPciDev, VBOX_PCI_COMMAND, u16Command);
    411471}
    412472
     
    419479DECLINLINE(uint16_t) PCIDevGetCommand(PPCIDEVICE pPciDev)
    420480{
    421     return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_COMMAND], pPciDev->config[VBOX_PCI_COMMAND + 1]));
     481    return PCIDevGetWord(pPciDev, VBOX_PCI_COMMAND);
    422482}
    423483
     
    431491DECLINLINE(void) PCIDevSetStatus(PPCIDEVICE pPciDev, uint16_t u16Status)
    432492{
    433     u16Status = RT_H2LE_U16(u16Status);
    434     pPciDev->config[VBOX_PCI_STATUS]     = u16Status & 0xff;
    435     pPciDev->config[VBOX_PCI_STATUS + 1] = u16Status >> 8;
     493    PCIDevSetWord(pPciDev, VBOX_PCI_STATUS, u16Status);
    436494}
    437495
     
    445503DECLINLINE(void) PCIDevSetRevisionId(PPCIDEVICE pPciDev, uint8_t u8RevisionId)
    446504{
    447     pPciDev->config[VBOX_PCI_REVISION_ID] = u8RevisionId;
     505    PCIDevSetByte(pPciDev, VBOX_PCI_REVISION_ID, u8RevisionId);
    448506}
    449507
     
    457515DECLINLINE(void) PCIDevSetClassProg(PPCIDEVICE pPciDev, uint8_t u8ClassProg)
    458516{
    459     pPciDev->config[VBOX_PCI_CLASS_PROG] = u8ClassProg;
     517    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_PROG, u8ClassProg);
    460518}
    461519
     
    469527DECLINLINE(void) PCIDevSetClassSub(PPCIDEVICE pPciDev, uint8_t u8SubClass)
    470528{
    471     pPciDev->config[VBOX_PCI_CLASS_SUB] = u8SubClass;
     529    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_SUB, u8SubClass);
    472530}
    473531
     
    481539DECLINLINE(void) PCIDevSetClassBase(PPCIDEVICE pPciDev, uint8_t u8BaseClass)
    482540{
    483     pPciDev->config[VBOX_PCI_CLASS_BASE] = u8BaseClass;
     541    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_BASE, u8BaseClass);
    484542}
    485543
     
    492550DECLINLINE(void) PCIDevSetHeaderType(PPCIDEVICE pPciDev, uint8_t u8HdrType)
    493551{
    494     pPciDev->config[VBOX_PCI_HEADER_TYPE] = u8HdrType;
     552    PCIDevSetByte(pPciDev, VBOX_PCI_HEADER_TYPE, u8HdrType);
    495553}
    496554
     
    503561DECLINLINE(uint8_t) PCIDevGetHeaderType(PPCIDEVICE pPciDev)
    504562{
    505     return pPciDev->config[VBOX_PCI_HEADER_TYPE];
     563    return PCIDevGetByte(pPciDev, VBOX_PCI_HEADER_TYPE);
    506564}
    507565
     
    514572DECLINLINE(void) PCIDevSetBIST(PPCIDEVICE pPciDev, uint8_t u8Bist)
    515573{
    516     pPciDev->config[VBOX_PCI_BIST] = u8Bist;
     574    PCIDevSetByte(pPciDev, VBOX_PCI_BIST, u8Bist);
    517575}
    518576
     
    525583DECLINLINE(uint8_t) PCIDevGetBIST(PPCIDEVICE pPciDev)
    526584{
    527     return pPciDev->config[VBOX_PCI_BIST];
     585    return PCIDevGetByte(pPciDev, VBOX_PCI_BIST);
    528586}
    529587
     
    564622    }
    565623
    566     u32Addr = RT_H2LE_U32(u32Addr);
    567     pPciDev->config[iReg]     = u32Addr         & 0xff;
    568     pPciDev->config[iReg + 1] = (u32Addr >>  8) & 0xff;
    569     pPciDev->config[iReg + 2] = (u32Addr >> 16) & 0xff;
    570     pPciDev->config[iReg + 3] = (u32Addr >> 24) & 0xff;
     624    PCIDevSetDWord(pPciDev, iReg, u32Addr);
    571625}
    572626
     
    580634DECLINLINE(void) PCIDevSetSubSystemVendorId(PPCIDEVICE pPciDev, uint16_t u16SubSysVendorId)
    581635{
    582     u16SubSysVendorId = RT_H2LE_U16(u16SubSysVendorId);
    583     pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID]     = u16SubSysVendorId & 0xff;
    584     pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1] = u16SubSysVendorId >> 8;
     636    PCIDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID, u16SubSysVendorId);
    585637}
    586638
     
    592644DECLINLINE(uint16_t) PCIDevGetSubSystemVendorId(PPCIDEVICE pPciDev)
    593645{
    594     return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1]));
     646    return PCIDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID);
    595647}
    596648
     
    604656DECLINLINE(void) PCIDevSetSubSystemId(PPCIDEVICE pPciDev, uint16_t u16SubSystemId)
    605657{
    606     u16SubSystemId = RT_H2LE_U16(u16SubSystemId);
    607     pPciDev->config[VBOX_PCI_SUBSYSTEM_ID]     = u16SubSystemId & 0xff;
    608     pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1] = u16SubSystemId >> 8;
     658    PCIDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID, u16SubSystemId);
    609659}
    610660
     
    616666DECLINLINE(uint16_t) PCIDevGetSubSystemId(PPCIDEVICE pPciDev)
    617667{
    618     return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1]));
     668    return PCIDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID);
    619669}
    620670
     
    627677DECLINLINE(void) PCIDevSetCapabilityList(PPCIDEVICE pPciDev, uint8_t u8Offset)
    628678{
    629     pPciDev->config[VBOX_PCI_CAPABILITY_LIST] = u8Offset;
     679    PCIDevSetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST, u8Offset);
    630680}
    631681
     
    638688DECLINLINE(uint8_t) PCIDevGetCapabilityList(PPCIDEVICE pPciDev)
    639689{
    640     return pPciDev->config[VBOX_PCI_CAPABILITY_LIST];
     690    return PCIDevGetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST);
    641691}
    642692
     
    649699DECLINLINE(void) PCIDevSetInterruptLine(PPCIDEVICE pPciDev, uint8_t u8Line)
    650700{
    651     pPciDev->config[VBOX_PCI_INTERRUPT_LINE] = u8Line;
     701    PCIDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE, u8Line);
    652702}
    653703
     
    660710DECLINLINE(uint8_t) PCIDevGetInterruptLine(PPCIDEVICE pPciDev)
    661711{
    662     return pPciDev->config[VBOX_PCI_INTERRUPT_LINE];
     712    return PCIDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE);
    663713}
    664714
     
    671721DECLINLINE(void) PCIDevSetInterruptPin(PPCIDEVICE pPciDev, uint8_t u8Pin)
    672722{
    673     pPciDev->config[VBOX_PCI_INTERRUPT_PIN] = u8Pin;
     723    PCIDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN, u8Pin);
    674724}
    675725
     
    683733DECLINLINE(uint8_t) PCIDevGetInterruptPin(PPCIDEVICE pPciDev)
    684734{
    685     return pPciDev->config[VBOX_PCI_INTERRUPT_PIN];
     735    return PCIDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN);
    686736}
    687737
     
    690740
    691741#endif
    692 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette