Created
December 5, 2024 02:27
Revisions
-
JJL772 revised this gist
Dec 5, 2024 . 1 changed file with 1 addition and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,14 +32,14 @@ int main(int argc, char** argv) 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) { @@ -53,18 +53,6 @@ int main(int argc, char** argv) } } dmaUnMapDma(fd, buffs); close(fd); -
JJL772 created this gist
Dec 5, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ #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; }