-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow pifiles to be writable in the DOM2 area #631
Open
nopjne
wants to merge
2
commits into
DragonMinded:unstable
Choose a base branch
from
nopjne:pifile_write_support
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,6 @@ typedef struct { | |
|
||
static void *__pifile_open(char *name, int flags) | ||
{ | ||
if (flags != O_RDONLY) { | ||
errno = EACCES; | ||
return NULL; | ||
} | ||
|
||
// Parse the name in the foramt "ADDR:SIZE" as hexdecimal numbers | ||
char *end; | ||
uint32_t base = strtoul(name, &end, 16); | ||
|
@@ -42,6 +37,13 @@ static void *__pifile_open(char *name, int flags) | |
return NULL; | ||
} | ||
|
||
if ((base < 0x08000000) || (base >= 0x09000000)) { | ||
if (flags != O_RDONLY) { | ||
errno = EACCES; | ||
return NULL; | ||
} | ||
} | ||
|
||
pifile_t *file = malloc(sizeof(pifile_t)); | ||
if (!file) { | ||
errno = ENOMEM; | ||
|
@@ -123,6 +125,41 @@ static int __pifile_read(void *file, uint8_t *buf, int len) | |
return len; | ||
} | ||
|
||
|
||
static int __pifile_write(void *file, uint8_t *buf, int len) | ||
{ | ||
pifile_t *f = file; | ||
if (f->ptr + len > f->size) | ||
len = f->size - f->ptr; | ||
if (len <= 0) | ||
return 0; | ||
|
||
// Check if we can DMA directly to the output buffer | ||
if ((((f->base + f->ptr) ^ (uint32_t)buf) & 1) == 0) { | ||
data_cache_hit_writeback_invalidate(buf, len); | ||
dma_write_raw_async(buf, f->base + f->ptr, len); | ||
dma_wait(); | ||
f->ptr += len; | ||
} else { | ||
// Go through a temporary buffer | ||
uint8_t *tmp = alloca(512+1); | ||
if ((f->base + f->ptr) & 1) tmp++; | ||
|
||
while (len > 0) { | ||
int n = len > 512 ? 512 : len; | ||
data_cache_hit_writeback_invalidate(tmp, n); | ||
dma_write_raw_async(tmp, f->base + f->ptr, n); | ||
dma_wait(); | ||
memcpy(buf, tmp, n); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong, seems like you haven't updated this code. |
||
buf += n; | ||
f->ptr += n; | ||
len -= n; | ||
} | ||
} | ||
|
||
return len; | ||
} | ||
|
||
static int __pifile_close(void *file) | ||
{ | ||
free(file); | ||
|
@@ -135,6 +172,7 @@ static filesystem_t pifile_fs = { | |
.lseek = __pifile_lseek, | ||
.read = __pifile_read, | ||
.close = __pifile_close, | ||
.write = __pifile_write, | ||
}; | ||
|
||
void pifile_init(void) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this at this level. In general any device can expose any writeable area at any PI address, so I wouldn't hardcode the range. Eg: many flashcarts allow to write the internal SDRAM by writing at 0x10000000, maybe after enabling writes with some register.
So I would just remove the check and let the user know what they are doing.