Skip to content

Commit

Permalink
Check prefetchable bit in BAR0 to use prefetchable registers
Browse files Browse the repository at this point in the history
Signed-off-by: Min Xu <[email protected]>
  • Loading branch information
mxu9 committed May 6, 2024
1 parent be608ff commit e828cba
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions teeio-validator/teeio_validator/pci_ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,12 @@

#define LINK_IDE_REGISTER_BLOCK_SIZE (sizeof(PCIE_LNK_IDE_STREAM_CTRL) + sizeof(PCIE_LINK_IDE_STREAM_STATUS))

typedef enum {
PCIE_DEVICE_BITS_WIDTH_32 = 0,
PCIE_DEVICE_BITS_WIDTH_64,
PCIE_DEVICE_BITS_WIDTH_INVALID
} PCIE_DEVICE_BITS_WIDTH;

const char* m_dev_bits_width[] = {
"32Bit",
"64Bit",
"Unknown"
};

#define PCIE_BAR0_OFFSETE 0x10
// PCIE Base 6.1 Table 7-9
#define PCIE_MEM_BASE_ADDR_MASK 0x6
#define PCIE_MEM_BASE_ADDR_64 0x4
// bit 3 prefetchable
#define PCIE_MEM_BASE_PREFETCHABLE_MASK 0x8

extern int m_dev_fp;
extern uint32_t g_doe_extended_offset;
Expand Down Expand Up @@ -578,21 +568,23 @@ bool populate_rid_assoc_reg_block(
return true;
}

PCIE_DEVICE_BITS_WIDTH check_device_bits_width(int fd)
// If the device is 64-bit and bit3 (prefetchable bit) is set, then use_prefetchable registers
bool check_use_prefetchable(int fd)
{
TEEIO_ASSERT(fd > 0);
bool use_prefetchable = false;

PCIE_DEVICE_BITS_WIDTH bits_width = PCIE_DEVICE_BITS_WIDTH_INVALID;
uint32_t bar0 = device_pci_read_32(PCIE_BAR0_OFFSETE, fd);
if((bar0 & PCIE_MEM_BASE_ADDR_MASK) == PCIE_MEM_BASE_ADDR_64) {
bits_width = PCIE_DEVICE_BITS_WIDTH_64;
} else {
bits_width = PCIE_DEVICE_BITS_WIDTH_32;
// check bit 3
if((bar0 & PCIE_MEM_BASE_PREFETCHABLE_MASK) != 0) {
use_prefetchable = true;
}
}

TEEIO_DEBUG((TEEIO_DEBUG_INFO, "Device bits width: %s\n", m_dev_bits_width[bits_width]));
TEEIO_DEBUG((TEEIO_DEBUG_INFO, "Device bar0 is 0x%08x, use_prefetchable = %d\n", bar0, use_prefetchable));

return bits_width;
return use_prefetchable;
}

bool populate_addr_assoc_reg_block(
Expand All @@ -608,12 +600,7 @@ bool populate_addr_assoc_reg_block(
return false;
}

PCIE_DEVICE_BITS_WIDTH bits_width = check_device_bits_width(cfg_space_fd);
if(bits_width == PCIE_DEVICE_BITS_WIDTH_INVALID) {
return false;
}

bool use_prefetch_memory = bits_width == PCIE_DEVICE_BITS_WIDTH_64;
bool use_prefetch_memory = check_use_prefetchable(cfg_space_fd);
int mem_base_offset = MEMORY_BASE_OFFSET;

if(use_prefetch_memory) {
Expand Down

0 comments on commit e828cba

Please sign in to comment.