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 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; | |
} | |
uint32_t count, size; | |
auto** buffs = dmaMapDma(fd, &count, &size); | |
if (!buffs || buffs == MAP_FAILED) { | |
perror("dmaMapDma failed"); | |
exit(1); | |
} | |
// This is unnecessary, but done for testing. you should see warnings immediately after the memory is mapped. | |
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); | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment