Remove gxemul drivers.

These were MIPS-only.
This commit is contained in:
Justin Hibbits 2023-02-06 13:06:25 -05:00
parent 93037a67bf
commit 655d043b49
6 changed files with 0 additions and 1221 deletions

View File

@ -1,335 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2011-2012 Robert N. M. Watson
* All rights reserved.
*
* This software was developed by SRI International and the University of
* Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
* ("CTSRD"), as part of the DARPA CRASH research programme.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/cons.h>
#include <sys/endian.h>
#include <sys/kdb.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/reboot.h>
#include <sys/tty.h>
#include <ddb/ddb.h>
#include <machine/cpuregs.h>
#define GC_LOCK_INIT() mtx_init(&gc_lock, "gc_lock", NULL, MTX_SPIN)
#define GC_LOCK() do { \
if (!kdb_active) \
mtx_lock_spin(&gc_lock); \
} while (0)
#define GC_LOCK_ASSERT() do { \
if (!kdb_active) \
mtx_assert(&gc_lock, MA_OWNED); \
} while (0)
#define GC_UNLOCK() do { \
if (!kdb_active) \
mtx_unlock_spin(&gc_lock); \
} while (0)
static struct mtx gc_lock;
/*
* Low-level console driver functions.
*/
static cn_probe_t gxemul_cons_cnprobe;
static cn_init_t gxemul_cons_cninit;
static cn_term_t gxemul_cons_cnterm;
static cn_getc_t gxemul_cons_cngetc;
static cn_putc_t gxemul_cons_cnputc;
static cn_grab_t gxemul_cons_cngrab;
static cn_ungrab_t gxemul_cons_cnungrab;
/*
* TTY-level fields.
*/
static tsw_outwakeup_t gxemul_cons_outwakeup;
static struct ttydevsw gxemul_cons_ttydevsw = {
.tsw_flags = TF_NOPREFIX,
.tsw_outwakeup = gxemul_cons_outwakeup,
};
static struct callout gxemul_cons_callout;
static u_int gxemul_cons_polltime = 10;
#ifdef KDB
static int gxemul_cons_alt_break_state;
#endif
static void gxemul_cons_timeout(void *);
/*
* I/O routines lifted from Deimos.
*
* XXXRW: Should be using FreeBSD's bus routines here, but they are not
* available until later in the boot.
*/
static inline vm_offset_t
mips_phys_to_uncached(vm_paddr_t phys)
{
return (MIPS_PHYS_TO_DIRECT_UNCACHED(phys));
}
static inline uint8_t
mips_ioread_uint8(vm_offset_t vaddr)
{
uint8_t v;
__asm__ __volatile__ ("lbu %0, 0(%1)" : "=r" (v) : "r" (vaddr));
return (v);
}
static inline void
mips_iowrite_uint8(vm_offset_t vaddr, uint8_t v)
{
__asm__ __volatile__ ("sb %0, 0(%1)" : : "r" (v), "r" (vaddr));
}
/*
* gxemul-specific constants.
*/
#define GXEMUL_CONS_BASE 0x10000000 /* gxemul console device. */
/*
* Routines for interacting with the gxemul test console. Programming details
* are a result of manually inspecting the source code for gxemul's
* dev_cons.cc and dev_cons.h.
*
* Offsets of I/O channels relative to the base.
*/
#define GXEMUL_PUTGETCHAR_OFF 0x00000000
#define GXEMUL_CONS_HALT 0x00000010
/*
* One-byte buffer as we can't check whether the console is readable without
* actually reading from it.
*/
static char buffer_data;
static int buffer_valid;
/*
* Low-level read and write routines.
*/
static inline uint8_t
gxemul_cons_data_read(void)
{
return (mips_ioread_uint8(mips_phys_to_uncached(GXEMUL_CONS_BASE +
GXEMUL_PUTGETCHAR_OFF)));
}
static inline void
gxemul_cons_data_write(uint8_t v)
{
mips_iowrite_uint8(mips_phys_to_uncached(GXEMUL_CONS_BASE +
GXEMUL_PUTGETCHAR_OFF), v);
}
static int
gxemul_cons_writable(void)
{
return (1);
}
static int
gxemul_cons_readable(void)
{
uint32_t v;
GC_LOCK_ASSERT();
if (buffer_valid)
return (1);
v = gxemul_cons_data_read();
if (v != 0) {
buffer_valid = 1;
buffer_data = v;
return (1);
}
return (0);
}
static void
gxemul_cons_write(char ch)
{
GC_LOCK_ASSERT();
while (!gxemul_cons_writable());
gxemul_cons_data_write(ch);
}
static char
gxemul_cons_read(void)
{
GC_LOCK_ASSERT();
while (!gxemul_cons_readable());
buffer_valid = 0;
return (buffer_data);
}
/*
* Implementation of a FreeBSD low-level, polled console driver.
*/
static void
gxemul_cons_cnprobe(struct consdev *cp)
{
sprintf(cp->cn_name, "ttyu0");
cp->cn_pri = (boothowto & RB_SERIAL) ? CN_REMOTE : CN_NORMAL;
}
static void
gxemul_cons_cninit(struct consdev *cp)
{
GC_LOCK_INIT();
}
static void
gxemul_cons_cnterm(struct consdev *cp)
{
}
static int
gxemul_cons_cngetc(struct consdev *cp)
{
int ret;
GC_LOCK();
ret = gxemul_cons_read();
GC_UNLOCK();
return (ret);
}
static void
gxemul_cons_cnputc(struct consdev *cp, int c)
{
GC_LOCK();
gxemul_cons_write(c);
GC_UNLOCK();
}
static void
gxemul_cons_cngrab(struct consdev *cp)
{
}
static void
gxemul_cons_cnungrab(struct consdev *cp)
{
}
CONSOLE_DRIVER(gxemul_cons);
/*
* TTY-level functions for gxemul_cons.
*/
static void
gxemul_cons_ttyinit(void *unused)
{
struct tty *tp;
tp = tty_alloc(&gxemul_cons_ttydevsw, NULL);
tty_init_console(tp, 0);
tty_makedev(tp, NULL, "%s", "ttyu0");
callout_init(&gxemul_cons_callout, 1);
callout_reset(&gxemul_cons_callout, gxemul_cons_polltime,
gxemul_cons_timeout, tp);
}
SYSINIT(gxemul_cons_ttyinit, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE,
gxemul_cons_ttyinit, NULL);
static void
gxemul_cons_outwakeup(struct tty *tp)
{
int len;
u_char ch;
/*
* XXXRW: Would be nice not to do blocking writes to the console here,
* rescheduling on our timer tick if work remains to be done..
*/
for (;;) {
len = ttydisc_getc(tp, &ch, sizeof(ch));
if (len == 0)
break;
GC_LOCK();
gxemul_cons_write(ch);
GC_UNLOCK();
}
}
static void
gxemul_cons_timeout(void *v)
{
struct tty *tp;
int c;
tp = v;
tty_lock(tp);
GC_LOCK();
while (gxemul_cons_readable()) {
c = gxemul_cons_read();
GC_UNLOCK();
#ifdef KDB
kdb_alt_break(c, &gxemul_cons_alt_break_state);
#endif
ttydisc_rint(tp, c, 0);
GC_LOCK();
}
GC_UNLOCK();
ttydisc_rint_done(tp);
tty_unlock(tp);
callout_reset(&gxemul_cons_callout, gxemul_cons_polltime,
gxemul_cons_timeout, tp);
}

View File

@ -1,331 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008-2012 Juli Mallett <jmallett@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/bio.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <geom/geom.h>
#include <machine/cpuregs.h>
#include <dev/gxemul/disk/gxemul_diskreg.h>
struct gxemul_disk_softc {
device_t sc_dev;
uint64_t sc_size;
struct g_geom *sc_geom;
struct g_provider *sc_provider;
};
static struct mtx gxemul_disk_controller_mutex;
static g_start_t gxemul_disk_start;
static g_access_t gxemul_disk_access;
struct g_class g_gxemul_disk_class = {
.name = "GXemul",
.version = G_VERSION,
.start = gxemul_disk_start,
.access = gxemul_disk_access,
};
DECLARE_GEOM_CLASS(g_gxemul_disk_class, g_gxemul_disk);
static void gxemul_disk_identify(driver_t *, device_t);
static int gxemul_disk_probe(device_t);
static int gxemul_disk_attach(device_t);
static void gxemul_disk_attach_geom(void *, int);
static int gxemul_disk_read(unsigned, void *, off_t);
static int gxemul_disk_size(unsigned, uint64_t *);
static int gxemul_disk_write(unsigned, const void *, off_t);
static void
gxemul_disk_start(struct bio *bp)
{
struct gxemul_disk_softc *sc;
unsigned diskid;
off_t offset;
uint8_t *buf;
int error;
sc = bp->bio_to->geom->softc;
diskid = device_get_unit(sc->sc_dev);
if ((bp->bio_length % GXEMUL_DISK_DEV_BLOCKSIZE) != 0) {
g_io_deliver(bp, EINVAL);
return;
}
buf = bp->bio_data;
offset = bp->bio_offset;
bp->bio_resid = bp->bio_length;
while (bp->bio_resid != 0) {
switch (bp->bio_cmd) {
case BIO_READ:
mtx_lock(&gxemul_disk_controller_mutex);
error = gxemul_disk_read(diskid, buf, offset);
mtx_unlock(&gxemul_disk_controller_mutex);
break;
case BIO_WRITE:
mtx_lock(&gxemul_disk_controller_mutex);
error = gxemul_disk_write(diskid, buf, offset);
mtx_unlock(&gxemul_disk_controller_mutex);
break;
default:
g_io_deliver(bp, EOPNOTSUPP);
return;
}
if (error != 0) {
g_io_deliver(bp, error);
return;
}
buf += GXEMUL_DISK_DEV_BLOCKSIZE;
offset += GXEMUL_DISK_DEV_BLOCKSIZE;
bp->bio_completed += GXEMUL_DISK_DEV_BLOCKSIZE;
bp->bio_resid -= GXEMUL_DISK_DEV_BLOCKSIZE;
}
g_io_deliver(bp, 0);
}
static int
gxemul_disk_access(struct g_provider *pp, int r, int w, int e)
{
return (0);
}
static void
gxemul_disk_identify(driver_t *drv, device_t parent)
{
unsigned diskid;
mtx_init(&gxemul_disk_controller_mutex, "GXemul disk controller", NULL, MTX_DEF);
mtx_lock(&gxemul_disk_controller_mutex);
for (diskid = 0; diskid < 0x100; diskid++) {
/*
* If we can read at offset 0, this disk id must be
* present enough. If we get an error, stop looking.
* Disks in GXemul are allocated linearly from 0.
*/
if (gxemul_disk_read(diskid, NULL, 0) != 0)
break;
BUS_ADD_CHILD(parent, 0, "gxemul_disk", diskid);
}
mtx_unlock(&gxemul_disk_controller_mutex);
}
static int
gxemul_disk_probe(device_t dev)
{
device_set_desc(dev, "GXemul test disk");
return (BUS_PROBE_NOWILDCARD);
}
static void
gxemul_disk_attach_geom(void *arg, int flag)
{
struct gxemul_disk_softc *sc;
sc = arg;
sc->sc_geom = g_new_geomf(&g_gxemul_disk_class, "%s", device_get_nameunit(sc->sc_dev));
sc->sc_geom->softc = sc;
sc->sc_provider = g_new_providerf(sc->sc_geom, "%s", sc->sc_geom->name);
sc->sc_provider->sectorsize = GXEMUL_DISK_DEV_BLOCKSIZE;
sc->sc_provider->mediasize = sc->sc_size;
g_error_provider(sc->sc_provider, 0);
}
static int
gxemul_disk_attach(device_t dev)
{
struct gxemul_disk_softc *sc;
unsigned diskid;
int error;
diskid = device_get_unit(dev);
sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_geom = NULL;
sc->sc_provider = NULL;
mtx_lock(&gxemul_disk_controller_mutex);
error = gxemul_disk_size(diskid, &sc->sc_size);
if (error != 0) {
mtx_unlock(&gxemul_disk_controller_mutex);
return (error);
}
mtx_unlock(&gxemul_disk_controller_mutex);
g_post_event(gxemul_disk_attach_geom, sc, M_WAITOK, NULL);
return (0);
}
static int
gxemul_disk_read(unsigned diskid, void *buf, off_t off)
{
const volatile void *src;
mtx_assert(&gxemul_disk_controller_mutex, MA_OWNED);
if (off < 0 || off % GXEMUL_DISK_DEV_BLOCKSIZE != 0)
return (EINVAL);
#ifdef _LP64
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET, (uint64_t)off);
#else
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET_LO,
(uint32_t)(off & 0xffffffff));
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET_HI,
(uint32_t)((off >> 32) & 0xffffffff));
#endif
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_DISKID, diskid);
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_START, GXEMUL_DISK_DEV_START_READ);
switch (GXEMUL_DISK_DEV_READ(GXEMUL_DISK_DEV_STATUS)) {
case GXEMUL_DISK_DEV_STATUS_FAILURE:
return (EIO);
default:
break;
}
if (buf != NULL) {
src = GXEMUL_DISK_DEV_FUNCTION(GXEMUL_DISK_DEV_BLOCK);
memcpy(buf, (const void *)(uintptr_t)src,
GXEMUL_DISK_DEV_BLOCKSIZE);
}
return (0);
}
static int
gxemul_disk_size(unsigned diskid, uint64_t *sizep)
{
uint64_t offset, ogood;
uint64_t m, s;
int error;
m = 1;
s = 3;
ogood = 0;
for (;;) {
offset = (ogood * s) + (m * GXEMUL_DISK_DEV_BLOCKSIZE);
error = gxemul_disk_read(diskid, NULL, offset);
if (error != 0) {
if (m == 1 && s == 1) {
*sizep = ogood + GXEMUL_DISK_DEV_BLOCKSIZE;
return (0);
}
if (m > 1)
m /= 2;
if (s > 1)
s--;
continue;
}
if (ogood == offset) {
m = 1;
continue;
}
ogood = offset;
m++;
}
return (EDOOFUS);
}
static int
gxemul_disk_write(unsigned diskid, const void *buf, off_t off)
{
volatile void *dst;
mtx_assert(&gxemul_disk_controller_mutex, MA_OWNED);
if (off < 0 || off % GXEMUL_DISK_DEV_BLOCKSIZE != 0)
return (EINVAL);
#ifdef _LP64
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET, (uint64_t)off);
#else
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET_LO,
(uint32_t)(off & 0xffffffff));
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_OFFSET_HI,
(uint32_t)((off >> 32) & 0xffffffff));
#endif
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_DISKID, diskid);
dst = GXEMUL_DISK_DEV_FUNCTION(GXEMUL_DISK_DEV_BLOCK);
memcpy((void *)(uintptr_t)dst, buf, GXEMUL_DISK_DEV_BLOCKSIZE);
GXEMUL_DISK_DEV_WRITE(GXEMUL_DISK_DEV_START, GXEMUL_DISK_DEV_START_WRITE);
switch (GXEMUL_DISK_DEV_READ(GXEMUL_DISK_DEV_STATUS)) {
case GXEMUL_DISK_DEV_STATUS_FAILURE:
return (EIO);
default:
break;
}
return (0);
}
static device_method_t gxemul_disk_methods[] = {
DEVMETHOD(device_probe, gxemul_disk_probe),
DEVMETHOD(device_identify, gxemul_disk_identify),
DEVMETHOD(device_attach, gxemul_disk_attach),
{ 0, 0 }
};
static driver_t gxemul_disk_driver = {
"gxemul_disk",
gxemul_disk_methods,
sizeof (struct gxemul_disk_softc)
};
DRIVER_MODULE(gxemul_disk, nexus, gxemul_disk_driver, 0, 0);

View File

@ -1,71 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008-2012 Juli Mallett <jmallett@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#ifndef _DEV_GXEMUL_DISK_GXEMUL_DISK_H_
#define _DEV_GXEMUL_DISK_GXEMUL_DISK_H_
#define GXEMUL_DISK_DEV_BASE (0x13000000)
#define GXEMUL_DISK_DEV_BLOCKSIZE (0x0200)
#define GXEMUL_DISK_DEV_ID_START (0x0000)
#define GXEMUL_DISK_DEV_ID_END (0x0100)
#ifdef _LP64
#define GXEMUL_DISK_DEV_OFFSET (0x0000)
#else
#define GXEMUL_DISK_DEV_OFFSET_LO (0x0000)
#define GXEMUL_DISK_DEV_OFFSET_HI (0x0008)
#endif
#define GXEMUL_DISK_DEV_DISKID (0x0010)
#define GXEMUL_DISK_DEV_START (0x0020)
#define GXEMUL_DISK_DEV_STATUS (0x0030)
#define GXEMUL_DISK_DEV_BLOCK (0x4000)
#ifdef _LP64
#define GXEMUL_DISK_DEV_FUNCTION(f) \
(volatile uint64_t *)MIPS_PHYS_TO_DIRECT_UNCACHED(GXEMUL_DISK_DEV_BASE + (f))
#define GXEMUL_DISK_DEV_READ(f) \
(volatile uint64_t)*GXEMUL_DISK_DEV_FUNCTION(f)
#else
#define GXEMUL_DISK_DEV_FUNCTION(f) \
(volatile uint32_t *)MIPS_PHYS_TO_DIRECT_UNCACHED(GXEMUL_DISK_DEV_BASE + (f))
#define GXEMUL_DISK_DEV_READ(f) \
(volatile uint32_t)*GXEMUL_DISK_DEV_FUNCTION(f)
#endif
#define GXEMUL_DISK_DEV_WRITE(f, v) \
*GXEMUL_DISK_DEV_FUNCTION(f) = (v)
#define GXEMUL_DISK_DEV_START_READ (0x00)
#define GXEMUL_DISK_DEV_START_WRITE (0x01)
#define GXEMUL_DISK_DEV_STATUS_FAILURE (0x00)
#endif /* !_DEV_GXEMUL_DISK_GXEMUL_DISK_H_ */

View File

@ -1,65 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008-2012 Juli Mallett <jmallett@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#ifndef _DEV_GXEMUL_ETHER_GXREG_H_
#define _DEV_GXEMUL_ETHER_GXREG_H_
#define GXEMUL_ETHER_DEV_BASE (0x14000000)
#define GXEMUL_ETHER_DEV_IRQ (3)
#define GXEMUL_ETHER_DEV_MTU (0x4000)
#define GXEMUL_ETHER_DEV_BUFFER (0x0000)
#define GXEMUL_ETHER_DEV_STATUS (0x4000)
#define GXEMUL_ETHER_DEV_LENGTH (0x4010)
#define GXEMUL_ETHER_DEV_COMMAND (0x4020)
#define GXEMUL_ETHER_DEV_MAC (0x4040)
#ifdef _LP64
#define GXEMUL_ETHER_DEV_FUNCTION(f) \
(volatile uint64_t *)MIPS_PHYS_TO_DIRECT_UNCACHED(GXEMUL_ETHER_DEV_BASE + (f))
#define GXEMUL_ETHER_DEV_READ(f) \
(volatile uint64_t)*GXEMUL_ETHER_DEV_FUNCTION(f)
#else
#define GXEMUL_ETHER_DEV_FUNCTION(f) \
(volatile uint32_t *)MIPS_PHYS_TO_DIRECT_UNCACHED(GXEMUL_ETHER_DEV_BASE + (f))
#define GXEMUL_ETHER_DEV_READ(f) \
(volatile uint32_t)*GXEMUL_ETHER_DEV_FUNCTION(f)
#endif
#define GXEMUL_ETHER_DEV_WRITE(f, v) \
*GXEMUL_ETHER_DEV_FUNCTION(f) = (v)
#define GXEMUL_ETHER_DEV_STATUS_RX_OK (0x01)
#define GXEMUL_ETHER_DEV_STATUS_RX_MORE (0x02)
#define GXEMUL_ETHER_DEV_COMMAND_RX (0x00)
#define GXEMUL_ETHER_DEV_COMMAND_TX (0x01)
#endif /* !_DEV_GXEMUL_ETHER_GXREG_H_ */

View File

@ -1,398 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008-2012 Juli Mallett <jmallett@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#include "opt_inet.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <net/bpf.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include <net/if_var.h>
#include <net/if_vlan_var.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif
#include <machine/cpuregs.h>
#include <dev/gxemul/ether/gxreg.h>
struct gx_softc {
struct ifnet *sc_ifp;
device_t sc_dev;
unsigned sc_port;
int sc_flags;
struct ifmedia sc_ifmedia;
struct resource *sc_intr;
void *sc_intr_cookie;
struct mtx sc_mtx;
};
#define GXEMUL_ETHER_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
#define GXEMUL_ETHER_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
static void gx_identify(driver_t *, device_t);
static int gx_probe(device_t);
static int gx_attach(device_t);
static int gx_detach(device_t);
static int gx_shutdown(device_t);
static void gx_init(void *);
static int gx_transmit(struct ifnet *, struct mbuf *);
static int gx_medchange(struct ifnet *);
static void gx_medstat(struct ifnet *, struct ifmediareq *);
static int gx_ioctl(struct ifnet *, u_long, caddr_t);
static void gx_rx_intr(void *);
static device_method_t gx_methods[] = {
/* Device interface */
DEVMETHOD(device_identify, gx_identify),
DEVMETHOD(device_probe, gx_probe),
DEVMETHOD(device_attach, gx_attach),
DEVMETHOD(device_detach, gx_detach),
DEVMETHOD(device_shutdown, gx_shutdown),
{ 0, 0 }
};
static driver_t gx_driver = {
"gx",
gx_methods,
sizeof (struct gx_softc),
};
DRIVER_MODULE(gx, nexus, gx_driver, 0, 0);
static void
gx_identify(driver_t *drv, device_t parent)
{
BUS_ADD_CHILD(parent, 0, "gx", 0);
}
static int
gx_probe(device_t dev)
{
if (device_get_unit(dev) != 0)
return (ENXIO);
device_set_desc(dev, "GXemul test Ethernet");
return (BUS_PROBE_NOWILDCARD);
}
static int
gx_attach(device_t dev)
{
struct ifnet *ifp;
struct gx_softc *sc;
uint8_t mac[6];
int error;
int rid;
sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_port = device_get_unit(dev);
/* Read MAC address. */
GXEMUL_ETHER_DEV_WRITE(GXEMUL_ETHER_DEV_MAC, (uintptr_t)mac);
/* Allocate and establish interrupt. */
rid = 0;
sc->sc_intr = bus_alloc_resource(sc->sc_dev, SYS_RES_IRQ, &rid,
GXEMUL_ETHER_DEV_IRQ - 2, GXEMUL_ETHER_DEV_IRQ - 2, 1, RF_ACTIVE);
if (sc->sc_intr == NULL) {
device_printf(dev, "unable to allocate IRQ.\n");
return (ENXIO);
}
error = bus_setup_intr(sc->sc_dev, sc->sc_intr, INTR_TYPE_NET, NULL,
gx_rx_intr, sc, &sc->sc_intr_cookie);
if (error != 0) {
device_printf(dev, "unable to setup interrupt.\n");
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr);
return (ENXIO);
}
bus_describe_intr(sc->sc_dev, sc->sc_intr, sc->sc_intr_cookie, "rx");
ifp = if_alloc(IFT_ETHER);
if (ifp == NULL) {
device_printf(dev, "cannot allocate ifnet.\n");
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr);
return (ENOMEM);
}
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_mtu = ETHERMTU;
ifp->if_init = gx_init;
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST | IFF_ALLMULTI;
ifp->if_ioctl = gx_ioctl;
sc->sc_ifp = ifp;
sc->sc_flags = ifp->if_flags;
ifmedia_init(&sc->sc_ifmedia, 0, gx_medchange, gx_medstat);
ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO);
mtx_init(&sc->sc_mtx, "GXemul Ethernet", NULL, MTX_DEF);
ether_ifattach(ifp, mac);
ifp->if_transmit = gx_transmit;
return (bus_generic_attach(dev));
}
static int
gx_detach(device_t dev)
{
struct gx_softc *sc;
sc = device_get_softc(dev);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr);
/* XXX Incomplete. */
return (0);
}
static int
gx_shutdown(device_t dev)
{
return (gx_detach(dev));
}
static void
gx_init(void *arg)
{
struct ifnet *ifp;
struct gx_softc *sc;
sc = arg;
ifp = sc->sc_ifp;
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
ifp->if_drv_flags |= IFF_DRV_RUNNING;
}
static int
gx_transmit(struct ifnet *ifp, struct mbuf *m)
{
struct gx_softc *sc;
sc = ifp->if_softc;
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != IFF_DRV_RUNNING) {
m_freem(m);
return (0);
}
GXEMUL_ETHER_LOCK(sc);
GXEMUL_ETHER_DEV_WRITE(GXEMUL_ETHER_DEV_LENGTH, m->m_pkthdr.len);
m_copydata(m, 0, m->m_pkthdr.len, (void *)(uintptr_t)GXEMUL_ETHER_DEV_FUNCTION(GXEMUL_ETHER_DEV_BUFFER));
GXEMUL_ETHER_DEV_WRITE(GXEMUL_ETHER_DEV_COMMAND, GXEMUL_ETHER_DEV_COMMAND_TX);
GXEMUL_ETHER_UNLOCK(sc);
ETHER_BPF_MTAP(ifp, m);
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
if_inc_counter(ifp, IFCOUNTER_OBYTES, m->m_pkthdr.len);
m_freem(m);
return (0);
}
static int
gx_medchange(struct ifnet *ifp)
{
return (ENOTSUP);
}
static void
gx_medstat(struct ifnet *ifp, struct ifmediareq *ifm)
{
struct gx_softc *sc;
sc = ifp->if_softc;
/* Lie amazingly. */
ifm->ifm_status = IFM_AVALID | IFM_ACTIVE;
ifm->ifm_active = IFT_ETHER | IFM_1000_T | IFM_FDX;
}
static int
gx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct gx_softc *sc;
struct ifreq *ifr;
#ifdef INET
struct ifaddr *ifa;
#endif
int error;
sc = ifp->if_softc;
ifr = (struct ifreq *)data;
#ifdef INET
ifa = (struct ifaddr *)data;
#endif
switch (cmd) {
case SIOCSIFADDR:
#ifdef INET
/*
* Avoid reinitialization unless it's necessary.
*/
if (ifa->ifa_addr->sa_family == AF_INET) {
ifp->if_flags |= IFF_UP;
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
gx_init(sc);
arp_ifinit(ifp, ifa);
return (0);
}
#endif
error = ether_ioctl(ifp, cmd, data);
if (error != 0)
return (error);
return (0);
case SIOCSIFFLAGS:
if (ifp->if_flags == sc->sc_flags)
return (0);
if ((ifp->if_flags & IFF_UP) != 0) {
gx_init(sc);
} else {
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
}
}
sc->sc_flags = ifp->if_flags;
return (0);
case SIOCSIFMTU:
if (ifr->ifr_mtu + ifp->if_hdrlen > GXEMUL_ETHER_DEV_MTU)
return (ENOTSUP);
return (0);
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd);
if (error != 0)
return (error);
return (0);
default:
error = ether_ioctl(ifp, cmd, data);
if (error != 0)
return (error);
return (0);
}
}
static void
gx_rx_intr(void *arg)
{
struct gx_softc *sc = arg;
GXEMUL_ETHER_LOCK(sc);
for (;;) {
uint64_t status, length;
struct mbuf *m;
/*
* XXX
* Limit number of packets received at once?
*/
status = GXEMUL_ETHER_DEV_READ(GXEMUL_ETHER_DEV_STATUS);
if (status == GXEMUL_ETHER_DEV_STATUS_RX_MORE) {
GXEMUL_ETHER_DEV_WRITE(GXEMUL_ETHER_DEV_COMMAND, GXEMUL_ETHER_DEV_COMMAND_RX);
continue;
}
if (status != GXEMUL_ETHER_DEV_STATUS_RX_OK)
break;
length = GXEMUL_ETHER_DEV_READ(GXEMUL_ETHER_DEV_LENGTH);
if (length > MCLBYTES - ETHER_ALIGN) {
if_inc_counter(sc->sc_ifp, IFCOUNTER_IERRORS, 1);
continue;
}
m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
if (m == NULL) {
device_printf(sc->sc_dev, "no memory for receive mbuf.\n");
if_inc_counter(sc->sc_ifp, IFCOUNTER_IQDROPS, 1);
GXEMUL_ETHER_UNLOCK(sc);
return;
}
/* Align incoming frame so IP headers are aligned. */
m->m_data += ETHER_ALIGN;
memcpy(m->m_data, (const void *)(uintptr_t)GXEMUL_ETHER_DEV_FUNCTION(GXEMUL_ETHER_DEV_BUFFER), length);
m->m_pkthdr.rcvif = sc->sc_ifp;
m->m_pkthdr.len = m->m_len = length;
if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
GXEMUL_ETHER_UNLOCK(sc);
(*sc->sc_ifp->if_input)(sc->sc_ifp, m);
GXEMUL_ETHER_LOCK(sc);
}
GXEMUL_ETHER_UNLOCK(sc);
}

View File

@ -1,21 +0,0 @@
# Doxyfile 1.5.2
# $FreeBSD$
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "FreeBSD kernel gxemul device code"
OUTPUT_DIRECTORY = $(DOXYGEN_DEST_PATH)/dev_gxemul/
EXTRACT_ALL = YES # for undocumented src, no warnings enabled
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = $(DOXYGEN_SRC_PATH)/dev/gxemul/ \
$(NOTREVIEWED)
GENERATE_TAGFILE = dev_gxemul/dev_gxemul.tag
@INCLUDE_PATH = $(DOXYGEN_INCLUDE_PATH)
@INCLUDE = common-Doxyfile