diff --git a/sys/include/kconfig.h b/sys/include/kconfig.h new file mode 100644 index 0000000..8457a1b --- /dev/null +++ b/sys/include/kconfig.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2015 Serge Vakulenko + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * This structure is used to encapsulate the routines for a device driver. + * This allows an "object oriented" approach so a controller device driver + * can support multiple attached devices or a device can be attached to + * different types of controllers. + */ +struct driver { + const char *d_name; /* driver name for vmstat and iostat */ + int (*d_init)(); /* routine to probe & initialize device */ +}; + +/* + * This structure describes controllers directly connected to CPU + * and is partially initialized in "ioconf.c" by the 'config' program. + */ +struct conf_ctlr { + struct driver *ctlr_driver; /* controller driver routines */ + int ctlr_unit; /* controller number */ + char *ctlr_addr; /* address of controller */ + int ctlr_pri; /* interrupt priority */ + int ctlr_flags; /* flags */ + + int ctlr_alive; /* true if init routine succeeded */ +}; + +/* + * This structure describes devices connected to an interface + * and is partially initialized in "ioconf.c" by the 'config' program. + */ +struct conf_device { + struct driver *dev_driver; /* device driver routines */ + struct driver *dev_cdriver; /* interface driver routines */ + int dev_unit; /* device unit number */ + int dev_ctlr; /* device interface number */ + int dev_drive; /* device address number */ + int dev_flags; /* flags */ + + /* assignment of signals to physical pins */ +#define KCONF_MAXPINS 16 + char dev_pins[KCONF_MAXPINS]; + + int dev_alive; /* true if init routine succeeded */ +}; + +/* + * This structure describes optional software services. + */ +struct conf_service { + void (*svc_attach)(); /* routine to initialize service */ +}; + +/* Define special unit types used by the config program */ +#define QUES -1 /* -1 means '?' */ +#define UNKNOWN -2 /* -2 means not set yet */ + +#ifdef KERNEL +extern struct conf_ctlr conf_ctlr_init[]; +extern struct conf_device conf_device_init[]; +extern struct conf_service conf_service_init[]; +#endif diff --git a/sys/include/pty.h b/sys/include/pty.h index 95ed62c..6aeecbc 100644 --- a/sys/include/pty.h +++ b/sys/include/pty.h @@ -18,17 +18,12 @@ extern const struct devspec ptsdevs[]; extern const struct devspec ptcdevs[]; - -#ifndef NPTY -#define NPTY 4 +#ifndef PTY_NUNITS +#define PTY_NUNITS 4 /* 4 units by default */ #endif -#if NPTY == 1 -#undef NPTY -#define NPTY 16 /* crude XXX */ -#endif - -extern struct tty pt_tty[NPTY]; +extern struct tty pt_tty[]; +extern int npty; extern int ptsopen(dev_t dev, int flag, int mode); extern int ptsclose(dev_t dev, int flag, int mode); diff --git a/sys/include/systm.h b/sys/include/systm.h index 8c78453..f0654e3 100644 --- a/sys/include/systm.h +++ b/sys/include/systm.h @@ -105,7 +105,7 @@ int loginit (void); void log (int level, char *fmt, ...); int logwrt (char *buf, int len, int log); void logwakeup (int unit); -void cpuidentify (void); +void kconfig (void); void cninit (void); void cnidentify (void); void cnputc (char c); diff --git a/sys/kernel/init_main.c b/sys/kernel/init_main.c index 8251313..c159963 100644 --- a/sys/kernel/init_main.c +++ b/sys/kernel/init_main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include u_int swapstart, nswap; /* start and size of swap space */ @@ -109,7 +110,7 @@ main() startup(); printf ("\n%s", version); - cpuidentify(); + kconfig(); cnidentify(); /* @@ -147,6 +148,12 @@ main() binit(); nchinit(); clkstart(); + + /* Attach services. */ + struct conf_service *svc; + for (svc = conf_service_init; svc->svc_attach != NULL; svc++) + (*svc->svc_attach)(); + s = spl0(); rdisk_init(); diff --git a/sys/kernel/tty_pty.c b/sys/kernel/tty_pty.c index 32cedc4..e2ad033 100644 --- a/sys/kernel/tty_pty.c +++ b/sys/kernel/tty_pty.c @@ -8,7 +8,7 @@ */ #include -#if NPTY > 0 +#ifdef PTY_ENABLED #include #include #include @@ -41,16 +41,16 @@ extern int TTYHOG; /* see tty.c */ * pts == /dev/tty[pqrs]? * ptc == /dev/pty[pqrs]? */ -struct tty pt_tty[NPTY]; +struct tty pt_tty[PTY_NUNITS]; struct pt_ioctl { int pt_flags; struct proc *pt_selr, *pt_selw; u_char pt_send; u_char pt_ucntl; -} pt_ioctl[NPTY]; +} pt_ioctl[PTY_NUNITS]; -int npty = NPTY; /* for pstat -t */ +int npty = PTY_NUNITS; /* for pstat -t */ #define PF_RCOLL 0x01 #define PF_WCOLL 0x02 @@ -69,7 +69,7 @@ int ptsopen(dev_t dev, int flag, int mode) #ifdef lint npty = npty; #endif - if (minor(dev) >= NPTY) + if (minor(dev) >= PTY_NUNITS) return (ENXIO); tp = &pt_tty[minor(dev)]; if ((tp->t_state & TS_ISOPEN) == 0) { @@ -197,7 +197,7 @@ int ptcopen(dev_t dev, int flag, int mode) register struct tty *tp; struct pt_ioctl *pti; - if (minor(dev) >= NPTY) + if (minor(dev) >= PTY_NUNITS) return (ENXIO); tp = &pt_tty[minor(dev)]; if (tp->t_oproc) @@ -519,4 +519,9 @@ int ptyioctl(dev_t dev, u_int cmd, caddr_t data, int flag) } return (error); } + +void ptyattach() +{ + printf("pty: %d units\n", PTY_NUNITS); +} #endif diff --git a/sys/pic32/32mxsdram/Config b/sys/pic32/32mxsdram/Config index 506aa41..2d5c7df 100644 --- a/sys/pic32/32mxsdram/Config +++ b/sys/pic32/32mxsdram/Config @@ -22,7 +22,7 @@ options "HZ=1000" # Rate of timer interrupt 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 -options "NPROC=20" +#options "NPROC=20" # LED options "LED_KERNEL_PORT=TRISA" # for kernel activity LED... diff --git a/sys/pic32/32mxsdram/Makefile b/sys/pic32/32mxsdram/Makefile index c78572d..ebd44bf 100644 --- a/sys/pic32/32mxsdram/Makefile +++ b/sys/pic32/32mxsdram/Makefile @@ -25,7 +25,6 @@ PARAM += -DLED_DISK_PIN=13 PARAM += -DLED_DISK_PORT=TRISC PARAM += -DLED_KERNEL_PIN=15 PARAM += -DLED_KERNEL_PORT=TRISA -PARAM += -DNPROC=20 PARAM += -DBUS_DIV=1 PARAM += -DBUS_KHZ=80000 PARAM += -DCPU_KHZ=80000 @@ -110,7 +109,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/Makefile.kconf b/sys/pic32/Makefile.kconf index 604ade9..2f8a52f 100644 --- a/sys/pic32/Makefile.kconf +++ b/sys/pic32/Makefile.kconf @@ -40,7 +40,7 @@ COMPILE_S = ${CC} -c ${DEFS} $< # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/adc.c b/sys/pic32/adc.c index 2a919a6..492052e 100644 --- a/sys/pic32/adc.c +++ b/sys/pic32/adc.c @@ -29,6 +29,7 @@ #include #include #include +#include const struct devspec adcdevs[] = { { 0, "adc0" }, { 1, "adc1" }, { 2, "adc2" }, { 3, "adc3" }, @@ -146,3 +147,21 @@ int adc_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag) return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +adcprobe(config) + struct conf_device *config; +{ + int flags = config->dev_flags; + + printf("adc: flags %#x\n", flags); + return 1; +} + +struct driver adcdriver = { + "adc", adcprobe, +}; diff --git a/sys/pic32/baremetal/Makefile b/sys/pic32/baremetal/Makefile index 55d8765..e47b21b 100644 --- a/sys/pic32/baremetal/Makefile +++ b/sys/pic32/baremetal/Makefile @@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/duinomite-emega/Makefile b/sys/pic32/duinomite-emega/Makefile index a7d3454..eee7168 100644 --- a/sys/pic32/duinomite-emega/Makefile +++ b/sys/pic32/duinomite-emega/Makefile @@ -102,7 +102,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/duinomite/Makefile b/sys/pic32/duinomite/Makefile index 3c09c0d..331bdf7 100644 --- a/sys/pic32/duinomite/Makefile +++ b/sys/pic32/duinomite/Makefile @@ -102,7 +102,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/explorer16/Makefile b/sys/pic32/explorer16/Makefile index d498544..9e911a8 100644 --- a/sys/pic32/explorer16/Makefile +++ b/sys/pic32/explorer16/Makefile @@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/files.kconf b/sys/pic32/files.kconf index dff2eb4..58816de 100644 --- a/sys/pic32/files.kconf +++ b/sys/pic32/files.kconf @@ -31,6 +31,7 @@ kernel/sys_pipe.c standard kernel/sys_process.c standard kernel/syscalls.c standard kernel/tty.c standard +kernel/tty_pty.c optional pty kernel/tty_subr.c standard kernel/tty_tty.c standard kernel/ufs_alloc.c standard diff --git a/sys/pic32/fubarino/Makefile b/sys/pic32/fubarino/Makefile index 6b1bdb0..693ccaf 100644 --- a/sys/pic32/fubarino/Makefile +++ b/sys/pic32/fubarino/Makefile @@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/glcd.c b/sys/pic32/glcd.c index 7adcb34..3883974 100644 --- a/sys/pic32/glcd.c +++ b/sys/pic32/glcd.c @@ -29,6 +29,7 @@ #include #include #include +#include const struct devspec glcddevs[] = { { 0, "glcd0" }, @@ -665,3 +666,21 @@ int glcd_ioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag) } return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +glcdprobe(config) + struct conf_device *config; +{ + int flags = config->dev_flags; + + printf("glcd0: flags %#x\n", flags); + return 1; +} + +struct driver glcddriver = { + "glcd", glcdprobe, +}; diff --git a/sys/pic32/gpio.c b/sys/pic32/gpio.c index 0937fe9..19874d2 100644 --- a/sys/pic32/gpio.c +++ b/sys/pic32/gpio.c @@ -28,6 +28,7 @@ #include #include #include +#include const struct devspec gpiodevs[] = { { 0, "porta" }, { 1, "portb" }, { 2, "portc" }, { 3, "portd" }, @@ -115,28 +116,6 @@ u_int gpio_confmask [NGPIO]; #define PRINTDBG(...) /*empty*/ //#define PRINTDBG printf -/* - * PIC32 port i/o registers. - */ -struct gpioreg { - volatile unsigned tris; /* Mask of inputs */ - volatile unsigned trisclr; - volatile unsigned trisset; - volatile unsigned trisinv; - volatile unsigned port; /* Read inputs, write outputs */ - volatile unsigned portclr; - volatile unsigned portset; - volatile unsigned portinv; - volatile unsigned lat; /* Read/write outputs */ - volatile unsigned latclr; - volatile unsigned latset; - volatile unsigned latinv; - volatile unsigned odc; /* Open drain configuration */ - volatile unsigned odcclr; - volatile unsigned odcset; - volatile unsigned odcinv; -}; - /* * If a port address matches a port number, * clear a given bit in pin mask. @@ -626,3 +605,30 @@ gpioioctl (dev, cmd, addr, flag) } return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +gpioprobe(config) + struct conf_device *config; +{ + int unit = config->dev_unit; + int flags = config->dev_flags; + char buf[20]; + + if (unit < 0 || unit >= NGPIO) + return 0; + + gpio_confmask[unit] = flags; + + gpio_print(unit | MINOR_CONF, buf); + printf("gpio%u: port%c, pins %s", unit, + unit + (unit<8 ? 'A' : 'B'), buf); + return 1; +} + +struct driver gpiodriver = { + "gpio", gpioprobe, +}; diff --git a/sys/pic32/hx8357.c b/sys/pic32/hx8357.c index e496326..2aa1a0d 100644 --- a/sys/pic32/hx8357.c +++ b/sys/pic32/hx8357.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -787,3 +788,21 @@ int hx8357_select (dev_t dev, int rw) } return ENODEV; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +hxtftprobe(config) + struct conf_device *config; +{ + int flags = config->dev_flags; + + printf("hxtft0: flags %#x\n", flags); + return 1; +} + +struct driver hxtftdriver = { + "hxtft", hxtftprobe, +}; diff --git a/sys/pic32/machdep.c b/sys/pic32/machdep.c index 2d8c9da..9506b77 100644 --- a/sys/pic32/machdep.c +++ b/sys/pic32/machdep.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #ifdef UARTUSB_ENABLED @@ -141,6 +142,9 @@ struct map swapmap[1] = { int waittime = -1; +/* CPU package type: 64 pins or 100 pins. */ +int cpu_pins; + static int nodump(dev) dev_t dev; @@ -392,7 +396,7 @@ startup() physmem = BMXDRMSZ; } -void cpuidentify() +static void cpuidentify() { unsigned devid = DEVID, osccon = OSCCON; static const char pllmult[] = { 15, 16, 17, 18, 19, 20, 21, 24 }; @@ -402,11 +406,26 @@ void cpuidentify() printf("cpu: "); switch (devid & 0x0fffffff) { - case 0x04307053: printf("795F512L"); break; - case 0x0430E053: printf("795F512H"); break; - case 0x04341053: printf("695F512L"); break; - case 0x04325053: printf("695F512H"); break; - default: printf("DevID %08x", devid); + case 0x04307053: + cpu_pins = 100; + printf("795F512L"); + break; + case 0x0430E053: + cpu_pins = 64; + printf("795F512H"); + break; + case 0x04341053: + cpu_pins = 100; + printf("695F512L"); + break; + case 0x04325053: + cpu_pins = 64; + printf("695F512H"); + break; + default: + /* Assume 100-pin package. */ + cpu_pins = 100; + printf("DevID %08x", devid); } printf(" %u MHz, bus %u MHz\n", CPU_KHZ/1000, BUS_KHZ/1000); @@ -443,6 +462,59 @@ void cpuidentify() } } +/* + * Check whether the controller has been successfully initialized. + */ +static int +is_controller_alive(driver, unit) + struct driver *driver; + int unit; +{ + struct conf_ctlr *ctlr; + + /* No controller - that's OK. */ + if (driver == 0) + return 1; + + for (ctlr = conf_ctlr_init; ctlr->ctlr_driver; ctlr++) { + if (ctlr->ctlr_driver == driver && + ctlr->ctlr_unit == unit && + ctlr->ctlr_alive) + { + return 1; + } + } + return 0; +} + +/* + * Configure all controllers and devices as specified + * in the kernel configuration file. + */ +void kconfig() +{ + struct conf_ctlr *ctlr; + struct conf_device *dev; + + cpuidentify(); + + /* Probe and initialize controllers first. */ + for (ctlr = conf_ctlr_init; ctlr->ctlr_driver; ctlr++) { + if ((*ctlr->ctlr_driver->d_init)(ctlr)) { + ctlr->ctlr_alive = 1; + } + } + + /* Probe and initialize devices. */ + for (dev = conf_device_init; dev->dev_driver; dev++) { + if (is_controller_alive(dev->dev_cdriver, dev->dev_ctlr)) { + if ((*dev->dev_driver->d_init)(dev)) { + dev->dev_alive = 1; + } + } + } +} + /* * Sit and wait for something to happen... */ @@ -942,3 +1014,58 @@ int copyin (caddr_t from, caddr_t to, u_int nbytes) bcopy(from, to, nbytes); return 0; } + +/* + * Routines for access to general purpose I/O pins. + */ +static const char pin_name[16] = "?ABCDEFG????????"; + +void gpio_set_input(int pin) +{ + struct gpioreg *port = (struct gpioreg*) &TRISA; + + port += (pin >> 4 & 15) - 1; + port->trisset = (1 << (pin & 15)); +} + +void gpio_set_output(int pin) +{ + struct gpioreg *port = (struct gpioreg*) &TRISA; + + port += (pin >> 4 & 15) - 1; + port->trisclr = (1 << (pin & 15)); +} + +void gpio_set(int pin) +{ + struct gpioreg *port = (struct gpioreg*) &TRISA; + + port += (pin >> 4 & 15) - 1; + port->latset = (1 << (pin & 15)); +} + +void gpio_clr(int pin) +{ + struct gpioreg *port = (struct gpioreg*) &TRISA; + + port += (pin >> 4 & 15) - 1; + port->latclr = (1 << (pin & 15)); +} + +int gpio_get(int pin) +{ + struct gpioreg *port = (struct gpioreg*) &TRISA; + + port += (pin >> 4 & 15) - 1; + return ((port->port & (1 << (pin & 15))) ? 1 : 0); +} + +char gpio_portname(int pin) +{ + return pin_name[(pin >> 4) & 15]; +} + +int gpio_pinno(int pin) +{ + return pin & 15; +} diff --git a/sys/pic32/machparam.h b/sys/pic32/machparam.h index 9ccca1f..53c1b62 100644 --- a/sys/pic32/machparam.h +++ b/sys/pic32/machparam.h @@ -203,6 +203,26 @@ extern int sd_timo_wait_wdone; extern int sd_timo_wait_wstop; extern int sd_timo_wait_widle; +/* + * GPIO pins. + */ +void gpio_set_input(int pin); +void gpio_set_output(int pin); +void gpio_set(int pin); +void gpio_clr(int pin); +int gpio_get(int pin); + +char gpio_portname(int pin); +int gpio_pinno(int pin); + +/* Convert port name/signal into a pin number. */ +#define GPIO_PIN(x,n) (((x)-'A'+1) << 4 | (n)) + +/* + * CPU package type: 64 pins or 100 pins. + */ +extern int cpu_pins; + #endif /* KERNEL */ #endif /* ENDIAN */ diff --git a/sys/pic32/max32/Makefile b/sys/pic32/max32/Makefile index d2ccf00..acdba5c 100644 --- a/sys/pic32/max32/Makefile +++ b/sys/pic32/max32/Makefile @@ -98,7 +98,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/maximite-color/Makefile b/sys/pic32/maximite-color/Makefile index 17f5dc3..2133af2 100644 --- a/sys/pic32/maximite-color/Makefile +++ b/sys/pic32/maximite-color/Makefile @@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/maximite/Makefile b/sys/pic32/maximite/Makefile index 2282a0a..78ef1b4 100644 --- a/sys/pic32/maximite/Makefile +++ b/sys/pic32/maximite/Makefile @@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/mmb-mx7/Makefile b/sys/pic32/mmb-mx7/Makefile index f7c4ce1..e6516ca 100644 --- a/sys/pic32/mmb-mx7/Makefile +++ b/sys/pic32/mmb-mx7/Makefile @@ -109,7 +109,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/pic32mx.h b/sys/pic32/pic32mx.h index d5b1950..5014ae5 100644 --- a/sys/pic32/pic32mx.h +++ b/sys/pic32/pic32mx.h @@ -117,6 +117,7 @@ #else #define PIC32_R(a) *(volatile unsigned*)(0xBF800000 + (a)) #endif + /*-------------------------------------- * UART registers. */ @@ -407,6 +408,30 @@ #define ODCGSET PIC32_R (0x861B8) #define ODCGINV PIC32_R (0x861BC) +#ifndef __ASSEMBLER__ +/* + * PIC32 port i/o registers. + */ +struct gpioreg { + volatile unsigned tris; /* Mask of inputs */ + volatile unsigned trisclr; + volatile unsigned trisset; + volatile unsigned trisinv; + volatile unsigned port; /* Read inputs, write outputs */ + volatile unsigned portclr; + volatile unsigned portset; + volatile unsigned portinv; + volatile unsigned lat; /* Read/write outputs */ + volatile unsigned latclr; + volatile unsigned latset; + volatile unsigned latinv; + volatile unsigned odc; /* Open drain configuration */ + volatile unsigned odcclr; + volatile unsigned odcset; + volatile unsigned odcinv; +}; +#endif + #define CNCON PIC32_R (0x861C0) /* Interrupt-on-change control */ #define CNCONCLR PIC32_R (0x861C4) #define CNCONSET PIC32_R (0x861C8) diff --git a/sys/pic32/picadillo/Makefile b/sys/pic32/picadillo/Makefile index fb07079..ffd4739 100644 --- a/sys/pic32/picadillo/Makefile +++ b/sys/pic32/picadillo/Makefile @@ -95,7 +95,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/pinguino-micro/Makefile b/sys/pic32/pinguino-micro/Makefile index 024442a..033f503 100644 --- a/sys/pic32/pinguino-micro/Makefile +++ b/sys/pic32/pinguino-micro/Makefile @@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/pwm.c b/sys/pic32/pwm.c index 792bbdc..f5840f2 100644 --- a/sys/pic32/pwm.c +++ b/sys/pic32/pwm.c @@ -30,6 +30,7 @@ #include #include #include +#include /* * Devices: @@ -205,3 +206,21 @@ pwm_ioctl (dev, cmd, addr, flag) } return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +pwmprobe(config) + struct conf_device *config; +{ + int flags = config->dev_flags; + + printf("pwm: flags %#x\n", flags); + return 1; +} + +struct driver pwmdriver = { + "pwm", pwmprobe, +}; diff --git a/sys/pic32/rd_sd.c b/sys/pic32/rd_sd.c index f7c4bdd..61d79d0 100644 --- a/sys/pic32/rd_sd.c +++ b/sys/pic32/rd_sd.c @@ -37,6 +37,7 @@ #include #include #include +#include /* * Two SD/MMC disks on SPI. @@ -568,8 +569,8 @@ void sd_preinit (int unit) spi_brg(fd, SD0_MHZ * 1000); spi_set(fd, PIC32_SPICON_CKE); - printf ("sd%d: port %s, select pin R%c%d\n", unit, - spi_name(fd), spi_csname(fd), spi_cspin(fd)); + //printf ("sd%d: port %s, select pin R%c%d\n", unit, + // spi_name(fd), spi_csname(fd), spi_cspin(fd)); } int sdinit (int unit, int flag) @@ -644,3 +645,26 @@ int sdopen(int unit, int flags, int mode) DEBUG("sd%d: open\n",unit); return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +sdprobe(config) + struct conf_device *config; +{ + int unit = config->dev_unit; + int cs; + + if (unit < 0 || unit >= NSD) + return 0; + cs = config->dev_pins[0]; + printf("sd%u: port SPI%d, pin cs=R%c%d\n", unit, + config->dev_ctlr, gpio_portname(cs), gpio_pinno(cs)); + return 1; +} + +struct driver sddriver = { + "sd", sdprobe, +}; diff --git a/sys/pic32/rd_sdramp.c b/sys/pic32/rd_sdramp.c index 661a3db..281d62f 100644 --- a/sys/pic32/rd_sdramp.c +++ b/sys/pic32/rd_sdramp.c @@ -13,6 +13,7 @@ #include #include #include +#include /* * See rd_sdramp_config.h for sdramp port/pin configuration @@ -63,32 +64,8 @@ static char swaptemp[CHUNK_SIZE]; m->partitions[n].lbastart = s; \ m->partitions[n].lbalength = l; -//void build_ramdisk_mbr(struct mbr* m); - // FIXME - FOLLOWING shared with gpio.c - needs to be made common -/* - * PIC32 port i/o registers. - */ -struct gpioreg { - volatile unsigned tris; /* Mask of inputs */ - volatile unsigned trisclr; - volatile unsigned trisset; - volatile unsigned trisinv; - volatile unsigned port; /* Read inputs, write outputs */ - volatile unsigned portclr; - volatile unsigned portset; - volatile unsigned portinv; - volatile unsigned lat; /* Read/write outputs */ - volatile unsigned latclr; - volatile unsigned latset; - volatile unsigned latinv; - volatile unsigned odc; /* Open drain configuration */ - volatile unsigned odcclr; - volatile unsigned odcset; - volatile unsigned odcinv; -}; - struct ocreg { volatile unsigned con; /* ? */ volatile unsigned conclr; @@ -397,16 +374,18 @@ int sdramp_size(int unit) return (1< #include #include +#include #include #include @@ -261,3 +262,60 @@ int spidev_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag) } return 0; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + * SPI ports are always present, if configured. + */ +static int +spiprobe(config) + struct conf_ctlr *config; +{ + int channel = config->ctlr_unit - 1; + int sdi, sdo, sck; + static const int sdi_tab[NSPI] = { + GPIO_PIN('C',4), /* SDI1 */ + GPIO_PIN('G',7), /* SDI2 */ + GPIO_PIN('D',2), /* SDI3: 64pin - RD2, 100pin - RF2 */ + GPIO_PIN('F',4), /* SDI4 */ + }; + static const int sdo_tab[NSPI] = { + GPIO_PIN('D',0), /* SDO1 */ + GPIO_PIN('G',8), /* SDO2 */ + GPIO_PIN('D',3), /* SDO3: 64pin - RD3, 100pin - RF8 */ + GPIO_PIN('F',5), /* SDO4 */ + }; + static const int sck_tab[NSPI] = { + GPIO_PIN('D',10), /* SCK1 */ + GPIO_PIN('G',6), /* SCK2 */ + GPIO_PIN('D',1), /* SCK3: 64pin - RD1, 100pin - RD15 */ + GPIO_PIN('D',10), /* SCK4 */ + }; + + if (channel < 0 || channel >= NSPI) + return 0; + sdi = sdi_tab[channel]; + sdo = sdo_tab[channel]; + sck = sck_tab[channel]; + if (channel+1 == 3 && cpu_pins > 64) { + /* Port SPI3 has different pin assignment for 100-pin packages. */ + sdi = GPIO_PIN('F',2); + sdo = GPIO_PIN('F',8); + sck = GPIO_PIN('D',15); + } + printf ("spi%u: pins sdi=R%c%d/sdo=R%c%d/sck=R%c%d\n", channel+1, + gpio_portname(sdi), gpio_pinno(sdi), + gpio_portname(sdo), gpio_pinno(sdo), + gpio_portname(sck), gpio_pinno(sck)); + + //TODO + //struct spiio *io = &spitab[channel]; + //io->reg = spi_base[channel]; + //spi_setup(io, 0, 0); + return 1; +} + +struct driver spidriver = { + "spi", spiprobe, +}; diff --git a/sys/pic32/starter-kit/Makefile b/sys/pic32/starter-kit/Makefile index f381907..367952c 100644 --- a/sys/pic32/starter-kit/Makefile +++ b/sys/pic32/starter-kit/Makefile @@ -100,7 +100,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/sysctl.c b/sys/pic32/sysctl.c index aa1bbd2..e824150 100644 --- a/sys/pic32/sysctl.c +++ b/sys/pic32/sysctl.c @@ -21,6 +21,9 @@ #include #include #include +#ifdef PTY_ENABLED +# include +#endif /* * Errno messages. @@ -165,7 +168,7 @@ static const struct { { "_tk_nout", (int) &tk_nout }, /* iostat */ { "_total", (int) &total }, /* vmstat */ { "_u", (int) &u }, /* ps */ -#if NPTY > 0 +#ifdef PTY_ENABLED { "_npty", (int) &npty }, /* pstat */ { "_pt_tty", (int) &pt_tty }, /* pstat */ #endif diff --git a/sys/pic32/uart.c b/sys/pic32/uart.c index c4d5a22..0433d5f 100644 --- a/sys/pic32/uart.c +++ b/sys/pic32/uart.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #define CONCAT(x,y) x ## y @@ -745,3 +746,69 @@ char uartgetc(dev_t dev) splx(s); return (unsigned char) c; } + +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +uartprobe(config) + struct conf_device *config; +{ + int unit = config->dev_unit - 1; + extern dev_t console_device; + int is_console = (major(console_device) == uart_major && + minor(console_device) == unit); + int rx, tx; + static const int rx_tab[NUART] = { + GPIO_PIN('D',2), /* U1RX: 64pin - RD2, 100pin - RF2 */ + GPIO_PIN('F',4), /* U2RX */ + GPIO_PIN('G',7), /* U3RX */ + GPIO_PIN('D',9), /* U4RX: 64pin - RD9, 100pin - RD14 */ + GPIO_PIN('B',8), /* U5RX: 64pin - RB8, 100pin - RF12 */ + GPIO_PIN('G',9), /* U6RX */ + }; + static const int tx_tab[NUART] = { + GPIO_PIN('D',3), /* U1TX: 64pin - RD3, 100pin - RF8 */ + GPIO_PIN('F',5), /* U2TX */ + GPIO_PIN('G',8), /* U3TX */ + GPIO_PIN('D',1), /* U4TX: 64pin - RD1, 100pin - RD15 */ + GPIO_PIN('B',14), /* U5TX: 64pin - RB14, 100pin - RF13 */ + GPIO_PIN('G',6), /* U6TX */ + }; + + if (unit < 0 || unit >= NUART) + return 0; + rx = rx_tab[unit]; + tx = tx_tab[unit]; + if (cpu_pins > 64) { + /* Ports UART1, UART4 and UART5 have different pin assignments + * for 100-pin packages. */ + switch (unit + 1) { + case 1: + rx = GPIO_PIN('F',2); + tx = GPIO_PIN('F',8); + break; + case 4: + rx = GPIO_PIN('D',14); + tx = GPIO_PIN('D',15); + break; + case 5: + rx = GPIO_PIN('F',12); + tx = GPIO_PIN('F',13); + break; + } + } + printf("uart%d: pins rx=R%c%d/tx=R%c%d, interrupts %u/%u/%u", unit+1, + gpio_portname(rx), gpio_pinno(rx), + gpio_portname(tx), gpio_pinno(tx), + uirq[unit].er, uirq[unit].rx, uirq[unit].tx); + if (is_console) + printf(", console"); + printf("\n"); + return 1; +} + +struct driver uartdriver = { + "uart", uartprobe, +}; diff --git a/sys/pic32/ubw32/Makefile b/sys/pic32/ubw32/Makefile index f1bac69..6b349e7 100644 --- a/sys/pic32/ubw32/Makefile +++ b/sys/pic32/ubw32/Makefile @@ -112,7 +112,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/sys/pic32/usb_uart.c b/sys/pic32/usb_uart.c index 438e4b8..25c9c06 100644 --- a/sys/pic32/usb_uart.c +++ b/sys/pic32/usb_uart.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -280,6 +281,28 @@ void usbintr (int chan) cdc_tx_service(); } +/* + * Test to see if device is present. + * Return true if found and initialized ok. + */ +static int +usbprobe(config) + struct conf_device *config; +{ + extern dev_t console_device; + int is_console = major(console_device) == usb_major; + + printf("uartusb: port USB, interrupt %u", PIC32_VECT_USB); + if (is_console) + printf(", console"); + printf("\n"); + return 1; +} + +struct driver uartusbdriver = { + "uartusb", usbprobe, +}; + /* * USB Callback Functions */ diff --git a/sys/pic32/wf32/Makefile b/sys/pic32/wf32/Makefile index 9e37973..10c913a 100644 --- a/sys/pic32/wf32/Makefile +++ b/sys/pic32/wf32/Makefile @@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ # ${SYSTEM_LD_HEAD} # ${SYSTEM_LD} swapxxx.o # ${SYSTEM_LD_TAIL} -SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o +SYSTEM_OBJ = startup.o ${OBJS} ioconf.o ifeq (devcfg.c,$(wildcard devcfg.c)) SYSTEM_OBJ += devcfg.o endif diff --git a/tools/kconfig/mkioconf.c b/tools/kconfig/mkioconf.c index 49acc99..83fa11d 100644 --- a/tools/kconfig/mkioconf.c +++ b/tools/kconfig/mkioconf.c @@ -42,18 +42,18 @@ service_ioconf(fp) { register struct device *dp; - for (dp = dtab; dp != NULL; dp = dp->d_next) + for (dp = dtab; dp != NULL; dp = dp->d_next) { if (dp->d_type == SERVICE) - fprintf(fp, "extern void %sattach __P((int));\n", + fprintf(fp, "void %sattach(int);\n", dp->d_name); + } - fprintf(fp, "\nstruct conf_pdev conf_sinit[] = {\n"); - for (dp = dtab; dp != NULL; dp = dp->d_next) + fprintf(fp, "\nstruct conf_service conf_service_init[] = {\n"); + for (dp = dtab; dp != NULL; dp = dp->d_next) { if (dp->d_type == SERVICE) - fprintf(fp, " { %sattach, %d },\n", dp->d_name, - dp->d_slave > 0 ? dp->d_slave : 1); - - fprintf(fp, " { 0, 0 }\n};\n"); + fprintf(fp, " { %sattach },\n", dp->d_name); + } + fprintf(fp, " { 0 }\n};\n"); } static char * @@ -78,8 +78,7 @@ void pic32_ioconf() exit(1); } fprintf(fp, "#include \"sys/types.h\"\n"); - fprintf(fp, "#include \"sys/time.h\"\n"); - fprintf(fp, "#include \"mips/dev/device.h\"\n\n"); + fprintf(fp, "#include \"sys/kconfig.h\"\n\n"); fprintf(fp, "#define C (char *)\n\n"); /* print controller initialization structures */ @@ -88,7 +87,7 @@ void pic32_ioconf() continue; fprintf(fp, "extern struct driver %sdriver;\n", dp->d_name); } - fprintf(fp, "\nstruct conf_ctlr conf_cinit[] = {\n"); + fprintf(fp, "\nstruct conf_ctlr conf_ctlr_init[] = {\n"); fprintf(fp, " /* driver,\t\tunit,\taddr,\t\tpri,\tflags */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { if (dp->d_type != CONTROLLER) @@ -108,7 +107,7 @@ void pic32_ioconf() fprintf(fp, " { 0 }\n};\n"); /* print devices connected to other controllers */ - fprintf(fp, "\nstruct conf_device conf_dinit[] = {\n"); + fprintf(fp, "\nstruct conf_device conf_device_init[] = {\n"); fprintf(fp, " /* driver,\t\tctlr driver,\tunit,\tctlr,\tdrive,\tflags,\tpins */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { diff --git a/tools/kconfig/mkmakefile.c b/tools/kconfig/mkmakefile.c index de6f0e6..1bd46e3 100644 --- a/tools/kconfig/mkmakefile.c +++ b/tools/kconfig/mkmakefile.c @@ -438,6 +438,9 @@ void makefile() fprintf(ofp, "PARAM += -D%s_ENABLED\n", raise(dp->d_name)); else fprintf(ofp, "PARAM += -D%s%d_ENABLED\n", raise(dp->d_name), dp->d_unit); + + if (dp->d_type == SERVICE && dp->d_slave > 0) + fprintf(ofp, "PARAM += -D%s_NUNITS=%d\n", raise(dp->d_name), dp->d_slave); } for (op = opt; op; op = op->op_next) { if (op->op_value)