| 1 |
|
| 2 |
|
| 3 |
#define __SIMPLE_DEVICE__ |
| 4 |
|
| 5 |
#include <device/pci_ops.h> |
| 6 |
#include <intelblocks/systemagent_server.h> |
| 7 |
|
| 8 |
static uint32_t pci_moving_config32(pci_devfn_t dev, unsigned int reg) |
| 9 |
{ |
| 10 |
uint32_t value, ones, zeroes; |
| 11 |
|
| 12 |
value = pci_read_config32(dev, reg); |
| 13 |
|
| 14 |
pci_write_config32(dev, reg, 0xffffffff); |
| 15 |
ones = pci_read_config32(dev, reg); |
| 16 |
|
| 17 |
pci_write_config32(dev, reg, 0x00000000); |
| 18 |
zeroes = pci_read_config32(dev, reg); |
| 19 |
|
| 20 |
pci_write_config32(dev, reg, value); |
| 21 |
|
| 22 |
return ones ^ zeroes; |
| 23 |
} |
| 24 |
|
| 25 |
uint64_t sa_server_read_map_entry(pci_devfn_t dev, |
| 26 |
const struct sa_server_mem_map_descriptor *entry) |
| 27 |
{ |
| 28 |
uint64_t value = 0; |
| 29 |
uint32_t alignment = entry->alignment; |
| 30 |
|
| 31 |
if (entry->is_64_bit) { |
| 32 |
value = pci_s_read_config32(dev, entry->reg_offset + 4); |
| 33 |
value <<= 32; |
| 34 |
} |
| 35 |
|
| 36 |
value |= pci_s_read_config32(dev, entry->reg_offset); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
if (!alignment) |
| 43 |
alignment = ~pci_moving_config32(dev, entry->reg_offset) + 1; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
if (entry->is_limit) |
| 50 |
value = ALIGN_UP(value + alignment - 1, alignment); |
| 51 |
else |
| 52 |
value = ALIGN_DOWN(value, alignment); |
| 53 |
|
| 54 |
return value; |
| 55 |
} |