Update sdramp driver for the new i/o framework.
This commit is contained in:
@@ -32,7 +32,7 @@ signal "LED_TTY" pin RA14 # tty activity indicator
|
||||
|
||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||
config unix root on sd0a
|
||||
swap on sd0b
|
||||
swap on dr0b # swap on SDRAM
|
||||
|
||||
# Serial UART ports
|
||||
device uart3
|
||||
@@ -57,13 +57,11 @@ device adc
|
||||
# PWM driver
|
||||
device pwm
|
||||
|
||||
# Use SDRAM driver for the external ramdisk
|
||||
device sdramp0 # SDRAM on external memory bus
|
||||
# Use SDRAM driver for the external ramdisk.
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
|
||||
@@ -5,15 +5,15 @@ PARAM += -DSPI4_ENABLED
|
||||
PARAM += -DSD_ENABLED
|
||||
PARAM += -DADC_ENABLED
|
||||
PARAM += -DPWM_ENABLED
|
||||
PARAM += -DSDRAMP_ENABLED
|
||||
PARAM += -DDR_ENABLED
|
||||
PARAM += -DSD_ENA_PORT=TRISB -DSD_ENA_PIN=13
|
||||
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=14
|
||||
PARAM += -DLED_SWAP_PORT=TRISC -DLED_SWAP_PIN=14
|
||||
PARAM += -DLED_DISK_PORT=TRISC -DLED_DISK_PIN=13
|
||||
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=15
|
||||
PARAM += -DNMOUNT=3
|
||||
PARAM += -DPARTITION='sdramp0:sa@2048,fs@14000'
|
||||
PARAM += -DKERNEL_EXECUTABLE_RAM
|
||||
PARAM += -DSDR_SWAP_KBYTES=2048
|
||||
PARAM += -DSD_MHZ=10
|
||||
PARAM += -DCONS_MINOR=2
|
||||
PARAM += -DCONS_MAJOR=UART_MAJOR
|
||||
|
||||
@@ -37,7 +37,6 @@ options "NMOUNT=2" # Number of mounted filesystems, def
|
||||
options "SMAPSIZ=NPROC" # Size of swap map, default NPROC
|
||||
options "HALTREBOOT" # Reboot the processor on halt()
|
||||
options "KERNEL_HIGHLIGHT" # Highlight kernel messages
|
||||
options "PARTITION='%1'" # Partition schema for RAM device
|
||||
|
||||
# LEDs
|
||||
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_CONTROL" pin RA5
|
||||
|
||||
#--------------------------------------------
|
||||
# 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
|
||||
# picga
|
||||
controller spi1 # RAM disk: picga
|
||||
device picga0 at spi1 pin RA4 # chip select signal
|
||||
options "PICGA_BUS=SPI1CON" # TODO: delete this option
|
||||
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
|
||||
controller spi1 # RAM disk: mrams
|
||||
device mrams0 at spi1
|
||||
device mr0 at spi1
|
||||
pins RA4, RA2, RB14, RB12, # chip select signals
|
||||
RB10, RB11
|
||||
options "MRAMS_CHIPS=6" # number of chips
|
||||
@@ -170,7 +173,7 @@ signal "MRAMS_LED5" pin RF5
|
||||
|
||||
# spirams - SPI block device
|
||||
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
|
||||
RF4, RF5, RF6, RF7,
|
||||
RF8, RF9, RF10, RF11,
|
||||
|
||||
@@ -1 +1,8 @@
|
||||
#
|
||||
# List of block devices and majors
|
||||
#
|
||||
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
|
||||
|
||||
@@ -24,7 +24,6 @@ kernel/kern_subr.c standard
|
||||
kernel/kern_synch.c standard
|
||||
kernel/kern_sysctl.c standard
|
||||
kernel/kern_time.c standard
|
||||
#kernel/rdisk.c standard
|
||||
kernel/subr_log.c optional log
|
||||
kernel/subr_prf.c standard
|
||||
kernel/subr_rmap.c standard
|
||||
@@ -76,12 +75,12 @@ pic32/hx8357.c optional hxtft
|
||||
pic32/picga.c optional picga
|
||||
pic32/power_control.c optional power
|
||||
pic32/pwm.c optional pwm
|
||||
pic32/mrams.c optional mrams
|
||||
pic32/mrams.c optional mr
|
||||
pic32/sd.c optional sd
|
||||
pic32/sdramp.c optional sdramp
|
||||
pic32/spirams.c optional spirams
|
||||
pic32/sramc.c optional sramc
|
||||
pic32/sdram.S optional sdramp
|
||||
pic32/sdramp.c optional dr
|
||||
pic32/sdram.S optional dr
|
||||
pic32/spirams.c optional sr
|
||||
pic32/sramc.c optional rc
|
||||
pic32/skel.c optional skel
|
||||
pic32/spi.c optional spi
|
||||
pic32/spi_bus.c optional spi
|
||||
|
||||
@@ -25,7 +25,7 @@ options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
|
||||
|
||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||
config unix root on sd0a
|
||||
swap on sd0b
|
||||
swap on sr0 # Swap on SPI RAM
|
||||
|
||||
# Serial UART ports
|
||||
device uart1 # Serial-to-USB converter
|
||||
@@ -51,8 +51,7 @@ device pwm
|
||||
device hxtft
|
||||
|
||||
# spirams - SPI block device
|
||||
device spirams0 at spi4
|
||||
options "PARTITION='spirams0:sa@2040'" # Partition schema
|
||||
device sr0 at spi4
|
||||
options "SPIRAMS_PORT=SPI4CON" # TODO: delete this option
|
||||
options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes
|
||||
options "SPIRAMS_CHIPS=16" # number of chips
|
||||
|
||||
@@ -772,7 +772,7 @@ void sdstrategy(struct buf *bp)
|
||||
{
|
||||
/* Write to partition table not allowed. */
|
||||
bp->b_error = EROFS;
|
||||
bad: bp->b_flags |= B_ERROR;
|
||||
bad: bp->b_flags |= B_ERROR;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
extern int sdopen(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 void sdstrategy(register struct buf *bp);
|
||||
extern int sdioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag);
|
||||
extern void sdstrategy(struct buf *bp);
|
||||
extern int sdioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
@@ -11,6 +10,8 @@
|
||||
#include <sys/buf.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/dk.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/disk.h>
|
||||
#include <machine/sdram.h>
|
||||
#include <machine/sdramp.h>
|
||||
#include <sys/kconfig.h>
|
||||
@@ -20,7 +21,7 @@
|
||||
*/
|
||||
#include <machine/sdramp_config.h>
|
||||
|
||||
int sw_dkn = -1; /* Statistics slot number */
|
||||
int sdramp_dkindex = -1; /* Statistics slot number */
|
||||
|
||||
/*
|
||||
* physical specs of SDRAM chip
|
||||
@@ -54,6 +55,11 @@ int sw_dkn = -1; /* Statistics slot number */
|
||||
|
||||
#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];
|
||||
|
||||
/*
|
||||
@@ -113,6 +119,7 @@ static void sdram_upperlowerbyte(unsigned bit)
|
||||
dqm_port->latclr = (1<<SDR_DQM_LDQM_BIT);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void sdram_init_c()
|
||||
{
|
||||
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.
|
||||
*/
|
||||
int
|
||||
sdramp_read(int unit, unsigned blockno, char* data, unsigned nbytes)
|
||||
static int
|
||||
sdramp_read(unsigned blockno, char* data, unsigned nbytes)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
int
|
||||
sdramp_write (int unit, unsigned blockno, char *data, unsigned nbytes)
|
||||
static int
|
||||
sdramp_write (unsigned blockno, char *data, unsigned nbytes)
|
||||
{
|
||||
blockno = blockno * (DEV_BSIZE/CHUNK_SIZE);
|
||||
|
||||
@@ -348,30 +355,127 @@ sdramp_write (int unit, unsigned blockno, char *data, unsigned nbytes)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sdramp_preinit (int unit)
|
||||
{
|
||||
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)
|
||||
int sdramp_open(dev_t dev, int flag, int mode)
|
||||
{
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
#define _SDRAMP_H
|
||||
|
||||
#ifdef KERNEL
|
||||
|
||||
extern int sdramp_write(int unit, unsigned blockno, char* data, unsigned nbytes);
|
||||
extern int sdramp_read (int unit, unsigned blockno, char *data, unsigned nbytes);
|
||||
extern void sdramp_preinit(int unit);
|
||||
extern int sdramp_size(int unit);
|
||||
extern int sdramp_open(int unit, int a, int b);
|
||||
|
||||
extern int sdramp_open(dev_t dev, int flag, int mode);
|
||||
extern int sdramp_close(dev_t dev, int flag, int mode);
|
||||
extern daddr_t sdramp_size(dev_t dev);
|
||||
extern void sdramp_strategy(struct buf *bp);
|
||||
extern int sdramp_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user