Created
December 5, 2024 02:27
-
-
Save JJL772/5a2816fd2fd2b32dbd9c6d110979218e to your computer and use it in GitHub Desktop.
Code to reproduce the write-back/uncache-minus memory mismatch in aes-stream-drivers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "getopt.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include "DmaDriver.h" | |
#define AXI_VERSION_OFFSET 0x20000 | |
#define DMA_MAP | |
int main(int argc, char** argv) | |
{ | |
char dev[256] = "/dev/datagpu_0"; | |
int o = 0; | |
while ((o = getopt(argc, argv, "d:")) != -1) { | |
switch (o) { | |
case 'd': | |
strcpy(dev, optarg); | |
break; | |
default: | |
break; | |
} | |
} | |
printf("Opening %s\n", dev); | |
int fd; | |
if ((fd = open(dev, O_RDWR)) < 0) { | |
perror("Could not open device"); | |
return -1; | |
} | |
#ifdef DMA_MAP | |
uint32_t count, size; | |
auto** buffs = dmaMapDma(fd, &count, &size); | |
if (!buffs || buffs == MAP_FAILED) { | |
perror("dmaMapDma failed"); | |
exit(1); | |
} | |
for (int b = 0; b < count; ++b) { | |
auto* buf = (uint8_t*)buffs[b]; | |
for (int i = 0; i < size; ++i) { | |
buf[i] = 0xAA; | |
} | |
for (int i = 0; i < size; ++i) { | |
if (buf[i] != 0xAA) { | |
printf("Bad b=%d, i=%d\n", b,i); | |
} | |
} | |
} | |
dmaUnMapDma(fd, buffs); | |
#else | |
auto* ptr = dmaMapRegister(fd, AXI_VERSION_OFFSET, 0x1000); | |
if (!ptr || ptr == MAP_FAILED) { | |
perror("Unable to map memory"); | |
exit(1); | |
} | |
auto* scr = static_cast<uint32_t*>(ptr) + 0x1; | |
//*scr = 0xDEADBEEF; | |
dmaUnMapRegister(fd, ptr, 0x1000); | |
#endif | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment