Merge branch 'master' of https://github.com/RetroBSD/retrobsd
This commit is contained in:
@@ -49,7 +49,7 @@ struct spiio {
|
||||
unsigned int mode;
|
||||
};
|
||||
|
||||
extern int spi_setup(struct spiio *io, int channel, unsigned int *tris, unsigned int pin);
|
||||
extern int spi_setup(struct spiio *io, int channel, int cs);
|
||||
extern void spi_set_cspin(struct spiio *io, unsigned int *tris, unsigned int pin);
|
||||
extern void spi_select(struct spiio *io);
|
||||
extern void spi_deselect(struct spiio *io);
|
||||
|
||||
@@ -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,52 +124,50 @@ 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
|
||||
# The volume is divided into two partitions: A and B.
|
||||
# Size of partition B is specified as option SRAMC_SWAP_KBYTES.
|
||||
# The rest is partition A.
|
||||
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
|
||||
options "SRAMC_SWAP_KBYTES=2048" # size of partition B
|
||||
|
||||
# mrams - SPI block device
|
||||
controller spi1 # RAM disk: mrams
|
||||
device mrams0 at spi1
|
||||
pins RA4, RA2, RB14, RB12, # chip select signals
|
||||
RB10, RB11
|
||||
options "MRAMS_CHIPS=6" # number of chips
|
||||
device mr0 at spi1
|
||||
pins RA4, RA2, RB14, RB12 # chip select signals
|
||||
options "MRAMS_CHIPS=4" # number of chips
|
||||
options "MRAMS_CHIPSIZE=512" # chip size in kbytes
|
||||
options "MRAMS_MHZ=10" # speed 10 MHz
|
||||
options "MRAMS_PORT=SPI1CON" # TODO: delete this option
|
||||
signal "MRAMS_CS0" pin RA4 # TODO: delete
|
||||
signal "MRAMS_CS1" pin RA2 # TODO: delete
|
||||
signal "MRAMS_CS2" pin RB14 # TODO: delete
|
||||
signal "MRAMS_CS3" pin RB12 # TODO: delete
|
||||
signal "MRAMS_CS4" pin RB10 # TODO: delete
|
||||
signal "MRAMS_CS5" pin RB11 # TODO: delete
|
||||
signal "MRAMS_LED0" pin RF0 # optional LED indicators
|
||||
signal "MRAMS_LED1" pin RF1
|
||||
signal "MRAMS_LED2" pin RF2
|
||||
signal "MRAMS_LED3" pin RF3
|
||||
signal "MRAMS_LED4" pin RF4
|
||||
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
|
||||
pins RF0, RF1, RF2, RF3, # chip select signals
|
||||
RF4, RF5, RF6, RF7,
|
||||
RF8, RF9, RF10, RF11,
|
||||
@@ -178,23 +175,6 @@ device spirams0 at spi1 # chip select signals:
|
||||
options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes
|
||||
options "SPIRAMS_CHIPS=16" # number of chips
|
||||
options "SPIRAMS_MHZ=10" # speed 10 MHz
|
||||
options "SPIRAMS_PORT=SPI1CON" # TODO: delete this option
|
||||
signal "SPIRAMS_CS0" pin RF0 # TODO: delete
|
||||
signal "SPIRAMS_CS1" pin RF1 # TODO: delete
|
||||
signal "SPIRAMS_CS2" pin RF2 # TODO: delete
|
||||
signal "SPIRAMS_CS3" pin RF3 # TODO: delete
|
||||
signal "SPIRAMS_CS4" pin RF4 # TODO: delete
|
||||
signal "SPIRAMS_CS5" pin RF5 # TODO: delete
|
||||
signal "SPIRAMS_CS6" pin RF6 # TODO: delete
|
||||
signal "SPIRAMS_CS7" pin RF7 # TODO: delete
|
||||
signal "SPIRAMS_CS8" pin RF8 # TODO: delete
|
||||
signal "SPIRAMS_CS9" pin RF9 # TODO: delete
|
||||
signal "SPIRAMS_CS10" pin RF10 # TODO: delete
|
||||
signal "SPIRAMS_CS11" pin RF11 # TODO: delete
|
||||
signal "SPIRAMS_CS12" pin RF12 # TODO: delete
|
||||
signal "SPIRAMS_CS13" pin RF13 # TODO: delete
|
||||
signal "SPIRAMS_CS14" pin RF14 # TODO: delete
|
||||
signal "SPIRAMS_CS15" pin RF15 # TODO: delete
|
||||
signal "SPIRAMS_LED0" pin RG0 # optional LED indicators
|
||||
signal "SPIRAMS_LED1" pin RG1
|
||||
signal "SPIRAMS_LED2" pin RG2
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#
|
||||
SUBDIR = baremetal duinomite duinomite-emega explorer16 \
|
||||
fubarino max32 maximite maximite-color mmb-mx7 \
|
||||
picadillo pinguino-micro sdxl starter-kit ubw32 wf32
|
||||
picadillo pinguino-micro sdxl snadpic starter-kit \
|
||||
ubw32 wf32
|
||||
|
||||
default:
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ Build directories:
|
||||
|
||||
sdxl/ - Majenko SDXL board.
|
||||
|
||||
snadpic/ - SnadPIC MX795 board.
|
||||
|
||||
starter-kit/ - Microchip PIC32MX USB or Ethernet Starter Kit,
|
||||
with I/O Expansion board and SD & MMC pictail.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,16 +26,16 @@ extern int strcmp(char *s1, char *s2);
|
||||
#ifdef SD_ENABLED
|
||||
# include <machine/sd.h>
|
||||
#endif
|
||||
#ifdef SRAMC_ENABLED
|
||||
#ifdef RC_ENABLED
|
||||
# include <machine/sramc.h>
|
||||
#endif
|
||||
#ifdef SDRAMP_ENABLED
|
||||
#ifdef DR_ENABLED
|
||||
# include <machine/sdramp.h>
|
||||
#endif
|
||||
#ifdef MRAMS_ENABLED
|
||||
#ifdef MR_ENABLED
|
||||
# include <machine/mrams.h>
|
||||
#endif
|
||||
#ifdef SPIRAMS_ENABLED
|
||||
#ifdef SR_ENABLED
|
||||
# include <machine/spirams.h>
|
||||
#endif
|
||||
#ifdef UARTUSB_ENABLED
|
||||
@@ -124,7 +124,7 @@ const struct bdevsw bdevsw[] = {
|
||||
#endif
|
||||
},
|
||||
{ /* 1 - sramc */
|
||||
#ifdef SRAMC_ENABLED
|
||||
#ifdef RC_ENABLED
|
||||
sramc_open, sramc_close, sramc_strategy,
|
||||
sramc_size, sramc_ioctl,
|
||||
#else
|
||||
@@ -132,7 +132,7 @@ const struct bdevsw bdevsw[] = {
|
||||
#endif
|
||||
},
|
||||
{ /* 2 - sdramp */
|
||||
#ifdef SDRAMP_ENABLED
|
||||
#ifdef DR_ENABLED
|
||||
sdramp_open, sdramp_close, sdramp_strategy,
|
||||
sdramp_size, sdramp_ioctl,
|
||||
#else
|
||||
@@ -140,7 +140,7 @@ const struct bdevsw bdevsw[] = {
|
||||
#endif
|
||||
},
|
||||
{ /* 3 - mrams */
|
||||
#ifdef MRAMS_ENABLED
|
||||
#ifdef MR_ENABLED
|
||||
mrams_open, mrams_close, mrams_strategy,
|
||||
mrams_size, mrams_ioctl,
|
||||
#else
|
||||
@@ -152,7 +152,7 @@ const struct bdevsw bdevsw[] = {
|
||||
swsize, swcioctl,
|
||||
},
|
||||
{ /* 5 - spirams */
|
||||
#ifdef SPIRAMS_ENABLED
|
||||
#ifdef SR_ENABLED
|
||||
spirams_open, spirams_close, spirams_strategy,
|
||||
spirams_size, spirams_ioctl,
|
||||
#else
|
||||
|
||||
@@ -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
|
||||
|
||||
74
sys/pic32/fubarino/Config-mrams
Normal file
74
sys/pic32/fubarino/Config-mrams
Normal file
@@ -0,0 +1,74 @@
|
||||
#
|
||||
# Fubarino SD board with MRAM swap disk
|
||||
# =====================================
|
||||
# Console on USB.
|
||||
# For details, see https://github.com/RetroBSD/retrobsd/wiki/Board-Fubarino-SD
|
||||
#
|
||||
# To build the kernel, use:
|
||||
# cd sys/pic32/fubarino
|
||||
# kconfig Config-mrams
|
||||
# make clean
|
||||
# make
|
||||
#
|
||||
# Format of this file is described on page:
|
||||
# http://retrobsd.org/wiki/doku.php/doc/kconfig
|
||||
#
|
||||
architecture "pic32"
|
||||
cpu "PIC32MX7" # Processor variant
|
||||
board "FUBARINO" # Board type
|
||||
ldscript "max32/bootloader.ld" # Linker script
|
||||
|
||||
# Standard system options
|
||||
options "CPU_KHZ=80000" # Oscillator frequency of CPU core
|
||||
options "BUS_KHZ=80000" # Frequency of peripheral bus
|
||||
options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
|
||||
|
||||
# LED
|
||||
signal "LED_KERNEL" pin RE5 # kernel activity indicator
|
||||
|
||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||
config unix root on sd0a
|
||||
swap on mr0 # Swap on MRAM disk
|
||||
|
||||
# Console options
|
||||
options "CONS_MAJOR=UARTUSB_MAJOR" # UARTUSB device
|
||||
|
||||
# Virtual UART on USB
|
||||
device uartusb
|
||||
options "USB_MAX_EP_NUMBER=3"
|
||||
options "USB_NUM_STRING_DESCRIPTORS=3"
|
||||
|
||||
# UART ports
|
||||
device uart2 # Pins RF4, RF5
|
||||
|
||||
# SPI ports
|
||||
controller spi2 # SD card
|
||||
controller spi3 # Pins RD1, RD2, RD3
|
||||
|
||||
# microSD card
|
||||
device sd0 at spi2 pin RG9 # select pin
|
||||
|
||||
# General purpose I/O ports
|
||||
# Flags define a mask of available pins
|
||||
# The following pins excluded:
|
||||
# RG6, RG7, RG8, RG9 - spi2, SD card
|
||||
# RD1, RD2, RD3 - spi3
|
||||
# RF4, RF5 - uart2
|
||||
device gpio1 flags 0xffff # port B
|
||||
device gpio2 flags 0xf000 # port C
|
||||
device gpio3 flags 0x0ff1 # port D
|
||||
device gpio4 flags 0x00ff # port E
|
||||
device gpio5 flags 0x000b # port F
|
||||
device gpio6 flags 0x000c # port G
|
||||
|
||||
# ADC driver
|
||||
device adc
|
||||
|
||||
# PWM driver
|
||||
device pwm
|
||||
|
||||
# mrams - SPI block device
|
||||
device mr0 at spi3
|
||||
pins RD4, RD5, RD6, RD7 # chip select signals
|
||||
options "MRAMS_CHIPS=4" # number of chips
|
||||
options "MRAMS_CHIPSIZE=512" # chip size in kbytes
|
||||
77
sys/pic32/fubarino/Config-spirams
Normal file
77
sys/pic32/fubarino/Config-spirams
Normal file
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# Fubarino SD board with RAM disk on SPI port
|
||||
# ===========================================
|
||||
# Console on USB.
|
||||
# For details, see https://github.com/RetroBSD/retrobsd/wiki/Board-Fubarino-SD
|
||||
#
|
||||
# To build the kernel, use:
|
||||
# cd sys/pic32/fubarino
|
||||
# kconfig Config-spirams
|
||||
# make clean
|
||||
# make
|
||||
#
|
||||
# Format of this file is described on page:
|
||||
# http://retrobsd.org/wiki/doku.php/doc/kconfig
|
||||
#
|
||||
architecture "pic32"
|
||||
cpu "PIC32MX7" # Processor variant
|
||||
board "FUBARINO" # Board type
|
||||
ldscript "max32/bootloader.ld" # Linker script
|
||||
|
||||
# Standard system options
|
||||
options "CPU_KHZ=80000" # Oscillator frequency of CPU core
|
||||
options "BUS_KHZ=80000" # Frequency of peripheral bus
|
||||
options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
|
||||
|
||||
# LED
|
||||
signal "LED_KERNEL" pin RE5 # kernel activity indicator
|
||||
|
||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||
config unix root on sd0a
|
||||
swap on sr0 # Swap on SPI RAM disk
|
||||
|
||||
# Console options
|
||||
options "CONS_MAJOR=UARTUSB_MAJOR" # UARTUSB device
|
||||
|
||||
# Virtual UART on USB
|
||||
device uartusb
|
||||
options "USB_MAX_EP_NUMBER=3"
|
||||
options "USB_NUM_STRING_DESCRIPTORS=3"
|
||||
|
||||
# UART ports
|
||||
device uart2 # Pins RF4, RF5
|
||||
|
||||
# SPI ports
|
||||
controller spi2 # SD card
|
||||
controller spi3 # Pins RD1, RD2, RD3
|
||||
|
||||
# microSD card
|
||||
device sd0 at spi2 pin RG9 # select pin
|
||||
|
||||
# General purpose I/O ports
|
||||
# Flags define a mask of available pins
|
||||
# The following pins excluded:
|
||||
# RG6, RG7, RG8, RG9 - spi2, SD card
|
||||
# RD1, RD2, RD3 - spi3
|
||||
# RF4, RF5 - uart2
|
||||
device gpio1 flags 0xffff # port B
|
||||
device gpio2 flags 0xf000 # port C
|
||||
device gpio3 flags 0x0ff1 # port D
|
||||
device gpio4 flags 0x00ff # port E
|
||||
device gpio5 flags 0x000b # port F
|
||||
device gpio6 flags 0x000c # port G
|
||||
|
||||
# ADC driver
|
||||
device adc
|
||||
|
||||
# PWM driver
|
||||
device pwm
|
||||
|
||||
# spirams - SPI block device
|
||||
device sr0 at spi3
|
||||
pins RD4, RD5, RD6, RD7, # chip select signals
|
||||
RD8, RD9, RD10, RD11,
|
||||
RE0, RE1, RE2, RE3,
|
||||
RE4, RE5, RE6, RE7
|
||||
options "SPIRAMS_CHIPS=16" # number of chips
|
||||
options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes
|
||||
@@ -1,13 +1,13 @@
|
||||
#
|
||||
# Fubarino SD board SRAMC swap disk
|
||||
# =================================
|
||||
# Fubarino SD board with SRAMC swap disk
|
||||
# ======================================
|
||||
# Console on UART2.
|
||||
# Overclocked to 120MHz.
|
||||
# Clock rate increased to 1000Hz.
|
||||
#
|
||||
# To build the kernel, use:
|
||||
# cd sys/pic32/fubarino-uart-sramc
|
||||
# kconfig Config
|
||||
# cd sys/pic32/fubarino
|
||||
# kconfig Config-uart-sramc
|
||||
# make clean
|
||||
# make
|
||||
#
|
||||
@@ -33,7 +33,7 @@ signal "LED_KERNEL" pin RE5 # kernel activity indicator
|
||||
|
||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||
config unix root on sd0a
|
||||
swap on sd0b
|
||||
swap on rc0b # Swap on SRAM disk
|
||||
|
||||
# Console options
|
||||
options "CONS_MAJOR=UART_MAJOR" # UART device
|
||||
@@ -70,5 +70,8 @@ device adc
|
||||
device pwm
|
||||
|
||||
# sramc - SRAM block device
|
||||
device sramc0 # SRAM via 4-wire CPLD interface
|
||||
options "PARTITION='sramc0:sa@2048,fs@6140'" # Partition schema
|
||||
# The volume is divided into two partitions: A and B.
|
||||
# Size of partition B is specified as option SRAMC_SWAP_KBYTES.
|
||||
# The rest is partition A.
|
||||
device rc0 # SRAM via 4-wire CPLD interface
|
||||
options "SRAMC_SWAP_KBYTES=2048" # size of partition B
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* TODO: Modify this driver to be able to function without rdisk layer.
|
||||
* Disk driver for serial MRAM chips connected via SPI port.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@@ -8,7 +8,8 @@
|
||||
#include <sys/dk.h>
|
||||
#include <sys/disk.h>
|
||||
#include <sys/spi.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/kconfig.h>
|
||||
#include <machine/debug.h>
|
||||
#include <machine/mrams.h>
|
||||
|
||||
#define MRAM_WREN 0x06
|
||||
@@ -26,10 +27,12 @@
|
||||
|
||||
struct spiio mrams_io[MRAMS_CHIPS];
|
||||
|
||||
int mrams_size(int unit)
|
||||
{
|
||||
return MRAMS_CHIPS * MRAMS_CHIPSIZE;
|
||||
}
|
||||
int mrams_dkindex; /* disk index for statistics */
|
||||
|
||||
/*
|
||||
* Size of RAM disk.
|
||||
*/
|
||||
#define MRAMS_TOTAL_KBYTES (MRAMS_CHIPS * MRAMS_CHIPSIZE)
|
||||
|
||||
#define MRBSIZE 1024
|
||||
#define MRBLOG2 10
|
||||
@@ -108,7 +111,7 @@ unsigned int mr_read_block(unsigned int chip, unsigned int address, unsigned int
|
||||
return cs;
|
||||
}
|
||||
|
||||
int mrams_read(int unit, unsigned int offset, char *data, unsigned int bcount)
|
||||
int mrams_read(unsigned int offset, char *data, unsigned int bcount)
|
||||
{
|
||||
register unsigned int chip;
|
||||
register unsigned int toread;
|
||||
@@ -211,7 +214,7 @@ unsigned int mr_write_block(unsigned int chip, unsigned int address, unsigned in
|
||||
return cs;
|
||||
}
|
||||
|
||||
int mrams_write(int unit, unsigned int offset, char *data, unsigned bcount)
|
||||
int mrams_write(unsigned int offset, char *data, unsigned bcount)
|
||||
{
|
||||
register unsigned int chip;
|
||||
register unsigned int address;
|
||||
@@ -240,27 +243,25 @@ int mrams_write(int unit, unsigned int offset, char *data, unsigned bcount)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mrams_preinit(int unit)
|
||||
/*
|
||||
* Initialize hardware.
|
||||
*/
|
||||
static int mrams_init(int spi_port, int cs0, int cs1, int cs2, int cs3)
|
||||
{
|
||||
struct spiio *io = &mrams_io[0];
|
||||
struct buf *bp;
|
||||
|
||||
if (unit >= 1)
|
||||
return;
|
||||
|
||||
/* Initialize hardware. */
|
||||
|
||||
if (spi_setup(io, MRAMS_PORT, (unsigned int *)&MRAMS_CS0_PORT, MRAMS_CS0_PIN) != 0)
|
||||
return;
|
||||
|
||||
if (spi_setup(io, spi_port, cs0) != 0) {
|
||||
printf("mr0: cannot open SPI%u port\n", spi_port);
|
||||
return 0;
|
||||
}
|
||||
spi_brg(io, MRAMS_MHZ * 1000);
|
||||
spi_set(io, PIC32_SPICON_CKE);
|
||||
spi_select(io);
|
||||
spi_transfer(io, MRAM_WREN);
|
||||
spi_deselect(io);
|
||||
|
||||
#ifdef MRAMS_CS1_PORT
|
||||
spi_setup(io+1, MRAMS_PORT, (unsigned int *)&MRAMS_CS1_PORT, MRAMS_CS1_PIN);
|
||||
#if MRAMS_CHIPS >= 1
|
||||
spi_setup(io+1, spi_port, cs1);
|
||||
|
||||
spi_brg(io+1, MRAMS_MHZ * 1000);
|
||||
spi_set(io+1, PIC32_SPICON_CKE);
|
||||
@@ -268,8 +269,8 @@ void mrams_preinit(int unit)
|
||||
spi_transfer(io+1, MRAM_WREN);
|
||||
spi_deselect(io+1);
|
||||
#endif
|
||||
#ifdef MRAMS_CS2_PORT
|
||||
spi_setup(io+2, MRAMS_PORT, (unsigned int *)&MRAMS_CS2_PORT, MRAMS_CS2_PIN);
|
||||
#if MRAMS_CHIPS >= 2
|
||||
spi_setup(io+2, spi_port, cs2);
|
||||
|
||||
spi_brg(io+2, MRAMS_MHZ * 1000);
|
||||
spi_set(io+2, PIC32_SPICON_CKE);
|
||||
@@ -277,8 +278,8 @@ void mrams_preinit(int unit)
|
||||
spi_transfer(io+2, MRAM_WREN);
|
||||
spi_deselect(io+2);
|
||||
#endif
|
||||
#ifdef MRAMS_CS3_PORT
|
||||
spi_setup(io+3, MRAMS_PORT, (unsigned int *)&MRAMS_CS3_PORT, MRAMS_CS3_PIN);
|
||||
#if MRAMS_CHIPS >= 3
|
||||
spi_setup(io+3, spi_port, cs3);
|
||||
|
||||
spi_brg(io+3, MRAMS_MHZ * 1000);
|
||||
spi_set(io+3, PIC32_SPICON_CKE);
|
||||
@@ -287,12 +288,137 @@ void mrams_preinit(int unit)
|
||||
spi_deselect(io+3);
|
||||
#endif
|
||||
|
||||
printf("mrams0: port %s, size %dKB, speed %d Mbit/sec\n",
|
||||
spi_name(MRAMS_PORT), MRAMS_CHIPS * MRAMS_CHIPSIZE,
|
||||
spi_get_brg(io) / 1000);
|
||||
bp = prepartition_device("mrams0");
|
||||
if (bp) {
|
||||
mrams_write(0, 0, bp->b_addr, 512);
|
||||
brelse(bp);
|
||||
}
|
||||
printf("mr0: size %dKB, speed %d Mbit/sec\n",
|
||||
MRAMS_CHIPS * MRAMS_CHIPSIZE, spi_get_brg(io) / 1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the disk.
|
||||
*/
|
||||
int mrams_open(dev_t dev, int flag, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mrams_close(dev_t dev, int flag, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the size of the device in kbytes.
|
||||
*/
|
||||
daddr_t mrams_size(dev_t dev)
|
||||
{
|
||||
return MRAMS_TOTAL_KBYTES;
|
||||
}
|
||||
|
||||
void mrams_strategy(struct buf *bp)
|
||||
{
|
||||
int offset = bp->b_blkno;
|
||||
long nblk = btod(bp->b_bcount);
|
||||
int s;
|
||||
|
||||
/*
|
||||
* Determine the size of the transfer, and make sure it is
|
||||
* within the boundaries of the partition.
|
||||
*/
|
||||
if (bp->b_blkno + nblk > MRAMS_TOTAL_KBYTES) {
|
||||
/* if exactly at end of partition, return an EOF */
|
||||
if (bp->b_blkno == MRAMS_TOTAL_KBYTES) {
|
||||
bp->b_resid = bp->b_bcount;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
/* or truncate if part of it fits */
|
||||
nblk = MRAMS_TOTAL_KBYTES - bp->b_blkno;
|
||||
if (nblk <= 0) {
|
||||
bp->b_error = EINVAL;
|
||||
bp->b_flags |= B_ERROR;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
bp->b_bcount = nblk << DEV_BSHIFT;
|
||||
}
|
||||
|
||||
led_control(LED_SWAP, 1);
|
||||
|
||||
s = splbio();
|
||||
#ifdef UCB_METER
|
||||
if (mrams_dkindex >= 0) {
|
||||
dk_busy |= 1 << mrams_dkindex;
|
||||
dk_xfer[mrams_dkindex]++;
|
||||
dk_bytes[mrams_dkindex] += bp->b_bcount;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bp->b_flags & B_READ) {
|
||||
mrams_read(offset, bp->b_addr, bp->b_bcount);
|
||||
} else {
|
||||
mrams_write(offset, bp->b_addr, bp->b_bcount);
|
||||
}
|
||||
|
||||
biodone(bp);
|
||||
led_control(LED_SWAP, 0);
|
||||
#ifdef UCB_METER
|
||||
if (mrams_dkindex >= 0)
|
||||
dk_busy &= ~(1 << mrams_dkindex);
|
||||
#endif
|
||||
splx(s);
|
||||
}
|
||||
|
||||
int mrams_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 = MRAMS_TOTAL_KBYTES;
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test to see if device is present.
|
||||
* Return true if found and initialized ok.
|
||||
*/
|
||||
static int
|
||||
mrams_probe(config)
|
||||
struct conf_device *config;
|
||||
{
|
||||
int cs0 = config->dev_pins[0];
|
||||
int cs1 = config->dev_pins[1];
|
||||
int cs2 = config->dev_pins[2];
|
||||
int cs3 = config->dev_pins[3];
|
||||
|
||||
/* Only one device unit is supported. */
|
||||
if (config->dev_unit != 0)
|
||||
return 0;
|
||||
|
||||
printf("mr0: port SPI%d, pins cs0=R%c%d/cs1=R%c%d/cs2=R%c%d/cs3=R%c%d\n",
|
||||
config->dev_ctlr,
|
||||
gpio_portname(cs0), gpio_pinno(cs0),
|
||||
gpio_portname(cs1), gpio_pinno(cs1),
|
||||
gpio_portname(cs2), gpio_pinno(cs2),
|
||||
gpio_portname(cs3), gpio_pinno(cs3));
|
||||
|
||||
if (mrams_init(config->dev_ctlr, cs0, cs1, cs2, cs3) != 0)
|
||||
return 0;
|
||||
|
||||
#ifdef UCB_METER
|
||||
dk_alloc(&mrams_dkindex, 1, "mr0");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct driver mrdriver = {
|
||||
"mr", mrams_probe,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef _MRAMS_H
|
||||
#define _MRAMS_H
|
||||
|
||||
extern int mrams_size(int unit);
|
||||
extern int mrams_read(int unit, unsigned int offset, char *data, unsigned int bcount);
|
||||
extern int mrams_write (int unit, unsigned offset, char *data, unsigned bcount);
|
||||
extern void mrams_preinit (int unit);
|
||||
#ifdef KERNEL
|
||||
extern int mrams_open(dev_t dev, int flag, int mode);
|
||||
extern int mrams_close(dev_t dev, int flag, int mode);
|
||||
extern daddr_t mrams_size(dev_t dev);
|
||||
extern void mrams_strategy(struct buf *bp);
|
||||
extern int mrams_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -877,11 +877,7 @@ sd_probe(config)
|
||||
printf("sd%u: port SPI%d, pin cs=R%c%d\n", unit,
|
||||
config->dev_ctlr, gpio_portname(cs), gpio_pinno(cs));
|
||||
|
||||
int port = (cs >> 4) - 1;
|
||||
int pin = cs & 15;
|
||||
struct gpioreg *base = port + (struct gpioreg*) &TRISA;
|
||||
|
||||
if (spi_setup(io, config->dev_ctlr, (unsigned int*) base, pin) != 0) {
|
||||
if (spi_setup(io, config->dev_ctlr, cs) != 0) {
|
||||
printf("sd%u: cannot open SPI%u port\n", unit, config->dev_ctlr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
65
sys/pic32/snadpic/Config
Normal file
65
sys/pic32/snadpic/Config
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# SnadPIC MX795 board
|
||||
# ===================
|
||||
# Console on USB.
|
||||
#
|
||||
# To build the kernel, use:
|
||||
# cd sys/pic32/snadpic
|
||||
# kconfig Config
|
||||
# make clean
|
||||
# make
|
||||
#
|
||||
# Format of this file is described on page:
|
||||
# http://retrobsd.org/wiki/doku.php/doc/kconfig
|
||||
#
|
||||
architecture "pic32"
|
||||
cpu "PIC32MX7" # Processor variant
|
||||
board "SNADPIC" # Board type
|
||||
ldscript "maximite/bootloader.ld" # Linker script
|
||||
|
||||
# Standard system options
|
||||
options "CPU_KHZ=80000" # Oscillator frequency of CPU core
|
||||
options "BUS_KHZ=80000" # Frequency of peripheral bus
|
||||
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
|
||||
|
||||
# Console options
|
||||
options "CONS_MAJOR=UARTUSB_MAJOR" # UARTUSB device
|
||||
|
||||
# Virtual UART on USB
|
||||
device uartusb
|
||||
options "USB_MAX_EP_NUMBER=3"
|
||||
options "USB_NUM_STRING_DESCRIPTORS=3"
|
||||
|
||||
# UART ports
|
||||
device uart2 # Pins RF4, RF5
|
||||
|
||||
# SPI ports
|
||||
controller spi2 # SD card
|
||||
controller spi3 # Pins RD1, RD2, RD3
|
||||
|
||||
# microSD card
|
||||
device sd0 at spi2 pin RG9 # select pin
|
||||
|
||||
# General purpose I/O ports
|
||||
# Flags define a mask of available pins
|
||||
# The following pins excluded:
|
||||
# RG6, RG7, RG8, RG9 - spi2, SD card
|
||||
# RD1, RD2, RD3 - spi3
|
||||
# RF4, RF5 - uart2
|
||||
device gpio0 flags 0xc6ff # port A
|
||||
device gpio1 flags 0xffff # port B
|
||||
device gpio2 flags 0xf01e # port C
|
||||
device gpio3 flags 0xfff1 # port D
|
||||
device gpio4 flags 0x03ff # port E
|
||||
device gpio5 flags 0x310f # port F
|
||||
device gpio6 flags 0xf00f # port G
|
||||
|
||||
# ADC driver
|
||||
device adc
|
||||
|
||||
# PWM driver
|
||||
device pwm
|
||||
362
sys/pic32/snadpic/Makefile
Normal file
362
sys/pic32/snadpic/Makefile
Normal file
@@ -0,0 +1,362 @@
|
||||
PARAM = -DSNADPIC
|
||||
PARAM += -DPIC32MX7
|
||||
PARAM += -DUARTUSB_ENABLED
|
||||
PARAM += -DUART2_ENABLED
|
||||
PARAM += -DSPI2_ENABLED
|
||||
PARAM += -DSPI3_ENABLED
|
||||
PARAM += -DSD_ENABLED
|
||||
PARAM += -DGPIO_ENABLED
|
||||
PARAM += -DGPIO1_ENABLED
|
||||
PARAM += -DGPIO2_ENABLED
|
||||
PARAM += -DGPIO3_ENABLED
|
||||
PARAM += -DGPIO4_ENABLED
|
||||
PARAM += -DGPIO5_ENABLED
|
||||
PARAM += -DGPIO6_ENABLED
|
||||
PARAM += -DADC_ENABLED
|
||||
PARAM += -DPWM_ENABLED
|
||||
PARAM += -DUSB_NUM_STRING_DESCRIPTORS=3
|
||||
PARAM += -DUSB_MAX_EP_NUMBER=3
|
||||
PARAM += -DCONS_MAJOR=UARTUSB_MAJOR
|
||||
PARAM += -DBUS_DIV=1
|
||||
PARAM += -DBUS_KHZ=80000
|
||||
PARAM += -DCPU_KHZ=80000
|
||||
LDSCRIPT = "maximite/bootloader.ld"
|
||||
#
|
||||
# Makefile for RetroBSD, pic32 target
|
||||
#
|
||||
# DEBUG is set to -g by kconfig if debugging is requested (kconfig -g).
|
||||
#
|
||||
include ../gcc-config.mk
|
||||
|
||||
AS = ${MIPS_GCC_PREFIX}as ${DEBUG} -mips32r2 -EL
|
||||
CC = ${MIPS_GCC_PREFIX}gcc ${DEBUG} -mips32r2 -EL -nostdinc -fno-builtin -Werror -Wall
|
||||
CPP = ${MIPS_GCC_PREFIX}cpp
|
||||
LD = ${MIPS_GCC_PREFIX}gcc -mips32r2 -EL
|
||||
LDFLAGS = -nostdlib -T ../${LDSCRIPT} -Wl,-Map=$(basename $@).map
|
||||
SIZE = ${MIPS_GCC_PREFIX}size
|
||||
OBJCOPY = ${MIPS_GCC_PREFIX}objcopy
|
||||
OBJDUMP = ${MIPS_GCC_PREFIX}objdump
|
||||
|
||||
ifneq (${MIPS_GCC_FORMAT},)
|
||||
LDFLAGS += -Wl,--oformat=${MIPS_GCC_FORMAT}
|
||||
endif
|
||||
|
||||
# sources are located via $S relative to the compilation directory
|
||||
S = ../..
|
||||
|
||||
DEPFLAGS = -MT $@ -MP -MD -MF .deps/$*.dep
|
||||
DEFS = -I. ${PARAM} -DKERNEL $(DEPFLAGS)
|
||||
CFLAGS = -O ${DEFS}
|
||||
|
||||
# compile rules: rules are named COMPILE_${SUFFIX}
|
||||
# SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
|
||||
|
||||
COMPILE_C = ${CC} -c ${CFLAGS} $<
|
||||
COMPILE_S = ${CC} -c ${DEFS} $<
|
||||
|
||||
OBJS = exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o \
|
||||
init_main.o init_sysent.o kern_clock.o kern_descrip.o \
|
||||
kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o \
|
||||
kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o \
|
||||
kern_subr.o kern_synch.o kern_sysctl.o kern_time.o subr_prf.o \
|
||||
subr_rmap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o \
|
||||
syscalls.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o \
|
||||
ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o \
|
||||
ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o \
|
||||
vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o clock.o cons.o devsw.o \
|
||||
exception.o machdep.o mem.o signal.o swap.o sysctl.o adc.o \
|
||||
gpio.o pwm.o sd.o spi.o spi_bus.o uart.o usb_device.o \
|
||||
usb_function_cdc.o usb_uart.o
|
||||
|
||||
CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
|
||||
$S/kernel/exec_script.c $S/kernel/exec_subr.c \
|
||||
$S/kernel/init_main.c $S/kernel/init_sysent.c \
|
||||
$S/kernel/kern_clock.c $S/kernel/kern_descrip.c \
|
||||
$S/kernel/kern_exec.c $S/kernel/kern_exit.c \
|
||||
$S/kernel/kern_fork.c $S/kernel/kern_mman.c \
|
||||
$S/kernel/kern_proc.c $S/kernel/kern_prot.c \
|
||||
$S/kernel/kern_prot2.c $S/kernel/kern_resource.c \
|
||||
$S/kernel/kern_sig.c $S/kernel/kern_sig2.c $S/kernel/kern_subr.c \
|
||||
$S/kernel/kern_synch.c $S/kernel/kern_sysctl.c \
|
||||
$S/kernel/kern_time.c $S/kernel/subr_prf.c $S/kernel/subr_rmap.c \
|
||||
$S/kernel/sys_generic.c $S/kernel/sys_inode.c \
|
||||
$S/kernel/sys_pipe.c $S/kernel/sys_process.c \
|
||||
$S/kernel/syscalls.c $S/kernel/tty.c $S/kernel/tty_subr.c \
|
||||
$S/kernel/tty_tty.c $S/kernel/ufs_alloc.c $S/kernel/ufs_bio.c \
|
||||
$S/kernel/ufs_bmap.c $S/kernel/ufs_dsort.c $S/kernel/ufs_fio.c \
|
||||
$S/kernel/ufs_inode.c $S/kernel/ufs_mount.c \
|
||||
$S/kernel/ufs_namei.c $S/kernel/ufs_subr.c \
|
||||
$S/kernel/ufs_syscalls.c $S/kernel/ufs_syscalls2.c \
|
||||
$S/kernel/vfs_vnops.c $S/kernel/vm_sched.c $S/kernel/vm_swap.c \
|
||||
$S/kernel/vm_swp.c $S/pic32/clock.c $S/pic32/cons.c \
|
||||
$S/pic32/devsw.c $S/pic32/exception.c $S/pic32/machdep.c \
|
||||
$S/pic32/mem.c $S/pic32/signal.c $S/pic32/swap.c \
|
||||
$S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/gpio.c $S/pic32/pwm.c \
|
||||
$S/pic32/sd.c $S/pic32/spi.c $S/pic32/spi_bus.c $S/pic32/uart.c \
|
||||
$S/pic32/usb_device.c $S/pic32/usb_function_cdc.c \
|
||||
$S/pic32/usb_uart.c swapunix.c
|
||||
|
||||
# load lines for config "xxx" will be emitted as:
|
||||
# xxx: ${SYSTEM_DEP} swapxxx.o
|
||||
# ${SYSTEM_LD_HEAD}
|
||||
# ${SYSTEM_LD} swapxxx.o
|
||||
# ${SYSTEM_LD_TAIL}
|
||||
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
|
||||
ifeq (devcfg.c,$(wildcard devcfg.c))
|
||||
SYSTEM_OBJ += devcfg.o
|
||||
endif
|
||||
SYSTEM_DEP = Makefile ioconf.c machine sys .deps ${SYSTEM_OBJ}
|
||||
SYSTEM_LD_HEAD = sh ../newvers.sh > vers.c; ${CC} $(CFLAGS) -c vers.c; rm -f $@
|
||||
SYSTEM_LD = -@echo ${LD} ${LDFLAGS} '$${SYSTEM_OBJ}' vers.o -o $@; \
|
||||
${LD} ${LDFLAGS} ${SYSTEM_OBJ} vers.o -o $@
|
||||
SYSTEM_LD_TAIL = ${SIZE} $@; \
|
||||
$(OBJCOPY) -O ihex --change-addresses=0x80000000 $@ $(basename $@).hex; \
|
||||
$(OBJCOPY) -O binary -R .boot -R .config $@ $(basename $@).bin; \
|
||||
$(OBJDUMP) -d -S $@ > $(basename $@).dis
|
||||
|
||||
unix: unix.elf
|
||||
|
||||
unix.elf: ${SYSTEM_DEP} swapunix.o
|
||||
${SYSTEM_LD_HEAD}
|
||||
${SYSTEM_LD} swapunix.o
|
||||
${SYSTEM_LD_TAIL}
|
||||
|
||||
swapunix.o: swapunix.c
|
||||
${COMPILE_C}
|
||||
|
||||
all: unix
|
||||
|
||||
clean:
|
||||
rm -rf .deps *.elf *.o *.map *.dis *.bin machine sys
|
||||
|
||||
clean-all: clean
|
||||
rm -f *.h *.hex ioconf.c swap*.c vers.c
|
||||
|
||||
reconfig ioconf.c: Config ../../../tools/kconfig/kconfig
|
||||
../../../tools/kconfig/kconfig Config
|
||||
$(MAKE) clean
|
||||
rm -f *.hex
|
||||
|
||||
load: unix.elf
|
||||
pic32prog unix.hex
|
||||
|
||||
machine:
|
||||
ln -s .. $@
|
||||
|
||||
sys:
|
||||
ln -s ../../include $@
|
||||
|
||||
.deps:
|
||||
mkdir .deps
|
||||
|
||||
startup.o: ../startup.S
|
||||
${COMPILE_S}
|
||||
|
||||
ioconf.o: ioconf.c
|
||||
${COMPILE_C}
|
||||
|
||||
exec_aout.o: $S/kernel/exec_aout.c
|
||||
${COMPILE_C}
|
||||
|
||||
exec_conf.o: $S/kernel/exec_conf.c
|
||||
${COMPILE_C}
|
||||
|
||||
exec_elf.o: $S/kernel/exec_elf.c
|
||||
${COMPILE_C}
|
||||
|
||||
exec_script.o: $S/kernel/exec_script.c
|
||||
${COMPILE_C}
|
||||
|
||||
exec_subr.o: $S/kernel/exec_subr.c
|
||||
${COMPILE_C}
|
||||
|
||||
init_main.o: $S/kernel/init_main.c
|
||||
${COMPILE_C}
|
||||
|
||||
init_sysent.o: $S/kernel/init_sysent.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_clock.o: $S/kernel/kern_clock.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_descrip.o: $S/kernel/kern_descrip.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_exec.o: $S/kernel/kern_exec.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_exit.o: $S/kernel/kern_exit.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_fork.o: $S/kernel/kern_fork.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_mman.o: $S/kernel/kern_mman.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_proc.o: $S/kernel/kern_proc.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_prot.o: $S/kernel/kern_prot.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_prot2.o: $S/kernel/kern_prot2.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_resource.o: $S/kernel/kern_resource.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_sig.o: $S/kernel/kern_sig.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_sig2.o: $S/kernel/kern_sig2.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_subr.o: $S/kernel/kern_subr.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_synch.o: $S/kernel/kern_synch.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_sysctl.o: $S/kernel/kern_sysctl.c
|
||||
${COMPILE_C}
|
||||
|
||||
kern_time.o: $S/kernel/kern_time.c
|
||||
${COMPILE_C}
|
||||
|
||||
subr_prf.o: $S/kernel/subr_prf.c
|
||||
${COMPILE_C}
|
||||
|
||||
subr_rmap.o: $S/kernel/subr_rmap.c
|
||||
${COMPILE_C}
|
||||
|
||||
sys_generic.o: $S/kernel/sys_generic.c
|
||||
${COMPILE_C}
|
||||
|
||||
sys_inode.o: $S/kernel/sys_inode.c
|
||||
${COMPILE_C}
|
||||
|
||||
sys_pipe.o: $S/kernel/sys_pipe.c
|
||||
${COMPILE_C}
|
||||
|
||||
sys_process.o: $S/kernel/sys_process.c
|
||||
${COMPILE_C}
|
||||
|
||||
syscalls.o: $S/kernel/syscalls.c
|
||||
${COMPILE_C}
|
||||
|
||||
tty.o: $S/kernel/tty.c
|
||||
${COMPILE_C}
|
||||
|
||||
tty_subr.o: $S/kernel/tty_subr.c
|
||||
${COMPILE_C}
|
||||
|
||||
tty_tty.o: $S/kernel/tty_tty.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_alloc.o: $S/kernel/ufs_alloc.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_bio.o: $S/kernel/ufs_bio.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_bmap.o: $S/kernel/ufs_bmap.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_dsort.o: $S/kernel/ufs_dsort.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_fio.o: $S/kernel/ufs_fio.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_inode.o: $S/kernel/ufs_inode.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_mount.o: $S/kernel/ufs_mount.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_namei.o: $S/kernel/ufs_namei.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_subr.o: $S/kernel/ufs_subr.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_syscalls.o: $S/kernel/ufs_syscalls.c
|
||||
${COMPILE_C}
|
||||
|
||||
ufs_syscalls2.o: $S/kernel/ufs_syscalls2.c
|
||||
${COMPILE_C}
|
||||
|
||||
vfs_vnops.o: $S/kernel/vfs_vnops.c
|
||||
${COMPILE_C}
|
||||
|
||||
vm_sched.o: $S/kernel/vm_sched.c
|
||||
${COMPILE_C}
|
||||
|
||||
vm_swap.o: $S/kernel/vm_swap.c
|
||||
${COMPILE_C}
|
||||
|
||||
vm_swp.o: $S/kernel/vm_swp.c
|
||||
${COMPILE_C}
|
||||
|
||||
clock.o: $S/pic32/clock.c
|
||||
${COMPILE_C}
|
||||
|
||||
cons.o: $S/pic32/cons.c
|
||||
${COMPILE_C}
|
||||
|
||||
devsw.o: $S/pic32/devsw.c
|
||||
${COMPILE_C}
|
||||
|
||||
exception.o: $S/pic32/exception.c
|
||||
${COMPILE_C}
|
||||
|
||||
machdep.o: $S/pic32/machdep.c
|
||||
${COMPILE_C}
|
||||
|
||||
mem.o: $S/pic32/mem.c
|
||||
${COMPILE_C}
|
||||
|
||||
signal.o: $S/pic32/signal.c
|
||||
${COMPILE_C}
|
||||
|
||||
swap.o: $S/pic32/swap.c
|
||||
${COMPILE_C}
|
||||
|
||||
sysctl.o: $S/pic32/sysctl.c
|
||||
${COMPILE_C}
|
||||
|
||||
adc.o: $S/pic32/adc.c
|
||||
${COMPILE_C}
|
||||
|
||||
gpio.o: $S/pic32/gpio.c
|
||||
${COMPILE_C}
|
||||
|
||||
pwm.o: $S/pic32/pwm.c
|
||||
${COMPILE_C}
|
||||
|
||||
sd.o: $S/pic32/sd.c
|
||||
${COMPILE_C}
|
||||
|
||||
spi.o: $S/pic32/spi.c
|
||||
${COMPILE_C}
|
||||
|
||||
spi_bus.o: $S/pic32/spi_bus.c
|
||||
${COMPILE_C}
|
||||
|
||||
uart.o: $S/pic32/uart.c
|
||||
${COMPILE_C}
|
||||
|
||||
usb_device.o: $S/pic32/usb_device.c
|
||||
${COMPILE_C}
|
||||
|
||||
usb_function_cdc.o: $S/pic32/usb_function_cdc.c
|
||||
${COMPILE_C}
|
||||
|
||||
usb_uart.o: $S/pic32/usb_uart.c
|
||||
${COMPILE_C}
|
||||
|
||||
|
||||
ifeq (.deps, $(wildcard .deps))
|
||||
-include .deps/*.dep
|
||||
endif
|
||||
@@ -317,7 +317,7 @@ spiprobe(config)
|
||||
gpio_portname(sdo), gpio_pinno(sdo),
|
||||
gpio_portname(sck), gpio_pinno(sck));
|
||||
|
||||
if (spi_setup(io, channel+1, 0, 0) != 0) {
|
||||
if (spi_setup(io, channel+1, 0) != 0) {
|
||||
printf("spi%u: setup failed\n", channel+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,11 +28,21 @@ static struct spireg *const spi_base[NSPI] = {
|
||||
// Returns an integer for the number of the device (ala fd).
|
||||
// Returns -1 if no devices are available.
|
||||
//
|
||||
int spi_setup(struct spiio *io, int channel, unsigned int *tris, unsigned int pin)
|
||||
int spi_setup(struct spiio *io, int channel, int cs)
|
||||
{
|
||||
unsigned *tris = 0;
|
||||
int pin = 0;
|
||||
|
||||
if (channel <= 0 || channel > NSPI)
|
||||
return ENXIO;
|
||||
|
||||
if (cs != 0) {
|
||||
/* Compute the port address and pin index of the chip select signal. */
|
||||
int port = (cs >> 4) - 1;
|
||||
tris = (unsigned*) (port + (struct gpioreg*) &TRISA);
|
||||
pin = cs & 15;
|
||||
}
|
||||
|
||||
// Set up the device
|
||||
io->bus = spi_base[channel-1];
|
||||
io->cs_tris = tris;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/*
|
||||
* TODO: Modify this driver to be able to function without rdisk layer.
|
||||
* Disk driver for serial RAM chips connected via SPI port.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/dk.h>
|
||||
#include <sys/disk.h>
|
||||
#include <sys/spi.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/kconfig.h>
|
||||
#include <machine/debug.h>
|
||||
#include <machine/spirams.h>
|
||||
|
||||
#define SPIRAM_WREN 0x06
|
||||
@@ -25,10 +27,12 @@
|
||||
|
||||
struct spiio spirams_io[SPIRAMS_CHIPS];
|
||||
|
||||
int spirams_size(int unit)
|
||||
{
|
||||
return SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE;
|
||||
}
|
||||
int spirams_dkindex; /* disk index for statistics */
|
||||
|
||||
/*
|
||||
* Size of RAM disk.
|
||||
*/
|
||||
#define SPIRAMS_TOTAL_KBYTES (SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE)
|
||||
|
||||
#define MRBSIZE 1024
|
||||
#define MRBLOG2 10
|
||||
@@ -179,7 +183,7 @@ unsigned int spir_read_block(unsigned int chip, unsigned int address, unsigned i
|
||||
return cs;
|
||||
}
|
||||
|
||||
int spirams_read(int unit, unsigned int offset, char *data, unsigned int bcount)
|
||||
int spirams_read(unsigned int offset, char *data, unsigned int bcount)
|
||||
{
|
||||
register unsigned int chip;
|
||||
register unsigned int toread;
|
||||
@@ -282,7 +286,7 @@ unsigned int spir_write_block(unsigned int chip, unsigned int address, unsigned
|
||||
return cs;
|
||||
}
|
||||
|
||||
int spirams_write (int unit, unsigned int offset, char *data, unsigned bcount)
|
||||
int spirams_write (unsigned int offset, char *data, unsigned bcount)
|
||||
{
|
||||
register unsigned int chip;
|
||||
register unsigned int address;
|
||||
@@ -311,119 +315,242 @@ int spirams_write (int unit, unsigned int offset, char *data, unsigned bcount)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void spirams_preinit (int unit)
|
||||
/*
|
||||
* Initialize hardware.
|
||||
*/
|
||||
static int spirams_init(int spi_port, char cs[])
|
||||
{
|
||||
struct spiio *io = &spirams_io[0];
|
||||
struct buf *bp;
|
||||
|
||||
if (unit >= 1)
|
||||
return;
|
||||
|
||||
/* Initialize hardware. */
|
||||
|
||||
if (spi_setup(io, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS0_PORT,SPIRAMS_CS0_PIN) != 0)
|
||||
return;
|
||||
|
||||
if (spi_setup(io, spi_port, cs[0]) != 0) {
|
||||
printf("sr0: cannot open SPI%u port\n", spi_port);
|
||||
return 0;
|
||||
}
|
||||
spi_brg(io, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io, PIC32_SPICON_CKE);
|
||||
|
||||
#ifdef SPIRAMS_CS1_PORT
|
||||
spi_setup(io+1, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS1_PORT,SPIRAMS_CS1_PIN);
|
||||
#if SPIRAMS_CHIPS >= 1
|
||||
spi_setup(io+1, spi_port, cs[1]);
|
||||
|
||||
spi_brg(io+1, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+1, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS2_PORT
|
||||
spi_setup(io+2, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS2_PORT,SPIRAMS_CS2_PIN);
|
||||
#if SPIRAMS_CHIPS >= 2
|
||||
spi_setup(io+2, spi_port, cs[2]);
|
||||
|
||||
spi_brg(io+2, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+2, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS3_PORT
|
||||
spi_setup(io+3, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS3_PORT,SPIRAMS_CS3_PIN);
|
||||
#if SPIRAMS_CHIPS >= 3
|
||||
spi_setup(io+3, spi_port, cs[3]);
|
||||
|
||||
spi_brg(io+3, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+3, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS4_PORT
|
||||
spi_setup(io+4, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS4_PORT,SPIRAMS_CS4_PIN);
|
||||
#if SPIRAMS_CHIPS >= 4
|
||||
spi_setup(io+4, spi_port, cs[4]);
|
||||
|
||||
spi_brg(io+4, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+4, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS5_PORT
|
||||
spi_setup(io+5, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS5_PORT,SPIRAMS_CS5_PIN);
|
||||
#if SPIRAMS_CHIPS >= 5
|
||||
spi_setup(io+5, spi_port, cs[5]);
|
||||
|
||||
spi_brg(io+5, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+5, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS6_PORT
|
||||
spi_setup(io+6, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS6_PORT,SPIRAMS_CS6_PIN);
|
||||
#if SPIRAMS_CHIPS >= 6
|
||||
spi_setup(io+6, spi_port, cs[6]);
|
||||
|
||||
spi_brg(io+6, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+6, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS7_PORT
|
||||
spi_setup(io+7, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS7_PORT,SPIRAMS_CS7_PIN);
|
||||
#if SPIRAMS_CHIPS >= 7
|
||||
spi_setup(io+7, spi_port, cs[7]);
|
||||
|
||||
spi_brg(io+7, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+7, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS8_PORT
|
||||
spi_setup(io+8, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS8_PORT,SPIRAMS_CS8_PIN);
|
||||
#if SPIRAMS_CHIPS >= 8
|
||||
spi_setup(io+8, spi_port, cs[8]);
|
||||
|
||||
spi_brg(io+8, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+8, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS9_PORT
|
||||
spi_setup(io+9, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS9_PORT,SPIRAMS_CS9_PIN);
|
||||
#if SPIRAMS_CHIPS >= 9
|
||||
spi_setup(io+9, spi_port, cs[9]);
|
||||
|
||||
spi_brg(io+9, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+9, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS10_PORT
|
||||
spi_setup(io+10, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS10_PORT,SPIRAMS_CS10_PIN);
|
||||
#if SPIRAMS_CHIPS >= 10
|
||||
spi_setup(io+10, spi_port, cs[10]);
|
||||
|
||||
spi_brg(io+10, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+10, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS11_PORT
|
||||
spi_setup(io+11, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS11_PORT,SPIRAMS_CS11_PIN);
|
||||
#if SPIRAMS_CHIPS >= 11
|
||||
spi_setup(io+11, spi_port, cs[11]);
|
||||
|
||||
spi_brg(io+11, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+11, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS12_PORT
|
||||
spi_setup(io+12, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS12_PORT,SPIRAMS_CS12_PIN);
|
||||
#if SPIRAMS_CHIPS >= 12
|
||||
spi_setup(io+12, spi_port, cs[12]);
|
||||
|
||||
spi_brg(io+12, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+12, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS13_PORT
|
||||
spi_setup(io+13, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS13_PORT,SPIRAMS_CS13_PIN);
|
||||
#if SPIRAMS_CHIPS >= 13
|
||||
spi_setup(io+13, spi_port, cs[13]);
|
||||
|
||||
spi_brg(io+13, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+13, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS14_PORT
|
||||
spi_setup(io+14, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS14_PORT,SPIRAMS_CS14_PIN);
|
||||
#if SPIRAMS_CHIPS >= 14
|
||||
spi_setup(io+14, spi_port, cs[14]);
|
||||
|
||||
spi_brg(io+14, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+14, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
#ifdef SPIRAMS_CS15_PORT
|
||||
spi_setup(io+15, SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS15_PORT,SPIRAMS_CS15_PIN);
|
||||
#if SPIRAMS_CHIPS >= 15
|
||||
spi_setup(io+15, spi_port, cs[15]);
|
||||
|
||||
spi_brg(io+15, SPIRAMS_MHZ * 1000);
|
||||
spi_set(io+15, PIC32_SPICON_CKE);
|
||||
#endif
|
||||
|
||||
printf("spirams0: port %d %s, size %dKB, speed %d Mbit/sec\n",
|
||||
SPIRAMS_PORT, spi_name(io), SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE,
|
||||
spi_get_brg(io) / 1000);
|
||||
bp = prepartition_device("spirams0");
|
||||
if (bp) {
|
||||
spirams_write (0, 0, bp->b_addr, 512);
|
||||
brelse(bp);
|
||||
}
|
||||
printf("spirams0: size %dKB, speed %d Mbit/sec\n",
|
||||
SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE, spi_get_brg(io) / 1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the disk.
|
||||
*/
|
||||
int spirams_open(dev_t dev, int flag, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spirams_close(dev_t dev, int flag, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the size of the device in kbytes.
|
||||
*/
|
||||
daddr_t spirams_size(dev_t dev)
|
||||
{
|
||||
return SPIRAMS_TOTAL_KBYTES;
|
||||
}
|
||||
|
||||
void spirams_strategy(struct buf *bp)
|
||||
{
|
||||
int offset = bp->b_blkno;
|
||||
long nblk = btod(bp->b_bcount);
|
||||
int s;
|
||||
|
||||
/*
|
||||
* Determine the size of the transfer, and make sure it is
|
||||
* within the boundaries of the partition.
|
||||
*/
|
||||
if (bp->b_blkno + nblk > SPIRAMS_TOTAL_KBYTES) {
|
||||
/* if exactly at end of partition, return an EOF */
|
||||
if (bp->b_blkno == SPIRAMS_TOTAL_KBYTES) {
|
||||
bp->b_resid = bp->b_bcount;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
/* or truncate if part of it fits */
|
||||
nblk = SPIRAMS_TOTAL_KBYTES - bp->b_blkno;
|
||||
if (nblk <= 0) {
|
||||
bp->b_error = EINVAL;
|
||||
bp->b_flags |= B_ERROR;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
bp->b_bcount = nblk << DEV_BSHIFT;
|
||||
}
|
||||
|
||||
led_control(LED_SWAP, 1);
|
||||
|
||||
s = splbio();
|
||||
#ifdef UCB_METER
|
||||
if (spirams_dkindex >= 0) {
|
||||
dk_busy |= 1 << spirams_dkindex;
|
||||
dk_xfer[spirams_dkindex]++;
|
||||
dk_bytes[spirams_dkindex] += bp->b_bcount;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bp->b_flags & B_READ) {
|
||||
spirams_read(offset, bp->b_addr, bp->b_bcount);
|
||||
} else {
|
||||
spirams_write(offset, bp->b_addr, bp->b_bcount);
|
||||
}
|
||||
|
||||
biodone(bp);
|
||||
led_control(LED_SWAP, 0);
|
||||
#ifdef UCB_METER
|
||||
if (spirams_dkindex >= 0)
|
||||
dk_busy &= ~(1 << spirams_dkindex);
|
||||
#endif
|
||||
splx(s);
|
||||
}
|
||||
|
||||
int spirams_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 = SPIRAMS_TOTAL_KBYTES;
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test to see if device is present.
|
||||
* Return true if found and initialized ok.
|
||||
*/
|
||||
static int
|
||||
spirams_probe(config)
|
||||
struct conf_device *config;
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Only one device unit is supported. */
|
||||
if (config->dev_unit != 0)
|
||||
return 0;
|
||||
|
||||
printf("sr0: port SPI%d, pins ", config->dev_ctlr);
|
||||
for (i=0; i<SPIRAMS_CHIPS; i++) {
|
||||
int cs = config->dev_pins[i];
|
||||
if (i > 0)
|
||||
printf("/");
|
||||
if (i == 7)
|
||||
printf("\n ");
|
||||
printf("R%c%d", gpio_portname(cs), gpio_pinno(cs));
|
||||
}
|
||||
printf("\n");
|
||||
if (spirams_init(config->dev_ctlr, config->dev_pins) != 0)
|
||||
return 0;
|
||||
|
||||
#ifdef UCB_METER
|
||||
dk_alloc(&spirams_dkindex, 1, "sr0");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct driver srdriver = {
|
||||
"sr", spirams_probe,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef _SPIRAMS_H
|
||||
#define _SPIRAMS_H
|
||||
|
||||
extern int spirams_size(int unit);
|
||||
extern int spirams_read(int unit, unsigned int offset, char *data, unsigned int bcount);
|
||||
extern int spirams_write (int unit, unsigned offset, char *data, unsigned bcount);
|
||||
extern void spirams_preinit (int unit);
|
||||
#ifdef KERNEL
|
||||
extern int spirams_open(dev_t dev, int flag, int mode);
|
||||
extern int spirams_close(dev_t dev, int flag, int mode);
|
||||
extern daddr_t spirams_size(dev_t dev);
|
||||
extern void spirams_strategy(struct buf *bp);
|
||||
extern int spirams_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Driver for external SRAM-CPLD based Swap and Filesystem devices
|
||||
* TODO: Modify this driver to be able to function without rdisk layer.
|
||||
*
|
||||
* This version is for 8MB RAMDISK v.1.1 and compatible
|
||||
* Pito 7.4.2014 - PIC32MX PMP bus version
|
||||
@@ -22,10 +21,18 @@
|
||||
#include <sys/buf.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/dk.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/disk.h>
|
||||
#include <sys/kconfig.h>
|
||||
#include <machine/debug.h>
|
||||
#include <machine/sramc.h>
|
||||
|
||||
int sw_dkn = -1; /* Statistics slot number */
|
||||
int sramc_dkindex = -1; /* Statistics slot number */
|
||||
|
||||
/*
|
||||
* Size of RAM disk.
|
||||
*/
|
||||
#define SRAMC_TOTAL_KBYTES 8192 /* 4096 for 4MB ramdisk */
|
||||
|
||||
// Ramdisk v.1.1. wiring
|
||||
// PMP RAMDISK
|
||||
@@ -77,13 +84,13 @@ typedef union {
|
||||
*
|
||||
*/
|
||||
inline static void
|
||||
dev_load_address (addr)
|
||||
dev_load_address(addr)
|
||||
unsigned addr;
|
||||
{
|
||||
nybbles temp;
|
||||
temp.value = addr;
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
|
||||
PMADDR = 1; // set ADR mode (1) to write the Address
|
||||
|
||||
@@ -91,45 +98,58 @@ dev_load_address (addr)
|
||||
|
||||
PMDIN = temp.nib6; /* write 4 bits */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = temp.nib5; /* write 4 bits */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = temp.nib4; /* write 4 bits */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = temp.nib3; /* write 4 bits */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = temp.nib2; /* write 4 bits */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = temp.nib1; /* write 4 bits */
|
||||
}
|
||||
|
||||
/*
|
||||
* Get number of kBytes on the disk.
|
||||
* Return nonzero if successful.
|
||||
* 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 SRAMC_SWAP_KBYTES.
|
||||
*/
|
||||
int sramc_size ( int unit )
|
||||
daddr_t sramc_size(dev_t dev)
|
||||
{
|
||||
return 8192; // 4096 for 4MB ramdisk
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
/* Whole disk. */
|
||||
return SRAMC_TOTAL_KBYTES;
|
||||
case 1:
|
||||
/* Partition A: filesystem. */
|
||||
return SRAMC_TOTAL_KBYTES - SRAMC_SWAP_KBYTES;
|
||||
case 2:
|
||||
default:
|
||||
/* Partition B: swap space. */
|
||||
return SRAMC_SWAP_KBYTES;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a block of data.
|
||||
*/
|
||||
inline int sramc_read (int unit, unsigned int blockno, char *data, unsigned int nbytes)
|
||||
static int sramc_read(unsigned int blockno, char *data, unsigned int nbytes)
|
||||
{
|
||||
int i;
|
||||
|
||||
//DEBUG9("sramc%d: read block %u, length %u bytes, addr %p\n", major(dev), blockno, nbytes, data);
|
||||
|
||||
dev_load_address (blockno * DEV_BSIZE);
|
||||
dev_load_address(blockno * DEV_BSIZE);
|
||||
|
||||
/* Read data. */
|
||||
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
|
||||
PMADDR = 0; // set DATA mode (0)
|
||||
|
||||
@@ -138,7 +158,7 @@ inline int sramc_read (int unit, unsigned int blockno, char *data, unsigned int
|
||||
PMDIN; // Read the PMDIN to clear previous data and latch new data
|
||||
|
||||
for (i=0; i<nbytes; i++) {
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
*data++ = PMDIN; /* read a byte of data */
|
||||
}
|
||||
return 1;
|
||||
@@ -147,13 +167,13 @@ inline int sramc_read (int unit, unsigned int blockno, char *data, unsigned int
|
||||
/*
|
||||
* Write a block of data.
|
||||
*/
|
||||
inline int sramc_write (int unit, unsigned int blockno, char *data, unsigned int nbytes)
|
||||
static int sramc_write(unsigned int blockno, char *data, unsigned int nbytes)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
//DEBUG9("sramc%d: write block %u, length %u bytes, addr %p\n", major(dev), blockno, nbytes, data);
|
||||
|
||||
dev_load_address (blockno * DEV_BSIZE);
|
||||
dev_load_address(blockno * DEV_BSIZE);
|
||||
|
||||
/* Write data. */
|
||||
|
||||
@@ -164,8 +184,8 @@ inline int sramc_write (int unit, unsigned int blockno, char *data, unsigned int
|
||||
PMMODE = 0b10<<8 | (WR_PULSE<<2); // faster with write
|
||||
|
||||
for (i=0; i<nbytes; i++) {
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = (*data++); /* write a byte of data */
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||
PMDIN = *data++; /* write a byte of data */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -173,10 +193,8 @@ inline int sramc_write (int unit, unsigned int blockno, char *data, unsigned int
|
||||
/*
|
||||
* Init the disk.
|
||||
*/
|
||||
void sramc_init (int unit)
|
||||
static void sramc_init()
|
||||
{
|
||||
struct buf *bp;
|
||||
|
||||
// Initialize PMP hardware
|
||||
|
||||
PMCON = 0; // disable PMP
|
||||
@@ -195,26 +213,144 @@ void sramc_init (int unit)
|
||||
asm volatile ("nop");
|
||||
|
||||
// make a couple of dummy reads - it refreshes the cpld internals a little bit :)
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
PMDIN; /* read a byte of data */
|
||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
while (PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||
PMDIN; /* read a byte of data */
|
||||
|
||||
PMADDR = 1; // go with with ADDRESS mode now
|
||||
|
||||
DEBUG3("sramc%d: init done\n",unit);
|
||||
bp = prepartition_device("sramc0");
|
||||
if (bp) {
|
||||
sramc_write(0, 0, bp->b_addr, 512);
|
||||
brelse(bp);
|
||||
}
|
||||
DEBUG3("sramc: init done\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the disk.
|
||||
*/
|
||||
int sramc_open (int unit)
|
||||
int sramc_open(dev_t dev, int flag, int mode)
|
||||
{
|
||||
DEBUG3("sramc%d: open\n",unit);
|
||||
DEBUG3("sramc: open\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sramc_close(dev_t dev, int flag, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sramc_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 = sramc_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 = SRAMC_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 (sramc_dkindex >= 0) {
|
||||
dk_busy |= 1 << sramc_dkindex;
|
||||
dk_xfer[sramc_dkindex]++;
|
||||
dk_bytes[sramc_dkindex] += bp->b_bcount;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bp->b_flags & B_READ) {
|
||||
sramc_read(offset, bp->b_addr, bp->b_bcount);
|
||||
} else {
|
||||
sramc_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 (sramc_dkindex >= 0)
|
||||
dk_busy &= ~(1 << sramc_dkindex);
|
||||
#endif
|
||||
splx(s);
|
||||
}
|
||||
|
||||
int sramc_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 = sramc_size(dev);
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test to see if device is present.
|
||||
* Return true if found and initialized ok.
|
||||
*/
|
||||
static int
|
||||
sramcprobe(config)
|
||||
struct conf_device *config;
|
||||
{
|
||||
/* Only one device unit is supported. */
|
||||
if (config->dev_unit != 0)
|
||||
return 0;
|
||||
|
||||
printf("rc0: total %u kbytes, swap space %u kbytes\n",
|
||||
SRAMC_TOTAL_KBYTES, SRAMC_SWAP_KBYTES);
|
||||
|
||||
sramc_init();
|
||||
|
||||
#ifdef UCB_METER
|
||||
dk_alloc(&sramc_dkindex, 1, "rc0");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct driver rcdriver = {
|
||||
"sramc", sramcprobe,
|
||||
};
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
#define _SRAMC_H
|
||||
|
||||
#ifdef KERNEL
|
||||
|
||||
extern int sramc_read(int unit, unsigned int offset, char *data, unsigned int bcount);
|
||||
extern int sramc_write(int unit, unsigned int offset, char *data, unsigned int bcount);
|
||||
extern int sramc_open(int unit, int flag, int mode);
|
||||
extern void sramc_init(int unit);
|
||||
extern int sramc_size(int unit);
|
||||
|
||||
extern int sramc_open(dev_t dev, int flag, int mode);
|
||||
extern int sramc_close(dev_t dev, int flag, int mode);
|
||||
extern daddr_t sramc_size(dev_t dev);
|
||||
extern void sramc_strategy(struct buf *bp);
|
||||
extern int sramc_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user