summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--devmem-aspeed.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/devmem-aspeed.c b/devmem-aspeed.c
index 21ad4a2..da125e2 100644
--- a/devmem-aspeed.c
+++ b/devmem-aspeed.c
@@ -62,6 +62,7 @@
struct pci_access *pacc;
uintptr_t aspeed_bar_offset = 0;
+void *aspeed_control_bar = NULL;
void *aspeed_bar = NULL;
struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
@@ -91,11 +92,11 @@ static int ast2400_set_a2b_bridge_dest_address(uintptr_t address)
{
aspeed_bar_offset = address & 0xffff;
- *((volatile uint32_t *)(aspeed_bar + 0xf000)) = 0x0;
+ *((volatile uint32_t *)(aspeed_control_bar + 0xf000)) = 0x0;
sync_primitive();
- *((volatile uint32_t *)(aspeed_bar + 0xf004)) = address & 0xffff0000;
+ *((volatile uint32_t *)(aspeed_control_bar + 0xf004)) = address & 0xffff0000;
sync_primitive();
- *((volatile uint32_t *)(aspeed_bar + 0xf000)) = 0x1;
+ *((volatile uint32_t *)(aspeed_control_bar + 0xf000)) = 0x1;
sync_primitive();
return 0;
@@ -103,7 +104,7 @@ static int ast2400_set_a2b_bridge_dest_address(uintptr_t address)
static int ast2400_disable_a2b_bridge(void)
{
- *((volatile uint32_t *)(aspeed_bar + 0xf000)) = 0x0;
+ *((volatile uint32_t *)(aspeed_control_bar + 0xf000)) = 0x0;
sync_primitive();
return 0;
@@ -141,11 +142,15 @@ int main(int argc, char **argv) {
bar_addr = (void *)(aspeed_dev->base_addr[1] & PCI_BASE_ADDRESS_MEM_MASK);
- bar_addr += ASPEED_P2A_OFFSET;
-
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
- /* Map one page */
+ /* Map control page */
+ aspeed_control_bar = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (uintptr_t)bar_addr);
+ if(aspeed_control_bar == (void *) -1) FATAL;
+
+ bar_addr += ASPEED_P2A_OFFSET;
+
+ /* Map data page */
aspeed_bar = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (uintptr_t)bar_addr);
if(aspeed_bar == (void *) -1) FATAL;
@@ -193,6 +198,7 @@ int main(int argc, char **argv) {
ast2400_disable_a2b_bridge();
if(munmap(aspeed_bar, MAP_SIZE) == -1) FATAL;
+ if(munmap(aspeed_control_bar, MAP_SIZE) == -1) FATAL;
close(fd);
return 0;
OpenPOWER on IntegriCloud