Update sdramp driver for the new i/o framework.

This commit is contained in:
Serge Vakulenko
2015-09-29 18:15:21 -07:00
parent c4cc4bc397
commit 84a38361a5
12 changed files with 252 additions and 81 deletions

View File

@@ -22,8 +22,31 @@ dir /u
# #
# Block devices. # Block devices.
# #
# Major Minor Name Device
# -------------------------
# 0 0 sd0 Main SD card
# 0 1 sd0a Partition 1: root file system
# 0 2 sd0b Partition 2: swap space
# 0 3 sd0c Partition 3
# 0 4 sd0d Partition 4
# 0 8 sd1 Second SD card
# 0 9 sd1a Partition 1
# 0 10 sd1b Partition 2
# 0 11 sd1c Partition 3
# 0 12 sd1d Partition 4
# 1 0 rc0 Volatile disk - SRAM connected via CPLD (sramc)
# 2 0 dr0 Volatile disk - SDRAM on external memory bus (sdramp)
# 2 1 dr0a Partition 1: filesystem
# 2 2 dr0b Partition 2: swap space
# 3 0 mr0 Volatile disk - MRAM on SPI port (mrams)
# 4 64 swap Virtual swap device, mapped to real swap partition
# 4 0 swap0 Virtual i/o area, allocated from swap space
# 4 1 swap1 Virtual i/o area, allocated from swap space
# 4 2 swap2 Virtual i/o area, allocated from swap space
# 5 0 sr0 Volatile disk - serial RAM on SPI port (spirams)
#
bdev /dev/sd0 bdev /dev/sd0
major 0 major 0 # Main SD card
minor 0 minor 0
bdev /dev/sd0a bdev /dev/sd0a
major 0 major 0
@@ -38,7 +61,7 @@ bdev /dev/sd0d
major 0 major 0
minor 4 minor 4
bdev /dev/sd1 bdev /dev/sd1
major 0 major 0 # Second SD card
minor 8 minor 8
bdev /dev/sd1a bdev /dev/sd1a
major 0 major 0
@@ -52,8 +75,23 @@ minor 11
bdev /dev/sd1d bdev /dev/sd1d
major 0 major 0
minor 12 minor 12
bdev /dev/rc0
major 1 # Volatile disk - SRAM connected via CPLD (sramc)
minor 0
bdev /dev/dr0
major 2 # Volatile disk - SDRAM on external memory bus (sdramp)
minor 0
bdev /dev/dr0a
major 2
minor 1
bdev /dev/dr0b
major 2
minor 2
bdev /dev/mr0
major 3 # Volatile disk - MRAM on SPI port (mrams)
minor 0
bdev /dev/swap bdev /dev/swap
major 4 major 4 # Virtual swap device, mapped to real swap partition
minor 64 minor 64
bdev /dev/swap0 bdev /dev/swap0
major 4 major 4
@@ -64,6 +102,9 @@ minor 1
bdev /dev/swap2 bdev /dev/swap2
major 4 major 4
minor 2 minor 2
bdev /dev/sr0
major 5 # Volatile disk - serial RAM on SPI port (spirams)
minor 0
# #
# Character devices. # Character devices.

View File

@@ -32,7 +32,7 @@ signal "LED_TTY" pin RA14 # tty activity indicator
# Root filesystem at /dev/sd0a, swap at /dev/sd0b # Root filesystem at /dev/sd0a, swap at /dev/sd0b
config unix root on sd0a config unix root on sd0a
swap on sd0b swap on dr0b # swap on SDRAM
# Serial UART ports # Serial UART ports
device uart3 device uart3
@@ -57,13 +57,11 @@ device adc
# PWM driver # PWM driver
device pwm device pwm
# Use SDRAM driver for the external ramdisk # Use SDRAM driver for the external ramdisk.
device sdramp0 # SDRAM on external memory bus # The volume is divided into two partitions: A and B.
# Size of partition B is specified as option SDR_SWAP_KBYTES.
# The rest is partition A.
device dr0 # SDRAM on external memory bus
options "SDR_SWAP_KBYTES=2048" # size of partition B
options "KERNEL_EXECUTABLE_RAM" # allow kernel code in RAM area options "KERNEL_EXECUTABLE_RAM" # allow kernel code in RAM area
# This defines the swap size and a fs partition size on the external ramdisk.
# When the sa@XXXX is larger than the SWAP_KBYTES, the system will use
# the swap located on the external ramdisk automatically.
# (sd@xxxx + fs@xxxx) <= ramdisk_size
options "PARTITION='sdramp0:sa@2048,fs@14000'"
options "NMOUNT=3" options "NMOUNT=3"

View File

@@ -5,15 +5,15 @@ PARAM += -DSPI4_ENABLED
PARAM += -DSD_ENABLED PARAM += -DSD_ENABLED
PARAM += -DADC_ENABLED PARAM += -DADC_ENABLED
PARAM += -DPWM_ENABLED PARAM += -DPWM_ENABLED
PARAM += -DSDRAMP_ENABLED PARAM += -DDR_ENABLED
PARAM += -DSD_ENA_PORT=TRISB -DSD_ENA_PIN=13 PARAM += -DSD_ENA_PORT=TRISB -DSD_ENA_PIN=13
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=14 PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=14
PARAM += -DLED_SWAP_PORT=TRISC -DLED_SWAP_PIN=14 PARAM += -DLED_SWAP_PORT=TRISC -DLED_SWAP_PIN=14
PARAM += -DLED_DISK_PORT=TRISC -DLED_DISK_PIN=13 PARAM += -DLED_DISK_PORT=TRISC -DLED_DISK_PIN=13
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=15 PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=15
PARAM += -DNMOUNT=3 PARAM += -DNMOUNT=3
PARAM += -DPARTITION='sdramp0:sa@2048,fs@14000'
PARAM += -DKERNEL_EXECUTABLE_RAM PARAM += -DKERNEL_EXECUTABLE_RAM
PARAM += -DSDR_SWAP_KBYTES=2048
PARAM += -DSD_MHZ=10 PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=2 PARAM += -DCONS_MINOR=2
PARAM += -DCONS_MAJOR=UART_MAJOR PARAM += -DCONS_MAJOR=UART_MAJOR

View File

@@ -37,7 +37,6 @@ options "NMOUNT=2" # Number of mounted filesystems, def
options "SMAPSIZ=NPROC" # Size of swap map, default NPROC options "SMAPSIZ=NPROC" # Size of swap map, default NPROC
options "HALTREBOOT" # Reboot the processor on halt() options "HALTREBOOT" # Reboot the processor on halt()
options "KERNEL_HIGHLIGHT" # Highlight kernel messages options "KERNEL_HIGHLIGHT" # Highlight kernel messages
options "PARTITION='%1'" # Partition schema for RAM device
# LEDs # LEDs
signal "LED_DISK" pin RF0 invert # disk activity indicator signal "LED_DISK" pin RF0 invert # disk activity indicator
@@ -125,30 +124,34 @@ signal "POWER_LED" pin RA3
signal "POWER_SWITCH" pin RA4 signal "POWER_SWITCH" pin RA4
signal "POWER_CONTROL" pin RA5 signal "POWER_CONTROL" pin RA5
#-------------------------------------------- # picga
# Custom RAM disk devices
#
# sdramp - SDRAM block device
device sdramp0 # SDRAM on external memory bus
options "KERNEL_EXECUTABLE_RAM" # allow kernel code in RAM area
# sramc - SRAM block device
device sramc0 # SRAM via 4-wire CPLD interface
signal "SRAMC_DATA" pin RE0
signal "SRAMC_LDA" pin RC13
signal "SRAMC_RD" pin RF1
signal "SRAMC_WR" pin RF0
# picga - SPI block device
controller spi1 # RAM disk: picga controller spi1 # RAM disk: picga
device picga0 at spi1 pin RA4 # chip select signal device picga0 at spi1 pin RA4 # chip select signal
options "PICGA_BUS=SPI1CON" # TODO: delete this option options "PICGA_BUS=SPI1CON" # TODO: delete this option
signal "PICGA_CS" pin RA4 # TODO: delete signal "PICGA_CS" pin RA4 # TODO: delete
#--------------------------------------------
# Custom RAM disk devices
#
# sdramp - SDRAM block device
# The volume is divided into two partitions: A and B.
# Size of partition B is specified as option SDR_SWAP_KBYTES.
# The rest is partition A.
device dr0 # SDRAM on external memory bus
options "SDR_SWAP_KBYTES=2048" # size of partition B
options "KERNEL_EXECUTABLE_RAM" # allow kernel code in RAM area
# sramc - SRAM block device
device rc0 # SRAM via 4-wire CPLD interface
signal "SRAMC_DATA" pin RE0
signal "SRAMC_LDA" pin RC13
signal "SRAMC_RD" pin RF1
signal "SRAMC_WR" pin RF0
# mrams - SPI block device # mrams - SPI block device
controller spi1 # RAM disk: mrams controller spi1 # RAM disk: mrams
device mrams0 at spi1 device mr0 at spi1
pins RA4, RA2, RB14, RB12, # chip select signals pins RA4, RA2, RB14, RB12, # chip select signals
RB10, RB11 RB10, RB11
options "MRAMS_CHIPS=6" # number of chips options "MRAMS_CHIPS=6" # number of chips
@@ -170,7 +173,7 @@ signal "MRAMS_LED5" pin RF5
# spirams - SPI block device # spirams - SPI block device
controller spi1 # RAM disk: spirams controller spi1 # RAM disk: spirams
device spirams0 at spi1 # chip select signals: device sr0 at spi1 # chip select signals:
pins RF0, RF1, RF2, RF3, # chip select signals pins RF0, RF1, RF2, RF3, # chip select signals
RF4, RF5, RF6, RF7, RF4, RF5, RF6, RF7,
RF8, RF9, RF10, RF11, RF8, RF9, RF10, RF11,

View File

@@ -1 +1,8 @@
#
# List of block devices and majors
#
sd 0 sd 0
rc 1 # sramc - SRAM connected via CPLD
dr 2 # sdramp - SDRAM at external memory bus
mr 3 # mrams - MRAM at SPI port
sr 5 # spirams - serial RAM at SPI port

View File

@@ -24,7 +24,6 @@ kernel/kern_subr.c standard
kernel/kern_synch.c standard kernel/kern_synch.c standard
kernel/kern_sysctl.c standard kernel/kern_sysctl.c standard
kernel/kern_time.c standard kernel/kern_time.c standard
#kernel/rdisk.c standard
kernel/subr_log.c optional log kernel/subr_log.c optional log
kernel/subr_prf.c standard kernel/subr_prf.c standard
kernel/subr_rmap.c standard kernel/subr_rmap.c standard
@@ -76,12 +75,12 @@ pic32/hx8357.c optional hxtft
pic32/picga.c optional picga pic32/picga.c optional picga
pic32/power_control.c optional power pic32/power_control.c optional power
pic32/pwm.c optional pwm pic32/pwm.c optional pwm
pic32/mrams.c optional mrams pic32/mrams.c optional mr
pic32/sd.c optional sd pic32/sd.c optional sd
pic32/sdramp.c optional sdramp pic32/sdramp.c optional dr
pic32/spirams.c optional spirams pic32/sdram.S optional dr
pic32/sramc.c optional sramc pic32/spirams.c optional sr
pic32/sdram.S optional sdramp pic32/sramc.c optional rc
pic32/skel.c optional skel pic32/skel.c optional skel
pic32/spi.c optional spi pic32/spi.c optional spi
pic32/spi_bus.c optional spi pic32/spi_bus.c optional spi

View File

@@ -25,7 +25,7 @@ options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
# Root filesystem at /dev/sd0a, swap at /dev/sd0b # Root filesystem at /dev/sd0a, swap at /dev/sd0b
config unix root on sd0a config unix root on sd0a
swap on sd0b swap on sr0 # Swap on SPI RAM
# Serial UART ports # Serial UART ports
device uart1 # Serial-to-USB converter device uart1 # Serial-to-USB converter
@@ -51,8 +51,7 @@ device pwm
device hxtft device hxtft
# spirams - SPI block device # spirams - SPI block device
device spirams0 at spi4 device sr0 at spi4
options "PARTITION='spirams0:sa@2040'" # Partition schema
options "SPIRAMS_PORT=SPI4CON" # TODO: delete this option options "SPIRAMS_PORT=SPI4CON" # TODO: delete this option
options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes
options "SPIRAMS_CHIPS=16" # number of chips options "SPIRAMS_CHIPS=16" # number of chips

View File

@@ -772,7 +772,7 @@ void sdstrategy(struct buf *bp)
{ {
/* Write to partition table not allowed. */ /* Write to partition table not allowed. */
bp->b_error = EROFS; bp->b_error = EROFS;
bad: bp->b_flags |= B_ERROR; bad: bp->b_flags |= B_ERROR;
biodone(bp); biodone(bp);
return; return;
} }

View File

@@ -5,8 +5,8 @@
extern int sdopen(dev_t dev, int flag, int mode); extern int sdopen(dev_t dev, int flag, int mode);
extern int sdclose(dev_t dev, int flag, int mode); extern int sdclose(dev_t dev, int flag, int mode);
extern daddr_t sdsize(dev_t dev); extern daddr_t sdsize(dev_t dev);
extern void sdstrategy(register struct buf *bp); extern void sdstrategy(struct buf *bp);
extern int sdioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag); extern int sdioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
#endif #endif
#endif #endif

View File

@@ -1,6 +1,5 @@
/* /*
* Driver for external SDRAM-based swap device. * Driver for external SDRAM-based swap device.
* TODO: Modify this driver to be able to function without rdisk layer.
* *
* See sdram.S for information on interface to sdram * See sdram.S for information on interface to sdram
* *
@@ -11,6 +10,8 @@
#include <sys/buf.h> #include <sys/buf.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <sys/dk.h> #include <sys/dk.h>
#include <sys/ioctl.h>
#include <sys/disk.h>
#include <machine/sdram.h> #include <machine/sdram.h>
#include <machine/sdramp.h> #include <machine/sdramp.h>
#include <sys/kconfig.h> #include <sys/kconfig.h>
@@ -20,7 +21,7 @@
*/ */
#include <machine/sdramp_config.h> #include <machine/sdramp_config.h>
int sw_dkn = -1; /* Statistics slot number */ int sdramp_dkindex = -1; /* Statistics slot number */
/* /*
* physical specs of SDRAM chip * physical specs of SDRAM chip
@@ -54,6 +55,11 @@ int sw_dkn = -1; /* Statistics slot number */
#define BLOCKS_PER_ROW (RAM_COLS / CHUNK_SIZE) #define BLOCKS_PER_ROW (RAM_COLS / CHUNK_SIZE)
/*
* Size of the whole disk in kbytes.
*/
#define SDR_TOTAL_KBYTES ((1<<SDR_ADDRESS_LINES) / 2 * 4 * SDR_DATA_BYTES)
static char swaptemp[CHUNK_SIZE]; static char swaptemp[CHUNK_SIZE];
/* /*
@@ -113,6 +119,7 @@ static void sdram_upperlowerbyte(unsigned bit)
dqm_port->latclr = (1<<SDR_DQM_LDQM_BIT); dqm_port->latclr = (1<<SDR_DQM_LDQM_BIT);
#endif #endif
} }
static void sdram_init_c() static void sdram_init_c()
{ {
struct gpioreg * bank_port = (struct gpioreg *)&SDR_BANK_PORT; struct gpioreg * bank_port = (struct gpioreg *)&SDR_BANK_PORT;
@@ -301,8 +308,8 @@ write_chunk_to_sdram(uint64_t* src, unsigned int blockNumber)
/* /*
* Read a block of data. * Read a block of data.
*/ */
int static int
sdramp_read(int unit, unsigned blockno, char* data, unsigned nbytes) sdramp_read(unsigned blockno, char* data, unsigned nbytes)
{ {
blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); blockno = blockno * (DEV_BSIZE/CHUNK_SIZE);
@@ -324,8 +331,8 @@ sdramp_read(int unit, unsigned blockno, char* data, unsigned nbytes)
/* /*
* Write a block of data. * Write a block of data.
*/ */
int static int
sdramp_write (int unit, unsigned blockno, char *data, unsigned nbytes) sdramp_write (unsigned blockno, char *data, unsigned nbytes)
{ {
blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); blockno = blockno * (DEV_BSIZE/CHUNK_SIZE);
@@ -348,30 +355,127 @@ sdramp_write (int unit, unsigned blockno, char *data, unsigned nbytes)
return 1; return 1;
} }
void sdramp_preinit (int unit) int sdramp_open(dev_t dev, int flag, int mode)
{
printf("sdramp_preinit\n");
int x = mips_intr_disable();
struct buf *bp;
sdram_init_c();
mips_intr_restore(x);
bp = prepartition_device("sdramp0"/*,sdramp_size(0)*/);
if (bp) {
sdramp_write (0, 0, bp->b_addr, 512);
brelse(bp);
}
}
int sdramp_open(int unit, int flag, int mode)
{ {
return 0; return 0;
} }
int sdramp_size(int unit) int sdramp_close(dev_t dev, int flag, int mode)
{ {
return (1<<SDR_ADDRESS_LINES) / 2 * 4 * SDR_DATA_BYTES; return 0;
}
/*
* Return a size of partition in kbytes.
* The memory is divided into two partitions: A and B.
* Size of partition B is specified in the kernel config file
* as option SDR_SWAP_KBYTES.
*/
daddr_t sdramp_size(dev_t dev)
{
switch (minor(dev)) {
case 0:
/* Whole disk. */
return SDR_TOTAL_KBYTES;
case 1:
/* Partition A: filesystem. */
return SDR_TOTAL_KBYTES - SDR_SWAP_KBYTES;
case 2:
default:
/* Partition B: swap space. */
return SDR_SWAP_KBYTES;
}
}
void sdramp_strategy(struct buf *bp)
{
int offset = bp->b_blkno;
long nblk = btod(bp->b_bcount);
int part_offset, part_size, s;
/* Compute partition size and offset. */
part_size = sdramp_size(bp->b_dev);
if (minor(bp->b_dev) < 2) {
/* Partition A or a whole disk. */
part_offset = 0;
} else {
/* Partition B: swap space. */
part_offset = SDR_TOTAL_KBYTES - part_size;
}
/*
* Determine the size of the transfer, and make sure it is
* within the boundaries of the partition.
*/
offset += part_offset;
if (bp->b_blkno + nblk > part_size) {
/* if exactly at end of partition, return an EOF */
if (bp->b_blkno == part_size) {
bp->b_resid = bp->b_bcount;
biodone(bp);
return;
}
/* or truncate if part of it fits */
nblk = part_size - bp->b_blkno;
if (nblk <= 0) {
bp->b_error = EINVAL;
bp->b_flags |= B_ERROR;
biodone(bp);
return;
}
bp->b_bcount = nblk << DEV_BSHIFT;
}
if (bp->b_dev == swapdev) {
led_control(LED_SWAP, 1);
} else {
led_control(LED_DISK, 1);
}
s = splbio();
#ifdef UCB_METER
if (sdramp_dkindex >= 0) {
dk_busy |= 1 << sdramp_dkindex;
dk_xfer[sdramp_dkindex]++;
dk_bytes[sdramp_dkindex] += bp->b_bcount;
}
#endif
if (bp->b_flags & B_READ) {
sdramp_read(offset, bp->b_addr, bp->b_bcount);
} else {
sdramp_write(offset, bp->b_addr, bp->b_bcount);
}
biodone(bp);
if (bp->b_dev == swapdev) {
led_control(LED_SWAP, 0);
} else {
led_control(LED_DISK, 0);
}
#ifdef UCB_METER
if (sdramp_dkindex >= 0)
dk_busy &= ~(1 << sdramp_dkindex);
#endif
splx(s);
}
int sdramp_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag)
{
int error = 0;
switch (cmd) {
case DIOCGETMEDIASIZE:
/* Get disk size in kbytes. */
*(int*) addr = sdramp_size(dev);
break;
default:
error = EINVAL;
break;
}
return error;
} }
/* /*
@@ -382,7 +486,20 @@ static int
sdrampprobe(config) sdrampprobe(config)
struct conf_device *config; struct conf_device *config;
{ {
//TODO /* Only one device unit is supported. */
if (config->dev_unit != 0)
return 0;
printf("dr0: total %u kbytes, swap space %u kbytes\n",
SDR_TOTAL_KBYTES, SDR_SWAP_KBYTES);
int x = mips_intr_disable();
sdram_init_c();
mips_intr_restore(x);
#ifdef UCB_METER
dk_alloc(&sdramp_dkindex, 1, "dr0");
#endif
return 1; return 1;
} }

View File

@@ -2,13 +2,11 @@
#define _SDRAMP_H #define _SDRAMP_H
#ifdef KERNEL #ifdef KERNEL
extern int sdramp_open(dev_t dev, int flag, int mode);
extern int sdramp_write(int unit, unsigned blockno, char* data, unsigned nbytes); extern int sdramp_close(dev_t dev, int flag, int mode);
extern int sdramp_read (int unit, unsigned blockno, char *data, unsigned nbytes); extern daddr_t sdramp_size(dev_t dev);
extern void sdramp_preinit(int unit); extern void sdramp_strategy(struct buf *bp);
extern int sdramp_size(int unit); extern int sdramp_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
extern int sdramp_open(int unit, int a, int b);
#endif #endif
#endif #endif

View File

@@ -124,7 +124,7 @@ static struct devdescription {
void initdevtable() void initdevtable()
{ {
char buf[BUFSIZ]; char buf[BUFSIZ], name[BUFSIZ], *p;
int maj; int maj;
register struct devdescription **dp = &devtable; register struct devdescription **dp = &devtable;
FILE *fp; FILE *fp;
@@ -135,9 +135,18 @@ void initdevtable()
fprintf(stderr, "config: can't open %s\n", buf); fprintf(stderr, "config: can't open %s\n", buf);
exit(1); exit(1);
} }
while (fscanf(fp, "%s\t%d\n", buf, &maj) == 2) { while (fgets(buf, sizeof(buf), fp)) {
for (p=buf; *p; p++)
if (*p != ' ' && *p != '\t')
break;
if (*p == '#' || *p == '\n' || *p == '\r')
continue;
if (sscanf(p, "%s %d", name, &maj) != 2) {
fprintf(stderr, "../devices.kconf: unrecognized line %s\n", buf);
exit(1);
}
*dp = (struct devdescription *)malloc(sizeof (**dp)); *dp = (struct devdescription *)malloc(sizeof (**dp));
(*dp)->dev_name = strdup(buf); (*dp)->dev_name = strdup(name);
(*dp)->dev_major = maj; (*dp)->dev_major = maj;
dp = &(*dp)->dev_next; dp = &(*dp)->dev_next;
} }