Skip to content

Commit

Permalink
SD Driver patch and config
Browse files Browse the repository at this point in the history
  • Loading branch information
angl-dev authored and msfschaffner committed Jun 4, 2019
1 parent 366b617 commit 8f0ae5d
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 0 deletions.
215 changes: 215 additions & 0 deletions configs/0099-Piton-SD-Driver.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
diff -urN linux-4.20-rc2/drivers/block/Kconfig linux-4.20-rc2/drivers/block/Kconfig
--- linux-4.20-rc2/drivers/block/Kconfig 2018-11-11 18:12:31.000000000 -0500
+++ linux-4.20-rc2/drivers/block/Kconfig 2019-02-18 22:16:37.592920785 -0500
@@ -386,6 +386,12 @@
Support for virtual disk devices as a client under Sun
Logical Domains.

+config OPENPITON_ARIANE_RAMDISK
+ tristate "OpenPiton+Ariane FPGA SD ramdisk device driver"
+ default n
+ help
+ Support for the ramdisk for OpenPiton+Ariane running on FPGA booting from SD card.
+
source "drivers/s390/block/Kconfig"

config XILINX_SYSACE
diff -urN linux-4.20-rc2/drivers/block/Makefile linux-4.20-rc2/drivers/block/Makefile
--- linux-4.20-rc2/drivers/block/Makefile 2018-11-11 18:12:31.000000000 -0500
+++ linux-4.20-rc2/drivers/block/Makefile 2019-02-18 22:20:48.006008000 -0500
@@ -19,6 +19,7 @@
obj-$(CONFIG_XILINX_SYSACE) += xsysace.o
obj-$(CONFIG_CDROM_PKTCDVD) += pktcdvd.o
obj-$(CONFIG_SUNVDC) += sunvdc.o
+obj-$(CONFIG_OPENPITON_ARIANE_RAMDISK) += piton_sd.o
obj-$(CONFIG_BLK_DEV_SKD) += skd.o

obj-$(CONFIG_BLK_DEV_UMEM) += umem.o
diff -urN linux-4.20-rc2/drivers/block/piton_sd.c linux-4.20-rc2/drivers/block/piton_sd.c
--- linux-4.20-rc2/drivers/block/piton_sd.c 1969-12-31 19:00:00.000000000 -0500
+++ linux-4.20-rc2/drivers/block/piton_sd.c 2019-02-18 22:19:57.711154000 -0500
@@ -0,0 +1,184 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/blkdev.h>
+#include <asm-generic/io.h>
+
+#define DRV_NAME "piton_sd"
+#define DRV_VERSION "1.0"
+#define DRV_RELDATE "Apr 26, 2019"
+
+MODULE_VERSION(DRV_VERSION);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("OpenPiton FPGA SD card device driver");
+
+static char version[] =
+ DRV_NAME ":v" DRV_VERSION " " DRV_RELDATE " \n";
+
+#ifndef PITON_SD_BASE_ADDR
+#define PITON_SD_BASE_ADDR 0xf000000000L
+#endif
+
+#define PITON_SD_NMINORS 128
+#define PITON_SD_BLOCK_SIZE 512
+
+// Partition Table Header (LBA 1)
+typedef struct gpt_pth
+{
+ uint64_t signature;
+ uint32_t revision;
+ uint32_t header_size; //! little endian, usually 0x5c = 92
+ uint32_t crc_header;
+ uint32_t reserved; //! must be 0
+ uint64_t current_lba;
+ uint64_t backup_lba;
+ uint64_t first_usable_lba;
+ uint64_t last_usable_lba;
+ uint8_t disk_guid[16];
+ uint64_t partition_entries_lba;
+ uint32_t nr_partition_entries;
+ uint32_t size_partition_entry; //! usually 0x80 = 128
+ uint32_t crc_partition_entry;
+} gpt_pth_t;
+
+// Partition Entries (LBA 2-33)
+typedef struct partition_entries
+{
+ uint8_t partition_type_guid[16];
+ uint8_t partition_guid[16];
+ uint64_t first_lba;
+ uint64_t last_lba; //! inclusive
+ uint64_t attributes;
+ uint8_t name[72]; //! utf16 encoded
+} partition_entries_t;
+
+static int piton_sd_major = 0;
+static char * piton_sd_name = "piton_sd";
+static struct gendisk *piton_sd_gendisk;
+static struct block_device_operations piton_sd_bdev_ops = {};
+static void __iomem * piton_sd_base_addr;
+
+// helpers
+#define PITON_SD_READ 0
+#define PITON_SD_WRITE 1
+static void piton_sd_rw(int rw, void *dst, uint32_t lba, unsigned long size) {
+ uint64_t * src;
+ volatile uint64_t * p;
+ unsigned long i;
+
+ src = (uint64_t *)(piton_sd_base_addr + ( ((uint64_t)lba) << 9 ));
+ p = (uint64_t *)dst;
+ for (i = 0; i < size; i += 8) {
+ if (rw == PITON_SD_READ) {
+ *(p++) = ioread64(src++);
+ } else {
+ iowrite64(*(p++), src++);
+ }
+ }
+}
+
+static blk_qc_t piton_sd_make_request(struct request_queue *queue, struct bio *bio) {
+ struct bio_vec bvec;
+ struct bvec_iter iter;
+ int direction = bio_data_dir(bio);
+
+ bio_for_each_segment(bvec, bio, iter) {
+ unsigned long real_addr = (unsigned long) page_to_virt(bvec.bv_page);
+ real_addr += bvec.bv_offset;
+ piton_sd_rw(direction, (void *)real_addr, iter.bi_sector, bvec.bv_len);
+ }
+
+ bio_endio(bio);
+ return BLK_QC_T_NONE;
+}
+
+static int piton_sd_init(void)
+{
+ static unsigned int version_printed = 0;
+ struct request_queue *queue = NULL;
+ int result;
+ uint8_t lba_buf[PITON_SD_BLOCK_SIZE];
+ gpt_pth_t * pth;
+
+ if (version_printed++ == 0) {
+ printk(KERN_INFO "%s\n", version);
+ }
+
+ piton_sd_base_addr = ioremap_nocache(PITON_SD_BASE_ADDR, PITON_SD_BLOCK_SIZE);
+ if (!piton_sd_base_addr) {
+ printk(KERN_ERR "ioremap returned NULL");
+ return -EIO;
+ }
+
+ // load GPT partition table header (the first sector on the disk)
+ piton_sd_rw(PITON_SD_READ, lba_buf, 1, PITON_SD_BLOCK_SIZE);
+ pth = (gpt_pth_t *)lba_buf;
+
+ // unmap that and remap the entire SD
+ iounmap(piton_sd_base_addr);
+ piton_sd_base_addr = ioremap_nocache(PITON_SD_BASE_ADDR, (pth->backup_lba + 1) * PITON_SD_BLOCK_SIZE);
+ if (!piton_sd_base_addr) {
+ printk(KERN_ERR "ioremap returned NULL");
+ return -EIO;
+ }
+
+ // register device
+ result = register_blkdev(piton_sd_major, piton_sd_name);
+ if (result <= 0) {
+ printk(KERN_ERR "%s: register_blkdev returned error %d \n", DRV_NAME, result);
+ return -EIO;
+ }
+ if (piton_sd_major == 0) {
+ piton_sd_major = result;
+ }
+
+ queue = blk_alloc_queue(GFP_KERNEL);
+ if (queue == NULL) {
+ printk(KERN_ERR "%s: blk_alloc_queue() returned NULL. \n", DRV_NAME);
+ goto fail;
+ }
+
+ piton_sd_gendisk = alloc_disk(PITON_SD_NMINORS);
+ if (piton_sd_gendisk == NULL) {
+ printk(KERN_ERR "%s: alloc_disk() returned NULL. \n", DRV_NAME);
+ goto fail;
+ }
+
+ blk_queue_make_request(queue, piton_sd_make_request);
+
+ piton_sd_gendisk->queue = queue;
+ piton_sd_gendisk->major = piton_sd_major;
+ piton_sd_gendisk->first_minor = 0;
+ snprintf(piton_sd_gendisk->disk_name, 32, "%s", piton_sd_name);
+ piton_sd_gendisk->fops = &piton_sd_bdev_ops;
+ set_capacity(piton_sd_gendisk, pth->backup_lba + 1);
+ add_disk(piton_sd_gendisk);
+
+ return 0;
+
+
+fail:
+ unregister_blkdev(piton_sd_major, piton_sd_name);
+
+ if (queue) {
+ blk_cleanup_queue(queue);
+ }
+
+ return -EIO;
+}
+
+
+static void piton_sd_exit(void)
+{
+ del_gendisk(piton_sd_gendisk);
+ put_disk(piton_sd_gendisk);
+ blk_cleanup_queue(piton_sd_gendisk->queue);
+
+ unregister_blkdev(piton_sd_major, piton_sd_name);
+
+ return;
+}
+
+
+module_init(piton_sd_init);
+module_exit(piton_sd_exit);
2 changes: 2 additions & 0 deletions configs/buildroot_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_GIT=y
BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/pulp-platform/linux.git"
BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="ariane-v0.7"
BR2_LINUX_KERNEL_PATCH="../configs/0099-Piton-SD-Driver.patch"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="../configs/linux_defconfig"
BR2_PACKAGE_BUSYBOX_CONFIG="../configs/busybox.config"
Expand All @@ -35,3 +36,4 @@ BR2_PACKAGE_TCPDUMP=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
BR2_TARGET_ROOTFS_INITRAMFS=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_E2FSPROGS
1 change: 1 addition & 0 deletions configs/linux_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ CONFIG_PRINTK_TIME=y
CONFIG_STRIP_ASM_SYMS=y
CONFIG_DEBUG_SECTION_MISMATCH=y
CONFIG_STACKTRACE=y
CONFIG_OPENPITON_ARIANE_RAMDISK=y

0 comments on commit 8f0ae5d

Please sign in to comment.