BlockDevice can now specify max request length

This commit is contained in:
Howard Mao 2017-06-23 17:17:21 -07:00
parent 8505078c41
commit 2b773a2e51
2 changed files with 29 additions and 7 deletions

@ -1 +1 @@
Subproject commit 058e50a2292a6e2e756a6f70f2afb6131d758c5c
Subproject commit e8a16be9b71535a2dd8258a90dec227c7ded17ca

View File

@ -13,6 +13,7 @@
#define BLKDEV_COMPLETE (BLKDEV_BASE + 24)
#define BLKDEV_NCOMPLETE (BLKDEV_BASE + 28)
#define BLKDEV_NSECTORS (BLKDEV_BASE + 32)
#define BLKDEV_MAX_REQUEST_LENGTH (BLKDEV_BASE + 36)
#define BLKDEV_SECTOR_SIZE 512
#define BLKDEV_SECTOR_SHIFT 9
@ -21,6 +22,11 @@ size_t blkdev_nsectors(void)
return read_reg(BLKDEV_NSECTORS);
}
size_t blkdev_max_req_len(void)
{
return read_reg(BLKDEV_MAX_REQUEST_LENGTH);
}
int blkdev_read(void *addr, unsigned long offset, size_t nsectors)
{
int req_tag, resp_tag;
@ -56,28 +62,44 @@ int blkdev_write(unsigned long offset, void *addr, size_t nsectors)
return (resp_tag == req_tag) ? 0 : -1;
}
#define NSECTORS 2
#define TEST_SIZE (NSECTORS * BLKDEV_SECTOR_SIZE / sizeof(int))
#define TEST_NSECTORS 2
#define TEST_SIZE (TEST_NSECTORS * BLKDEV_SECTOR_SIZE / sizeof(int))
unsigned int test_data[TEST_SIZE];
unsigned int res_data[TEST_SIZE];
int main(void)
{
unsigned int nsectors = blkdev_nsectors();
unsigned int max_req_len = blkdev_max_req_len();
if (nsectors < TEST_NSECTORS) {
printf("Error: blkdev nsectors not large enough: %u < %u\n",
nsectors, TEST_NSECTORS);
return 1;
}
if (max_req_len < TEST_NSECTORS) {
printf("Error: blkdev max_req_len not large enough: %u < %u\n",
max_req_len, TEST_NSECTORS);
return 1;
}
printf("blkdev: %u sectors %u max request length\n",
nsectors, max_req_len);
for (int i = 0; i < TEST_SIZE; i++) {
test_data[i] = i << 8;
}
asm volatile ("fence");
printf("Block device with %ld sectors\n", blkdev_nsectors());
if (blkdev_write(0, (void *) test_data, NSECTORS)) {
if (blkdev_write(0, (void *) test_data, TEST_NSECTORS)) {
printf("write error\n");
return 1;
}
if (blkdev_read((void *) res_data, 0, NSECTORS)) {
if (blkdev_read((void *) res_data, 0, TEST_NSECTORS)) {
printf("read error\n");
return 1;
}