Remove versatile support

It was used for testing armv6 under QEMU, however since then we added
support for the QEMU virt platform.

Reviewed by:	imp, manu
Differential Revision:	https://reviews.freebsd.org/D29707
This commit is contained in:
Andrew Turner 2021-04-11 13:26:50 +00:00
parent 5d2d599d3f
commit 3da5983889
12 changed files with 1 additions and 3228 deletions

View File

@ -1,6 +1,6 @@
# $FreeBSD$
arm/versatile/sp804.c standard
arm/arm/sp804.c standard
dev/uart/uart_dev_ns8250.c optional uart
arm/annapurna/alpine/alpine_machdep.c standard

View File

@ -1,311 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo@bluezbox.com>
* 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include "pic_if.h"
#ifdef DEBUG
#define dprintf(fmt, args...) printf(fmt, ##args)
#else
#define dprintf(fmt, args...)
#endif
#define VICIRQSTATUS 0x000
#define VICFIQSTATUS 0x004
#define VICRAWINTR 0x008
#define VICINTSELECT 0x00C
#define VICINTENABLE 0x010
#define VICINTENCLEAR 0x014
#define VICSOFTINT 0x018
#define VICSOFTINTCLEAR 0x01C
#define VICPROTECTION 0x020
#define VICPERIPHID 0xFE0
#define VICPRIMECELLID 0xFF0
#define VIC_NIRQS 32
struct pl190_intc_irqsrc {
struct intr_irqsrc isrc;
u_int irq;
};
struct pl190_intc_softc {
device_t dev;
struct mtx mtx;
struct resource * intc_res;
struct pl190_intc_irqsrc isrcs[VIC_NIRQS];
};
#define INTC_VIC_READ_4(sc, reg) \
bus_read_4(sc->intc_res, (reg))
#define INTC_VIC_WRITE_4(sc, reg, val) \
bus_write_4(sc->intc_res, (reg), (val))
#define VIC_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx)
#define VIC_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx)
static inline void
pl190_intc_irq_dispatch(struct pl190_intc_softc *sc, u_int irq,
struct trapframe *tf)
{
struct pl190_intc_irqsrc *src;
src = &sc->isrcs[irq];
if (intr_isrc_dispatch(&src->isrc, tf) != 0)
device_printf(sc->dev, "Stray irq %u detected\n", irq);
}
static int
pl190_intc_intr(void *arg)
{
struct pl190_intc_softc *sc;
u_int cpu;
uint32_t num, pending;
struct trapframe *tf;
sc = arg;
cpu = PCPU_GET(cpuid);
tf = curthread->td_intr_frame;
VIC_LOCK(sc);
pending = INTC_VIC_READ_4(sc, VICIRQSTATUS);
VIC_UNLOCK(sc);
for (num = 0 ; num < VIC_NIRQS; num++) {
if (pending & (1 << num))
pl190_intc_irq_dispatch(sc, num, tf);
}
return (FILTER_HANDLED);
}
static void
pl190_intc_disable_intr(device_t dev, struct intr_irqsrc *isrc)
{
struct pl190_intc_softc *sc;
struct pl190_intc_irqsrc *src;
sc = device_get_softc(dev);
src = (struct pl190_intc_irqsrc *)isrc;
VIC_LOCK(sc);
INTC_VIC_WRITE_4(sc, VICINTENCLEAR, (1 << src->irq));
VIC_UNLOCK(sc);
}
static void
pl190_intc_enable_intr(device_t dev, struct intr_irqsrc *isrc)
{
struct pl190_intc_softc *sc;
struct pl190_intc_irqsrc *src;
sc = device_get_softc(dev);
src = (struct pl190_intc_irqsrc *)isrc;
VIC_LOCK(sc);
INTC_VIC_WRITE_4(sc, VICINTENABLE, (1 << src->irq));
VIC_UNLOCK(sc);
}
static int
pl190_intc_map_intr(device_t dev, struct intr_map_data *data,
struct intr_irqsrc **isrcp)
{
struct intr_map_data_fdt *daf;
struct pl190_intc_softc *sc;
if (data->type != INTR_MAP_DATA_FDT)
return (ENOTSUP);
daf = (struct intr_map_data_fdt *)data;
if (daf->ncells != 1 || daf->cells[0] >= VIC_NIRQS)
return (EINVAL);
sc = device_get_softc(dev);
*isrcp = &sc->isrcs[daf->cells[0]].isrc;
return (0);
}
static void
pl190_intc_pre_ithread(device_t dev, struct intr_irqsrc *isrc)
{
pl190_intc_disable_intr(dev, isrc);
}
static void
pl190_intc_post_ithread(device_t dev, struct intr_irqsrc *isrc)
{
struct pl190_intc_irqsrc *src;
src = (struct pl190_intc_irqsrc *)isrc;
pl190_intc_enable_intr(dev, isrc);
arm_irq_memory_barrier(src->irq);
}
static void
pl190_intc_post_filter(device_t dev, struct intr_irqsrc *isrc)
{
struct pl190_intc_irqsrc *src;
src = (struct pl190_intc_irqsrc *)isrc;
arm_irq_memory_barrier(src->irq);
}
static int
pl190_intc_setup_intr(device_t dev, struct intr_irqsrc *isrc,
struct resource *res, struct intr_map_data *data)
{
return (0);
}
static int
pl190_intc_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "arm,versatile-vic"))
return (ENXIO);
device_set_desc(dev, "ARM PL190 VIC");
return (BUS_PROBE_DEFAULT);
}
static int
pl190_intc_attach(device_t dev)
{
struct pl190_intc_softc *sc;
uint32_t id;
int i, rid;
struct pl190_intc_irqsrc *isrcs;
struct intr_pic *pic;
int error;
uint32_t irq;
const char *name;
phandle_t xref;
sc = device_get_softc(dev);
sc->dev = dev;
mtx_init(&sc->mtx, device_get_nameunit(dev), "pl190",
MTX_SPIN);
/* Request memory resources */
rid = 0;
sc->intc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (sc->intc_res == NULL) {
device_printf(dev, "Error: could not allocate memory resources\n");
return (ENXIO);
}
/*
* All interrupts should use IRQ line
*/
INTC_VIC_WRITE_4(sc, VICINTSELECT, 0x00000000);
/* Disable all interrupts */
INTC_VIC_WRITE_4(sc, VICINTENCLEAR, 0xffffffff);
id = 0;
for (i = 3; i >= 0; i--) {
id = (id << 8) |
(INTC_VIC_READ_4(sc, VICPERIPHID + i*4) & 0xff);
}
device_printf(dev, "Peripheral ID: %08x\n", id);
id = 0;
for (i = 3; i >= 0; i--) {
id = (id << 8) |
(INTC_VIC_READ_4(sc, VICPRIMECELLID + i*4) & 0xff);
}
device_printf(dev, "PrimeCell ID: %08x\n", id);
/* PIC attachment */
isrcs = sc->isrcs;
name = device_get_nameunit(sc->dev);
for (irq = 0; irq < VIC_NIRQS; irq++) {
isrcs[irq].irq = irq;
error = intr_isrc_register(&isrcs[irq].isrc, sc->dev,
0, "%s,%u", name, irq);
if (error != 0)
return (error);
}
xref = OF_xref_from_node(ofw_bus_get_node(sc->dev));
pic = intr_pic_register(sc->dev, xref);
if (pic == NULL)
return (ENXIO);
return (intr_pic_claim_root(sc->dev, xref, pl190_intc_intr, sc, 0));
}
static device_method_t pl190_intc_methods[] = {
DEVMETHOD(device_probe, pl190_intc_probe),
DEVMETHOD(device_attach, pl190_intc_attach),
DEVMETHOD(pic_disable_intr, pl190_intc_disable_intr),
DEVMETHOD(pic_enable_intr, pl190_intc_enable_intr),
DEVMETHOD(pic_map_intr, pl190_intc_map_intr),
DEVMETHOD(pic_post_filter, pl190_intc_post_filter),
DEVMETHOD(pic_post_ithread, pl190_intc_post_ithread),
DEVMETHOD(pic_pre_ithread, pl190_intc_pre_ithread),
DEVMETHOD(pic_setup_intr, pl190_intc_setup_intr),
DEVMETHOD_END
};
static driver_t pl190_intc_driver = {
"intc",
pl190_intc_methods,
sizeof(struct pl190_intc_softc),
};
static devclass_t pl190_intc_devclass;
EARLY_DRIVER_MODULE(intc, simplebus, pl190_intc_driver, pl190_intc_devclass,
0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_MIDDLE);

View File

@ -1,75 +0,0 @@
#
# VERSATILEPB - Configuration for QEMU version of Versatile Platform Board
#
# For more information on this file, please read the config(5) manual page,
# and/or the handbook section on Kernel Configuration Files:
#
# https://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html
#
# The handbook is also available locally in /usr/share/doc/handbook
# if you've installed the doc distribution, otherwise always see the
# FreeBSD World Wide Web server (https://www.FreeBSD.org/) for the
# latest information.
#
# An exhaustive list of options and more detailed explanations of the
# device lines is also present in the ../../conf/NOTES and NOTES files.
# If you are in doubt as to the purpose or necessity of a line, check first
# in NOTES.
#
# $FreeBSD$
ident VERSATILEPB
machine arm armv6
cpu CPU_ARM1176
include "std.armv6"
files "../versatile/files.versatile"
makeoptions MODULES_OVERRIDE=""
options KERNVIRTADDR=0xc0100000
makeoptions KERNVIRTADDR=0xc0100000
options SCHED_4BSD # 4BSD scheduler
options LINUX_BOOT_ABI # Process metadata passed from Linux boot loaders
options ROOTDEVNAME=\"ufs:da0s1a\"
device bpf
device loop
device mii
device mii_bitbang
device smc
device smcphy
device ether
device uart
device pl011
device pl190
device pty
device snp
device pci
# SCSI Controllers
device sym # NCR/Symbios/LSI Logic 53C8XX/53C1010/53C1510D
# ATA/SCSI peripherals
device scbus # SCSI bus (required for ATA/SCSI)
device da # Direct Access (disks)
device pass # Passthrough device (direct ATA/SCSI access)
# NOTE: serial console is disabled if syscons enabled
# Comment following lines for headless setup
device sc
device kbdmux
options SC_DFLT_FONT # compile font in
makeoptions SC_DFLT_FONT=cp437
device md
options PLATFORM
# Flattened Device Tree
options FDT # Configure using FDT/DTB data
options FDT_DTB_STATIC
makeoptions FDT_DTS_FILE=versatile-pb.dts

View File

@ -1,9 +0,0 @@
# $FreeBSD$
arm/versatile/pl050.c optional sc
arm/versatile/sp804.c standard
arm/versatile/versatile_machdep.c standard
arm/versatile/versatile_clcd.c optional sc
arm/versatile/versatile_pci.c optional pci
arm/versatile/versatile_scm.c standard
arm/versatile/versatile_sic.c standard

View File

@ -1,742 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
* All rights reserved.
*
* Based on dev/usb/input/ukbd.c
*
* 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/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/kdb.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/intr.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <sys/ioccom.h>
#include <sys/filio.h>
#include <sys/kbio.h>
#include <dev/kbd/kbdreg.h>
#include <machine/bus.h>
#include <dev/kbd/kbdtables.h>
#define KMI_LOCK() mtx_lock(&Giant)
#define KMI_UNLOCK() mtx_unlock(&Giant)
#ifdef INVARIANTS
/*
* Assert that the lock is held in all contexts
* where the code can be executed.
*/
#define KMI_LOCK_ASSERT() mtx_assert(&Giant, MA_OWNED)
/*
* Assert that the lock is held in the contexts
* where it really has to be so.
*/
#define KMI_CTX_LOCK_ASSERT() \
do { \
if (!kdb_active && !KERNEL_PANICKED()) \
mtx_assert(&Giant, MA_OWNED); \
} while (0)
#else
#define KMI_LOCK_ASSERT() (void)0
#define KMI_CTX_LOCK_ASSERT() (void)0
#endif
#define KMICR 0x00
#define KMICR_TYPE_NONPS2 (1 << 5)
#define KMICR_RXINTREN (1 << 4)
#define KMICR_TXINTREN (1 << 3)
#define KMICR_EN (1 << 2)
#define KMICR_FKMID (1 << 1)
#define KMICR_FKMIC (1 << 0)
#define KMISTAT 0x04
#define KMISTAT_TXEMPTY (1 << 6)
#define KMISTAT_TXBUSY (1 << 5)
#define KMISTAT_RXFULL (1 << 4)
#define KMISTAT_RXBUSY (1 << 3)
#define KMISTAT_RXPARITY (1 << 2)
#define KMISTAT_KMIC (1 << 1)
#define KMISTAT_KMID (1 << 0)
#define KMIDATA 0x08
#define KMICLKDIV 0x0C
#define KMIIR 0x10
#define KMIIR_TXINTR (1 << 1)
#define KMIIR_RXINTR (1 << 0)
#define KMI_DRIVER_NAME "kmi"
#define KMI_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
#define SET_SCANCODE_SET 0xf0
struct kmi_softc {
device_t sc_dev;
keyboard_t sc_kbd;
keymap_t sc_keymap;
accentmap_t sc_accmap;
fkeytab_t sc_fkeymap[KMI_NFKEY];
struct resource* sc_mem_res;
struct resource* sc_irq_res;
void* sc_intr_hl;
int sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
int sc_state; /* shift/lock key state */
int sc_accents; /* accent key index (> 0) */
uint32_t sc_flags; /* flags */
#define KMI_FLAG_COMPOSE 0x00000001
#define KMI_FLAG_POLLING 0x00000002
struct thread *sc_poll_thread;
};
/* Read/Write macros for Timer used as timecounter */
#define pl050_kmi_read_4(sc, reg) \
bus_read_4((sc)->sc_mem_res, (reg))
#define pl050_kmi_write_4(sc, reg, val) \
bus_write_4((sc)->sc_mem_res, (reg), (val))
/* prototypes */
static void kmi_set_leds(struct kmi_softc *, uint8_t);
static int kmi_set_typematic(keyboard_t *, int);
static uint32_t kmi_read_char(keyboard_t *, int);
static void kmi_clear_state(keyboard_t *);
static int kmi_ioctl(keyboard_t *, u_long, caddr_t);
static int kmi_enable(keyboard_t *);
static int kmi_disable(keyboard_t *);
static int kmi_attached = 0;
/* early keyboard probe, not supported */
static int
kmi_configure(int flags)
{
return (0);
}
/* detect a keyboard, not used */
static int
kmi_probe(int unit, void *arg, int flags)
{
return (ENXIO);
}
/* reset and initialize the device, not used */
static int
kmi_init(int unit, keyboard_t **kbdp, void *arg, int flags)
{
return (ENXIO);
}
/* test the interface to the device, not used */
static int
kmi_test_if(keyboard_t *kbd)
{
return (0);
}
/* finish using this keyboard, not used */
static int
kmi_term(keyboard_t *kbd)
{
return (ENXIO);
}
/* keyboard interrupt routine, not used */
static int
kmi_intr(keyboard_t *kbd, void *arg)
{
return (0);
}
/* lock the access to the keyboard, not used */
static int
kmi_lock(keyboard_t *kbd, int lock)
{
return (1);
}
/*
* Enable the access to the device; until this function is called,
* the client cannot read from the keyboard.
*/
static int
kmi_enable(keyboard_t *kbd)
{
KMI_LOCK();
KBD_ACTIVATE(kbd);
KMI_UNLOCK();
return (0);
}
/* disallow the access to the device */
static int
kmi_disable(keyboard_t *kbd)
{
KMI_LOCK();
KBD_DEACTIVATE(kbd);
KMI_UNLOCK();
return (0);
}
/* check if data is waiting */
static int
kmi_check(keyboard_t *kbd)
{
struct kmi_softc *sc = kbd->kb_data;
uint32_t reg;
KMI_CTX_LOCK_ASSERT();
if (!KBD_IS_ACTIVE(kbd))
return (0);
reg = pl050_kmi_read_4(sc, KMIIR);
return (reg & KMIIR_RXINTR);
}
/* check if char is waiting */
static int
kmi_check_char_locked(keyboard_t *kbd)
{
KMI_CTX_LOCK_ASSERT();
if (!KBD_IS_ACTIVE(kbd))
return (0);
return (kmi_check(kbd));
}
static int
kmi_check_char(keyboard_t *kbd)
{
int result;
KMI_LOCK();
result = kmi_check_char_locked(kbd);
KMI_UNLOCK();
return (result);
}
/* read one byte from the keyboard if it's allowed */
/* Currently unused. */
static int
kmi_read(keyboard_t *kbd, int wait)
{
KMI_CTX_LOCK_ASSERT();
if (!KBD_IS_ACTIVE(kbd))
return (-1);
++(kbd->kb_count);
printf("Implement ME: %s\n", __func__);
return (0);
}
/* read char from the keyboard */
static uint32_t
kmi_read_char_locked(keyboard_t *kbd, int wait)
{
struct kmi_softc *sc = kbd->kb_data;
uint32_t reg, data;
KMI_CTX_LOCK_ASSERT();
if (!KBD_IS_ACTIVE(kbd))
return (NOKEY);
reg = pl050_kmi_read_4(sc, KMIIR);
if (reg & KMIIR_RXINTR) {
data = pl050_kmi_read_4(sc, KMIDATA);
return (data);
}
++kbd->kb_count;
return (NOKEY);
}
/* Currently wait is always false. */
static uint32_t
kmi_read_char(keyboard_t *kbd, int wait)
{
uint32_t keycode;
KMI_LOCK();
keycode = kmi_read_char_locked(kbd, wait);
KMI_UNLOCK();
return (keycode);
}
/* some useful control functions */
static int
kmi_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg)
{
struct kmi_softc *sc = kbd->kb_data;
int i;
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
int ival;
#endif
KMI_LOCK_ASSERT();
switch (cmd) {
case KDGKBMODE: /* get keyboard mode */
*(int *)arg = sc->sc_mode;
break;
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
case _IO('K', 7):
ival = IOCPARM_IVAL(arg);
arg = (caddr_t)&ival;
/* FALLTHROUGH */
#endif
case KDSKBMODE: /* set keyboard mode */
switch (*(int *)arg) {
case K_XLATE:
if (sc->sc_mode != K_XLATE) {
/* make lock key state and LED state match */
sc->sc_state &= ~LOCK_MASK;
sc->sc_state |= KBD_LED_VAL(kbd);
}
/* FALLTHROUGH */
case K_RAW:
case K_CODE:
if (sc->sc_mode != *(int *)arg) {
if ((sc->sc_flags & KMI_FLAG_POLLING) == 0)
kmi_clear_state(kbd);
sc->sc_mode = *(int *)arg;
}
break;
default:
return (EINVAL);
}
break;
case KDGETLED: /* get keyboard LED */
*(int *)arg = KBD_LED_VAL(kbd);
break;
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
case _IO('K', 66):
ival = IOCPARM_IVAL(arg);
arg = (caddr_t)&ival;
/* FALLTHROUGH */
#endif
case KDSETLED: /* set keyboard LED */
/* NOTE: lock key state in "sc_state" won't be changed */
if (*(int *)arg & ~LOCK_MASK)
return (EINVAL);
i = *(int *)arg;
/* replace CAPS LED with ALTGR LED for ALTGR keyboards */
if (sc->sc_mode == K_XLATE &&
kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
if (i & ALKED)
i |= CLKED;
else
i &= ~CLKED;
}
if (KBD_HAS_DEVICE(kbd))
kmi_set_leds(sc, i);
KBD_LED_VAL(kbd) = *(int *)arg;
break;
case KDGKBSTATE: /* get lock key state */
*(int *)arg = sc->sc_state & LOCK_MASK;
break;
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
case _IO('K', 20):
ival = IOCPARM_IVAL(arg);
arg = (caddr_t)&ival;
/* FALLTHROUGH */
#endif
case KDSKBSTATE: /* set lock key state */
if (*(int *)arg & ~LOCK_MASK) {
return (EINVAL);
}
sc->sc_state &= ~LOCK_MASK;
sc->sc_state |= *(int *)arg;
/* set LEDs and quit */
return (kmi_ioctl(kbd, KDSETLED, arg));
case KDSETREPEAT: /* set keyboard repeat rate (new
* interface) */
if (!KBD_HAS_DEVICE(kbd)) {
return (0);
}
if (((int *)arg)[1] < 0) {
return (EINVAL);
}
if (((int *)arg)[0] < 0) {
return (EINVAL);
}
if (((int *)arg)[0] < 200) /* fastest possible value */
kbd->kb_delay1 = 200;
else
kbd->kb_delay1 = ((int *)arg)[0];
kbd->kb_delay2 = ((int *)arg)[1];
return (0);
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
case _IO('K', 67):
ival = IOCPARM_IVAL(arg);
arg = (caddr_t)&ival;
/* FALLTHROUGH */
#endif
case KDSETRAD: /* set keyboard repeat rate (old
* interface) */
return (kmi_set_typematic(kbd, *(int *)arg));
case PIO_KEYMAP: /* set keyboard translation table */
case OPIO_KEYMAP: /* set keyboard translation table
* (compat) */
case PIO_KEYMAPENT: /* set keyboard translation table
* entry */
case PIO_DEADKEYMAP: /* set accent key translation table */
sc->sc_accents = 0;
/* FALLTHROUGH */
default:
return (genkbd_commonioctl(kbd, cmd, arg));
}
return (0);
}
static int
kmi_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
{
int result;
/*
* XXX KDGKBSTATE, KDSKBSTATE and KDSETLED can be called from any
* context where printf(9) can be called, which among other things
* includes interrupt filters and threads with any kinds of locks
* already held. For this reason it would be dangerous to acquire
* the Giant here unconditionally. On the other hand we have to
* have it to handle the ioctl.
* So we make our best effort to auto-detect whether we can grab
* the Giant or not. Blame syscons(4) for this.
*/
switch (cmd) {
case KDGKBSTATE:
case KDSKBSTATE:
case KDSETLED:
if (!mtx_owned(&Giant) && !SCHEDULER_STOPPED())
return (EDEADLK); /* best I could come up with */
/* FALLTHROUGH */
default:
KMI_LOCK();
result = kmi_ioctl_locked(kbd, cmd, arg);
KMI_UNLOCK();
return (result);
}
}
/* clear the internal state of the keyboard */
static void
kmi_clear_state(keyboard_t *kbd)
{
struct kmi_softc *sc = kbd->kb_data;
KMI_CTX_LOCK_ASSERT();
sc->sc_flags &= ~(KMI_FLAG_COMPOSE | KMI_FLAG_POLLING);
sc->sc_state &= LOCK_MASK; /* preserve locking key state */
sc->sc_accents = 0;
}
/* save the internal state, not used */
static int
kmi_get_state(keyboard_t *kbd, void *buf, size_t len)
{
return (len == 0) ? 1 : -1;
}
/* set the internal state, not used */
static int
kmi_set_state(keyboard_t *kbd, void *buf, size_t len)
{
return (EINVAL);
}
static int
kmi_poll(keyboard_t *kbd, int on)
{
struct kmi_softc *sc = kbd->kb_data;
KMI_LOCK();
if (on) {
sc->sc_flags |= KMI_FLAG_POLLING;
sc->sc_poll_thread = curthread;
} else {
sc->sc_flags &= ~KMI_FLAG_POLLING;
}
KMI_UNLOCK();
return (0);
}
/* local functions */
static void
kmi_set_leds(struct kmi_softc *sc, uint8_t leds)
{
KMI_LOCK_ASSERT();
/* start transfer, if not already started */
printf("Implement me: %s\n", __func__);
}
static int
kmi_set_typematic(keyboard_t *kbd, int code)
{
static const int delays[] = {250, 500, 750, 1000};
static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63,
68, 76, 84, 92, 100, 110, 118, 126,
136, 152, 168, 184, 200, 220, 236, 252,
272, 304, 336, 368, 400, 440, 472, 504};
if (code & ~0x7f) {
return (EINVAL);
}
kbd->kb_delay1 = delays[(code >> 5) & 3];
kbd->kb_delay2 = rates[code & 0x1f];
return (0);
}
static keyboard_switch_t kmisw = {
.probe = &kmi_probe,
.init = &kmi_init,
.term = &kmi_term,
.intr = &kmi_intr,
.test_if = &kmi_test_if,
.enable = &kmi_enable,
.disable = &kmi_disable,
.read = &kmi_read,
.check = &kmi_check,
.read_char = &kmi_read_char,
.check_char = &kmi_check_char,
.ioctl = &kmi_ioctl,
.lock = &kmi_lock,
.clear_state = &kmi_clear_state,
.get_state = &kmi_get_state,
.set_state = &kmi_set_state,
.poll = &kmi_poll,
};
KEYBOARD_DRIVER(kmi, kmisw, kmi_configure);
static void
pl050_kmi_intr(void *arg)
{
struct kmi_softc *sc = arg;
uint32_t c;
KMI_CTX_LOCK_ASSERT();
if ((sc->sc_flags & KMI_FLAG_POLLING) != 0)
return;
if (KBD_IS_ACTIVE(&sc->sc_kbd) &&
KBD_IS_BUSY(&sc->sc_kbd)) {
/* let the callback function process the input */
(sc->sc_kbd.kb_callback.kc_func) (&sc->sc_kbd, KBDIO_KEYINPUT,
sc->sc_kbd.kb_callback.kc_arg);
} else {
/* read and discard the input, no one is waiting for it */
do {
c = kmi_read_char_locked(&sc->sc_kbd, 0);
} while (c != NOKEY);
}
}
static int
pl050_kmi_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
/*
* PL050 is plain PS2 port that pushes bytes to/from computer
* VersatilePB has two such ports and QEMU simulates keyboard
* connected to port #0 and mouse connected to port #1. This
* information can't be obtained from device tree so we just
* hardcode this knowledge here. We attach keyboard driver to
* port #0 and ignore port #1
*/
if (kmi_attached)
return (ENXIO);
if (ofw_bus_is_compatible(dev, "arm,pl050")) {
device_set_desc(dev, "PL050 Keyboard/Mouse Interface");
return (BUS_PROBE_DEFAULT);
}
return (ENXIO);
}
static int
pl050_kmi_attach(device_t dev)
{
struct kmi_softc *sc = device_get_softc(dev);
keyboard_t *kbd;
int rid;
int i;
uint32_t ack;
sc->sc_dev = dev;
kbd = &sc->sc_kbd;
rid = 0;
sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (sc->sc_mem_res == NULL) {
device_printf(dev, "could not allocate memory resource\n");
return (ENXIO);
}
/* Request the IRQ resources */
sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
if (sc->sc_irq_res == NULL) {
device_printf(dev, "Error: could not allocate irq resources\n");
return (ENXIO);
}
/* Setup and enable the timer */
if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_CLK,
NULL, pl050_kmi_intr, sc,
&sc->sc_intr_hl) != 0) {
bus_release_resource(dev, SYS_RES_IRQ, rid,
sc->sc_irq_res);
device_printf(dev, "Unable to setup the clock irq handler.\n");
return (ENXIO);
}
/* TODO: clock & divisor */
pl050_kmi_write_4(sc, KMICR, KMICR_EN);
pl050_kmi_write_4(sc, KMIDATA, SET_SCANCODE_SET);
/* read out ACK */
ack = pl050_kmi_read_4(sc, KMIDATA);
/* Set Scan Code set 1 (XT) */
pl050_kmi_write_4(sc, KMIDATA, 1);
/* read out ACK */
ack = pl050_kmi_read_4(sc, KMIDATA);
pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN);
kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER,
device_get_unit(dev), 0, 0, 0);
kbd->kb_data = (void *)sc;
sc->sc_keymap = key_map;
sc->sc_accmap = accent_map;
for (i = 0; i < KMI_NFKEY; i++) {
sc->sc_fkeymap[i] = fkey_tab[i];
}
kbd_set_maps(kbd, &sc->sc_keymap, &sc->sc_accmap,
sc->sc_fkeymap, KMI_NFKEY);
KBD_FOUND_DEVICE(kbd);
kmi_clear_state(kbd);
KBD_PROBE_DONE(kbd);
KBD_INIT_DONE(kbd);
if (kbd_register(kbd) < 0) {
goto detach;
}
KBD_CONFIG_DONE(kbd);
#ifdef KBD_INSTALL_CDEV
if (kbd_attach(kbd)) {
goto detach;
}
#endif
if (bootverbose) {
kbdd_diag(kbd, bootverbose);
}
kmi_attached = 1;
return (0);
detach:
return (ENXIO);
}
static device_method_t pl050_kmi_methods[] = {
DEVMETHOD(device_probe, pl050_kmi_probe),
DEVMETHOD(device_attach, pl050_kmi_attach),
{ 0, 0 }
};
static driver_t pl050_kmi_driver = {
"kmi",
pl050_kmi_methods,
sizeof(struct kmi_softc),
};
static devclass_t pl050_kmi_devclass;
DRIVER_MODULE(pl050_kmi, simplebus, pl050_kmi_driver, pl050_kmi_devclass, 0, 0);

View File

@ -1,921 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo@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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/malloc.h>
#include <sys/rman.h>
#include <sys/fbio.h>
#include <sys/consio.h>
#include <sys/kdb.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/intr.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/fb/fbreg.h>
#include <dev/syscons/syscons.h>
#include <arm/versatile/versatile_scm.h>
#include <machine/bus.h>
#define PL110_VENDOR_ARM926PXP 1
#define CLCD_MODE_RGB888 0x0
#define CLCD_MODE_RGB555 0x01
#define CLCD_MODE_RBG565 0x02
#define CLCD_MODE_RGB565 0x03
#define CLCDC_TIMING0 0x00
#define CLCDC_TIMING1 0x04
#define CLCDC_TIMING2 0x08
#define CLCDC_TIMING3 0x0C
#define CLCDC_TIMING3 0x0C
#define CLCDC_UPBASE 0x10
#define CLCDC_LPBASE 0x14
#ifdef PL110_VENDOR_ARM926PXP
#define CLCDC_CONTROL 0x18
#define CLCDC_IMSC 0x1C
#else
#define CLCDC_IMSC 0x18
#define CLCDC_CONTROL 0x1C
#endif
#define CONTROL_WATERMARK (1 << 16)
#define CONTROL_VCOMP_VS (0 << 12)
#define CONTROL_VCOMP_BP (1 << 12)
#define CONTROL_VCOMP_SAV (2 << 12)
#define CONTROL_VCOMP_FP (3 << 12)
#define CONTROL_PWR (1 << 11)
#define CONTROL_BEPO (1 << 10)
#define CONTROL_BEBO (1 << 9)
#define CONTROL_BGR (1 << 8)
#define CONTROL_DUAL (1 << 7)
#define CONTROL_MONO8 (1 << 6)
#define CONTROL_TFT (1 << 5)
#define CONTROL_BW (1 << 4)
#define CONTROL_BPP1 (0x00 << 1)
#define CONTROL_BPP2 (0x01 << 1)
#define CONTROL_BPP4 (0x02 << 1)
#define CONTROL_BPP8 (0x03 << 1)
#define CONTROL_BPP16 (0x04 << 1)
#define CONTROL_BPP24 (0x05 << 1)
#define CONTROL_EN (1 << 0)
#define CLCDC_RIS 0x20
#define CLCDC_MIS 0x24
#define INTR_MBERR (1 << 4)
#define INTR_VCOMP (1 << 3)
#define INTR_LNB (1 << 2)
#define INTR_FUF (1 << 1)
#define CLCDC_ICR 0x28
#ifdef DEBUG
#define dprintf(fmt, args...) do { printf("%s(): ", __func__); \
printf(fmt,##args); } while (0)
#else
#define dprintf(fmt, args...)
#endif
#define versatile_clcdc_read_4(sc, reg) \
bus_read_4((sc)->mem_res, (reg))
#define versatile_clcdc_write_4(sc, reg, val) \
bus_write_4((sc)->mem_res, (reg), (val))
struct versatile_clcdc_softc {
struct resource* mem_res;
struct mtx mtx;
int width;
int height;
int mode;
bus_dma_tag_t dma_tag;
bus_dmamap_t dma_map;
bus_addr_t fb_phys;
uint8_t *fb_base;
};
struct video_adapter_softc {
/* Videoadpater part */
video_adapter_t va;
int console;
intptr_t fb_addr;
unsigned int fb_size;
unsigned int height;
unsigned int width;
unsigned int depth;
unsigned int stride;
unsigned int xmargin;
unsigned int ymargin;
unsigned char *font;
int initialized;
};
struct argb {
uint8_t a;
uint8_t r;
uint8_t g;
uint8_t b;
};
static struct argb versatilefb_palette[16] = {
{0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xaa},
{0x00, 0x00, 0xaa, 0x00},
{0x00, 0x00, 0xaa, 0xaa},
{0x00, 0xaa, 0x00, 0x00},
{0x00, 0xaa, 0x00, 0xaa},
{0x00, 0xaa, 0x55, 0x00},
{0x00, 0xaa, 0xaa, 0xaa},
{0x00, 0x55, 0x55, 0x55},
{0x00, 0x55, 0x55, 0xff},
{0x00, 0x55, 0xff, 0x55},
{0x00, 0x55, 0xff, 0xff},
{0x00, 0xff, 0x55, 0x55},
{0x00, 0xff, 0x55, 0xff},
{0x00, 0xff, 0xff, 0x55},
{0x00, 0xff, 0xff, 0xff}
};
/* mouse pointer from dev/syscons/scgfbrndr.c */
static u_char mouse_pointer[16] = {
0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
};
#define FB_WIDTH 640
#define FB_HEIGHT 480
#define FB_DEPTH 16
#define VERSATILE_FONT_HEIGHT 16
static struct video_adapter_softc va_softc;
static int versatilefb_configure(int);
static void versatilefb_update_margins(video_adapter_t *adp);
static void
versatile_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err)
{
bus_addr_t *addr;
if (err)
return;
addr = (bus_addr_t*)arg;
*addr = segs[0].ds_addr;
}
static int
versatile_clcdc_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (ofw_bus_is_compatible(dev, "arm,pl110")) {
device_set_desc(dev, "PL110 CLCD controller");
return (BUS_PROBE_DEFAULT);
}
return (ENXIO);
}
static int
versatile_clcdc_attach(device_t dev)
{
struct versatile_clcdc_softc *sc = device_get_softc(dev);
struct video_adapter_softc *va_sc = &va_softc;
int err, rid;
uint32_t reg;
int clcdid;
int dma_size;
/* Request memory resources */
rid = 0;
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (sc->mem_res == NULL) {
device_printf(dev, "could not allocate memory resources\n");
return (ENXIO);
}
err = versatile_scm_reg_read_4(SCM_CLCD, &reg);
if (err) {
device_printf(dev, "failed to read SCM register\n");
goto fail;
}
clcdid = (reg >> SCM_CLCD_CLCDID_SHIFT) & SCM_CLCD_CLCDID_MASK;
switch (clcdid) {
case 31:
device_printf(dev, "QEMU VGA 640x480\n");
sc->width = 640;
sc->height = 480;
break;
default:
device_printf(dev, "Unsupported: %d\n", clcdid);
goto fail;
}
reg &= ~SCM_CLCD_LCD_MODE_MASK;
reg |= CLCD_MODE_RGB565;
sc->mode = CLCD_MODE_RGB565;
versatile_scm_reg_write_4(SCM_CLCD, reg);
dma_size = sc->width*sc->height*2;
/*
* Power on LCD
*/
reg |= SCM_CLCD_PWR3V5VSWITCH | SCM_CLCD_NLCDIOON;
versatile_scm_reg_write_4(SCM_CLCD, reg);
/*
* XXX: hardcoded timing for VGA. For other modes/panels
* we need to keep table of timing register values
*/
/*
* XXX: set SYS_OSC1
*/
versatile_clcdc_write_4(sc, CLCDC_TIMING0, 0x3F1F3F9C);
versatile_clcdc_write_4(sc, CLCDC_TIMING1, 0x090B61DF);
versatile_clcdc_write_4(sc, CLCDC_TIMING2, 0x067F1800);
/* XXX: timing 3? */
/*
* Now allocate framebuffer memory
*/
err = bus_dma_tag_create(
bus_get_dma_tag(dev),
4, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
dma_size, 1, /* maxsize, nsegments */
dma_size, 0, /* maxsegsize, flags */
NULL, NULL, /* lockfunc, lockarg */
&sc->dma_tag);
err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_base,
0, &sc->dma_map);
if (err) {
device_printf(dev, "cannot allocate framebuffer\n");
goto fail;
}
err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_base,
dma_size, versatile_fb_dmamap_cb, &sc->fb_phys, BUS_DMA_NOWAIT);
if (err) {
device_printf(dev, "cannot load DMA map\n");
goto fail;
}
/* Make sure it's blank */
memset(sc->fb_base, 0x00, dma_size);
versatile_clcdc_write_4(sc, CLCDC_UPBASE, sc->fb_phys);
err = (sc_attach_unit(device_get_unit(dev),
device_get_flags(dev) | SC_AUTODETECT_KBD));
if (err) {
device_printf(dev, "failed to attach syscons\n");
goto fail;
}
/*
* XXX: hardcoded for VGA
*/
reg = CONTROL_VCOMP_BP | CONTROL_TFT | CONTROL_BGR | CONTROL_EN;
reg |= CONTROL_BPP16;
versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
DELAY(20);
reg |= CONTROL_PWR;
versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
va_sc->fb_addr = (vm_offset_t)sc->fb_base;
va_sc->fb_size = dma_size;
va_sc->width = sc->width;
va_sc->height = sc->height;
va_sc->depth = 16;
va_sc->stride = sc->width * 2;
versatilefb_update_margins(&va_sc->va);
return (0);
fail:
if (sc->fb_base)
bus_dmamem_free(sc->dma_tag, sc->fb_base, sc->dma_map);
if (sc->dma_tag)
bus_dma_tag_destroy(sc->dma_tag);
return (err);
}
static device_method_t versatile_clcdc_methods[] = {
DEVMETHOD(device_probe, versatile_clcdc_probe),
DEVMETHOD(device_attach, versatile_clcdc_attach),
DEVMETHOD_END
};
static driver_t versatile_clcdc_driver = {
"clcdc",
versatile_clcdc_methods,
sizeof(struct versatile_clcdc_softc),
};
static devclass_t versatile_clcdc_devclass;
DRIVER_MODULE(versatile_clcdc, simplebus, versatile_clcdc_driver, versatile_clcdc_devclass, 0, 0);
/*
* Video driver routines and glue.
*/
static vi_probe_t versatilefb_probe;
static vi_init_t versatilefb_init;
static vi_get_info_t versatilefb_get_info;
static vi_query_mode_t versatilefb_query_mode;
static vi_set_mode_t versatilefb_set_mode;
static vi_save_font_t versatilefb_save_font;
static vi_load_font_t versatilefb_load_font;
static vi_show_font_t versatilefb_show_font;
static vi_save_palette_t versatilefb_save_palette;
static vi_load_palette_t versatilefb_load_palette;
static vi_set_border_t versatilefb_set_border;
static vi_save_state_t versatilefb_save_state;
static vi_load_state_t versatilefb_load_state;
static vi_set_win_org_t versatilefb_set_win_org;
static vi_read_hw_cursor_t versatilefb_read_hw_cursor;
static vi_set_hw_cursor_t versatilefb_set_hw_cursor;
static vi_set_hw_cursor_shape_t versatilefb_set_hw_cursor_shape;
static vi_blank_display_t versatilefb_blank_display;
static vi_mmap_t versatilefb_mmap;
static vi_ioctl_t versatilefb_ioctl;
static vi_clear_t versatilefb_clear;
static vi_fill_rect_t versatilefb_fill_rect;
static vi_bitblt_t versatilefb_bitblt;
static vi_diag_t versatilefb_diag;
static vi_save_cursor_palette_t versatilefb_save_cursor_palette;
static vi_load_cursor_palette_t versatilefb_load_cursor_palette;
static vi_copy_t versatilefb_copy;
static vi_putp_t versatilefb_putp;
static vi_putc_t versatilefb_putc;
static vi_puts_t versatilefb_puts;
static vi_putm_t versatilefb_putm;
static video_switch_t versatilefbvidsw = {
.probe = versatilefb_probe,
.init = versatilefb_init,
.get_info = versatilefb_get_info,
.query_mode = versatilefb_query_mode,
.set_mode = versatilefb_set_mode,
.save_font = versatilefb_save_font,
.load_font = versatilefb_load_font,
.show_font = versatilefb_show_font,
.save_palette = versatilefb_save_palette,
.load_palette = versatilefb_load_palette,
.set_border = versatilefb_set_border,
.save_state = versatilefb_save_state,
.load_state = versatilefb_load_state,
.set_win_org = versatilefb_set_win_org,
.read_hw_cursor = versatilefb_read_hw_cursor,
.set_hw_cursor = versatilefb_set_hw_cursor,
.set_hw_cursor_shape = versatilefb_set_hw_cursor_shape,
.blank_display = versatilefb_blank_display,
.mmap = versatilefb_mmap,
.ioctl = versatilefb_ioctl,
.clear = versatilefb_clear,
.fill_rect = versatilefb_fill_rect,
.bitblt = versatilefb_bitblt,
.diag = versatilefb_diag,
.save_cursor_palette = versatilefb_save_cursor_palette,
.load_cursor_palette = versatilefb_load_cursor_palette,
.copy = versatilefb_copy,
.putp = versatilefb_putp,
.putc = versatilefb_putc,
.puts = versatilefb_puts,
.putm = versatilefb_putm,
};
VIDEO_DRIVER(versatilefb, versatilefbvidsw, versatilefb_configure);
static vr_init_t clcdr_init;
static vr_clear_t clcdr_clear;
static vr_draw_border_t clcdr_draw_border;
static vr_draw_t clcdr_draw;
static vr_set_cursor_t clcdr_set_cursor;
static vr_draw_cursor_t clcdr_draw_cursor;
static vr_blink_cursor_t clcdr_blink_cursor;
static vr_set_mouse_t clcdr_set_mouse;
static vr_draw_mouse_t clcdr_draw_mouse;
/*
* We use our own renderer; this is because we must emulate a hardware
* cursor.
*/
static sc_rndr_sw_t clcdrend = {
clcdr_init,
clcdr_clear,
clcdr_draw_border,
clcdr_draw,
clcdr_set_cursor,
clcdr_draw_cursor,
clcdr_blink_cursor,
clcdr_set_mouse,
clcdr_draw_mouse
};
RENDERER(versatilefb, 0, clcdrend, gfb_set);
RENDERER_MODULE(versatilefb, gfb_set);
static void
clcdr_init(scr_stat* scp)
{
}
static void
clcdr_clear(scr_stat* scp, int c, int attr)
{
}
static void
clcdr_draw_border(scr_stat* scp, int color)
{
}
static void
clcdr_draw(scr_stat* scp, int from, int count, int flip)
{
video_adapter_t* adp = scp->sc->adp;
int i, c, a;
if (!flip) {
/* Normal printing */
vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
} else {
/* This is for selections and such: invert the color attribute */
for (i = count; i-- > 0; ++from) {
c = sc_vtb_getc(&scp->vtb, from);
a = sc_vtb_geta(&scp->vtb, from) >> 8;
vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
}
}
}
static void
clcdr_set_cursor(scr_stat* scp, int base, int height, int blink)
{
}
static void
clcdr_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
{
video_adapter_t* adp = scp->sc->adp;
struct video_adapter_softc *sc;
int row, col;
uint8_t *addr;
int i,j;
sc = (struct video_adapter_softc *)adp;
if (scp->curs_attr.height <= 0)
return;
if (sc->fb_addr == 0)
return;
if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
return;
/* calculate the coordinates in the video buffer */
row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
addr = (uint8_t *)sc->fb_addr
+ (row + sc->ymargin)*(sc->stride)
+ (sc->depth/8) * (col + sc->xmargin);
/* our cursor consists of simply inverting the char under it */
for (i = 0; i < adp->va_info.vi_cheight; i++) {
for (j = 0; j < adp->va_info.vi_cwidth; j++) {
addr[2*j] ^= 0xff;
addr[2*j + 1] ^= 0xff;
}
addr += sc->stride;
}
}
static void
clcdr_blink_cursor(scr_stat* scp, int at, int flip)
{
}
static void
clcdr_set_mouse(scr_stat* scp)
{
}
static void
clcdr_draw_mouse(scr_stat* scp, int x, int y, int on)
{
vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
}
static uint16_t versatilefb_static_window[ROW*COL];
extern u_char dflt_font_16[];
/*
* Update videoadapter settings after changing resolution
*/
static void
versatilefb_update_margins(video_adapter_t *adp)
{
struct video_adapter_softc *sc;
video_info_t *vi;
sc = (struct video_adapter_softc *)adp;
vi = &adp->va_info;
sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
}
static int
versatilefb_configure(int flags)
{
struct video_adapter_softc *va_sc;
va_sc = &va_softc;
if (va_sc->initialized)
return (0);
va_sc->width = FB_WIDTH;
va_sc->height = FB_HEIGHT;
va_sc->depth = FB_DEPTH;
versatilefb_init(0, &va_sc->va, 0);
va_sc->initialized = 1;
return (0);
}
static int
versatilefb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
{
return (0);
}
static int
versatilefb_init(int unit, video_adapter_t *adp, int flags)
{
struct video_adapter_softc *sc;
video_info_t *vi;
sc = (struct video_adapter_softc *)adp;
vi = &adp->va_info;
vid_init_struct(adp, "versatilefb", -1, unit);
sc->font = dflt_font_16;
vi->vi_cheight = VERSATILE_FONT_HEIGHT;
vi->vi_cwidth = 8;
vi->vi_width = sc->width/8;
vi->vi_height = sc->height/vi->vi_cheight;
/*
* Clamp width/height to syscons maximums
*/
if (vi->vi_width > COL)
vi->vi_width = COL;
if (vi->vi_height > ROW)
vi->vi_height = ROW;
sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
adp->va_window = (vm_offset_t) versatilefb_static_window;
adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
vid_register(&sc->va);
return (0);
}
static int
versatilefb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
{
bcopy(&adp->va_info, info, sizeof(*info));
return (0);
}
static int
versatilefb_query_mode(video_adapter_t *adp, video_info_t *info)
{
return (0);
}
static int
versatilefb_set_mode(video_adapter_t *adp, int mode)
{
return (0);
}
static int
versatilefb_save_font(video_adapter_t *adp, int page, int size, int width,
u_char *data, int c, int count)
{
return (0);
}
static int
versatilefb_load_font(video_adapter_t *adp, int page, int size, int width,
u_char *data, int c, int count)
{
struct video_adapter_softc *sc = (struct video_adapter_softc *)adp;
sc->font = data;
return (0);
}
static int
versatilefb_show_font(video_adapter_t *adp, int page)
{
return (0);
}
static int
versatilefb_save_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
versatilefb_load_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
versatilefb_set_border(video_adapter_t *adp, int border)
{
return (versatilefb_blank_display(adp, border));
}
static int
versatilefb_save_state(video_adapter_t *adp, void *p, size_t size)
{
return (0);
}
static int
versatilefb_load_state(video_adapter_t *adp, void *p)
{
return (0);
}
static int
versatilefb_set_win_org(video_adapter_t *adp, off_t offset)
{
return (0);
}
static int
versatilefb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
{
*col = *row = 0;
return (0);
}
static int
versatilefb_set_hw_cursor(video_adapter_t *adp, int col, int row)
{
return (0);
}
static int
versatilefb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
int celsize, int blink)
{
return (0);
}
static int
versatilefb_blank_display(video_adapter_t *adp, int mode)
{
struct video_adapter_softc *sc;
sc = (struct video_adapter_softc *)adp;
if (sc && sc->fb_addr)
memset((void*)sc->fb_addr, 0, sc->fb_size);
return (0);
}
static int
versatilefb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
int prot, vm_memattr_t *memattr)
{
struct video_adapter_softc *sc;
sc = (struct video_adapter_softc *)adp;
/*
* This might be a legacy VGA mem request: if so, just point it at the
* framebuffer, since it shouldn't be touched
*/
if (offset < sc->stride*sc->height) {
*paddr = sc->fb_addr + offset;
return (0);
}
return (EINVAL);
}
static int
versatilefb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
{
return (0);
}
static int
versatilefb_clear(video_adapter_t *adp)
{
return (versatilefb_blank_display(adp, 0));
}
static int
versatilefb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
{
return (0);
}
static int
versatilefb_bitblt(video_adapter_t *adp, ...)
{
return (0);
}
static int
versatilefb_diag(video_adapter_t *adp, int level)
{
return (0);
}
static int
versatilefb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
versatilefb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
versatilefb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
{
return (0);
}
static int
versatilefb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
int size, int bpp, int bit_ltor, int byte_ltor)
{
return (0);
}
static int
versatilefb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
{
struct video_adapter_softc *sc;
int row;
int col;
int i, j, k;
uint8_t *addr;
u_char *p;
uint8_t fg, bg, color;
uint16_t rgb;
sc = (struct video_adapter_softc *)adp;
if (sc->fb_addr == 0)
return (0);
if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
return (0);
row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
p = sc->font + c*VERSATILE_FONT_HEIGHT;
addr = (uint8_t *)sc->fb_addr
+ (row + sc->ymargin)*(sc->stride)
+ (sc->depth/8) * (col + sc->xmargin);
fg = a & 0xf ;
bg = (a >> 4) & 0xf;
for (i = 0; i < VERSATILE_FONT_HEIGHT; i++) {
for (j = 0, k = 7; j < 8; j++, k--) {
if ((p[i] & (1 << k)) == 0)
color = bg;
else
color = fg;
switch (sc->depth) {
case 16:
rgb = (versatilefb_palette[color].r >> 3) << 11;
rgb |= (versatilefb_palette[color].g >> 2) << 5;
rgb |= (versatilefb_palette[color].b >> 3);
addr[2*j] = rgb & 0xff;
addr[2*j + 1] = (rgb >> 8) & 0xff;
default:
/* Not supported yet */
break;
}
}
addr += (sc->stride);
}
return (0);
}
static int
versatilefb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
{
int i;
for (i = 0; i < len; i++)
versatilefb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
return (0);
}
static int
versatilefb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
uint32_t pixel_mask, int size, int width)
{
return (0);
}

View File

@ -1,104 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-4-Clause
*
* Copyright (c) 2012 Oleksandr Tymoshenko.
* All rights reserved.
*
* This code is derived from software written for Brini by Mark Brinicombe
*
* 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 Brini.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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 "opt_ddb.h"
#include "opt_platform.h"
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/devmap.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/bus.h>
#include <machine/machdep.h>
#include <machine/platform.h>
#include <machine/platformvar.h>
#include "platform_if.h"
/* Start of address space used for bootstrap map */
#define DEVMAP_BOOTSTRAP_MAP_START 0xE0000000
static vm_offset_t
versatile_lastaddr(platform_t plat)
{
return (DEVMAP_BOOTSTRAP_MAP_START);
}
#define FDT_DEVMAP_MAX (2) /* FIXME */
static struct devmap_entry fdt_devmap[FDT_DEVMAP_MAX] = {
{ 0, 0, 0, },
{ 0, 0, 0, }
};
/*
* Construct devmap table with DT-derived config data.
*/
static int
versatile_devmap_init(platform_t plat)
{
int i = 0;
fdt_devmap[i].pd_va = 0xf0100000;
fdt_devmap[i].pd_pa = 0x10100000;
fdt_devmap[i].pd_size = 0x01000000; /* 1 MB */
devmap_register_table(&fdt_devmap[0]);
return (0);
}
static void
versatile_cpu_reset(platform_t plat)
{
printf("cpu_reset\n");
while (1);
}
static platform_method_t versatile_methods[] = {
PLATFORMMETHOD(platform_lastaddr, versatile_lastaddr),
PLATFORMMETHOD(platform_devmap_init, versatile_devmap_init),
PLATFORMMETHOD(platform_cpu_reset, versatile_cpu_reset),
PLATFORMMETHOD_END,
};
FDT_PLATFORM_DEF(versatile, "versatile", 0, "arm,versatile-pb", 1);

View File

@ -1,548 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo@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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.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 <sys/watchdog.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/intr.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcib_private.h>
#include "pcib_if.h"
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
#include <arm/versatile/versatile_scm.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#define MEM_CORE 0
#define MEM_BASE 1
#define MEM_CONF_BASE 2
#define MEM_REGIONS 3
#define PCI_CORE_IMAP0 0x00
#define PCI_CORE_IMAP1 0x04
#define PCI_CORE_IMAP2 0x08
#define PCI_CORE_SELFID 0x0C
#define PCI_CORE_SMAP0 0x10
#define PCI_CORE_SMAP1 0x14
#define PCI_CORE_SMAP2 0x18
#define VERSATILE_PCI_DEV 0x030010ee
#define VERSATILE_PCI_CLASS 0x0b400000
#define PCI_IO_WINDOW 0x44000000
#define PCI_IO_SIZE 0x0c000000
#define PCI_NPREFETCH_WINDOW 0x50000000
#define PCI_NPREFETCH_SIZE 0x10000000
#define PCI_PREFETCH_WINDOW 0x60000000
#define PCI_PREFETCH_SIZE 0x10000000
#define VERSATILE_PCI_IRQ_START 27
#define VERSATILE_PCI_IRQ_END 30
#ifdef DEBUG
#define dprintf(fmt, args...) do { printf("%s(): ", __func__); \
printf(fmt,##args); } while (0)
#else
#define dprintf(fmt, args...)
#endif
#define versatile_pci_core_read_4(reg) \
bus_read_4(sc->mem_res[MEM_CORE], (reg))
#define versatile_pci_core_write_4(reg, val) \
bus_write_4(sc->mem_res[MEM_CORE], (reg), (val))
#define versatile_pci_read_4(reg) \
bus_read_4(sc->mem_res[MEM_BASE], (reg))
#define versatile_pci_write_4(reg, val) \
bus_write_4(sc->mem_res[MEM_BASE], (reg), (val))
#define versatile_pci_conf_read_4(reg) \
bus_read_4(sc->mem_res[MEM_CONF_BASE], (reg))
#define versatile_pci_conf_write_4(reg, val) \
bus_write_4(sc->mem_res[MEM_CONF_BASE], (reg), (val))
#define versatile_pci_conf_write_2(reg, val) \
bus_write_2(sc->mem_res[MEM_CONF_BASE], (reg), (val))
#define versatile_pci_conf_write_1(reg, val) \
bus_write_1(sc->mem_res[MEM_CONF_BASE], (reg), (val))
struct versatile_pci_softc {
struct resource* mem_res[MEM_REGIONS];
struct resource* irq_res;
void* intr_hl;
int pcib_slot;
/* Bus part */
int busno;
struct rman io_rman;
struct rman irq_rman;
struct rman mem_rman;
struct mtx mtx;
struct ofw_bus_iinfo pci_iinfo;
};
static struct resource_spec versatile_pci_mem_spec[] = {
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
{ SYS_RES_MEMORY, 1, RF_ACTIVE },
{ SYS_RES_MEMORY, 2, RF_ACTIVE },
{ -1, 0, 0 }
};
static int
versatile_pci_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (ofw_bus_is_compatible(dev, "arm,versatile-pci")) {
device_set_desc(dev, "Versatile PCI controller");
return (BUS_PROBE_DEFAULT);
}
return (ENXIO);
}
static int
versatile_pci_attach(device_t dev)
{
struct versatile_pci_softc *sc = device_get_softc(dev);
int err;
int slot;
uint32_t vendordev_id, class_id;
uint32_t val;
phandle_t node;
node = ofw_bus_get_node(dev);
/* Request memory resources */
err = bus_alloc_resources(dev, versatile_pci_mem_spec,
sc->mem_res);
if (err) {
device_printf(dev, "Error: could not allocate memory resources\n");
return (ENXIO);
}
/*
* Setup memory windows
*/
versatile_pci_core_write_4(PCI_CORE_IMAP0, (PCI_IO_WINDOW >> 28));
versatile_pci_core_write_4(PCI_CORE_IMAP1, (PCI_NPREFETCH_WINDOW >> 28));
versatile_pci_core_write_4(PCI_CORE_IMAP2, (PCI_PREFETCH_WINDOW >> 28));
/*
* XXX: this is SDRAM offset >> 28
* Unused as of QEMU 1.5
*/
versatile_pci_core_write_4(PCI_CORE_SMAP0, (PCI_IO_WINDOW >> 28));
versatile_pci_core_write_4(PCI_CORE_SMAP1, (PCI_NPREFETCH_WINDOW >> 28));
versatile_pci_core_write_4(PCI_CORE_SMAP2, (PCI_NPREFETCH_WINDOW >> 28));
versatile_scm_reg_write_4(SCM_PCICTL, 1);
for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
vendordev_id = versatile_pci_read_4((slot << 11) + PCIR_DEVVENDOR);
class_id = versatile_pci_read_4((slot << 11) + PCIR_REVID);
if ((vendordev_id == VERSATILE_PCI_DEV) &&
(class_id == VERSATILE_PCI_CLASS))
break;
}
if (slot == (PCI_SLOTMAX + 1)) {
bus_release_resources(dev, versatile_pci_mem_spec,
sc->mem_res);
device_printf(dev, "Versatile PCI core not found\n");
return (ENXIO);
}
sc->pcib_slot = slot;
device_printf(dev, "PCI core at slot #%d\n", slot);
versatile_pci_core_write_4(PCI_CORE_SELFID, slot);
val = versatile_pci_conf_read_4((slot << 11) + PCIR_COMMAND);
val |= (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN | PCIM_CMD_MWRICEN);
versatile_pci_conf_write_4((slot << 11) + PCIR_COMMAND, val);
/* Again SDRAM start >> 28 */
versatile_pci_write_4((slot << 11) + PCIR_BAR(0), 0);
versatile_pci_write_4((slot << 11) + PCIR_BAR(1), 0);
versatile_pci_write_4((slot << 11) + PCIR_BAR(2), 0);
/* Prepare resource managers */
sc->mem_rman.rm_type = RMAN_ARRAY;
sc->mem_rman.rm_descr = "versatile PCI memory window";
if (rman_init(&sc->mem_rman) != 0 ||
rman_manage_region(&sc->mem_rman, PCI_NPREFETCH_WINDOW,
PCI_NPREFETCH_WINDOW + PCI_NPREFETCH_SIZE - 1) != 0) {
panic("versatile_pci_attach: failed to set up memory rman");
}
bootverbose = 1;
sc->io_rman.rm_type = RMAN_ARRAY;
sc->io_rman.rm_descr = "versatile PCI IO window";
if (rman_init(&sc->io_rman) != 0 ||
rman_manage_region(&sc->io_rman, PCI_IO_WINDOW,
PCI_IO_WINDOW + PCI_IO_SIZE - 1) != 0) {
panic("versatile_pci_attach: failed to set up I/O rman");
}
sc->irq_rman.rm_type = RMAN_ARRAY;
sc->irq_rman.rm_descr = "versatile PCI IRQs";
if (rman_init(&sc->irq_rman) != 0 ||
rman_manage_region(&sc->irq_rman, VERSATILE_PCI_IRQ_START,
VERSATILE_PCI_IRQ_END) != 0) {
panic("versatile_pci_attach: failed to set up IRQ rman");
}
mtx_init(&sc->mtx, device_get_nameunit(dev), "versatilepci",
MTX_SPIN);
val = versatile_pci_conf_read_4((12 << 11) + PCIR_COMMAND);
for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
vendordev_id = versatile_pci_read_4((slot << 11) + PCIR_DEVVENDOR);
class_id = versatile_pci_read_4((slot << 11) + PCIR_REVID);
if (slot == sc->pcib_slot)
continue;
if ((vendordev_id == 0xffffffff) &&
(class_id == 0xffffffff))
continue;
val = versatile_pci_conf_read_4((slot << 11) + PCIR_COMMAND);
val |= PCIM_CMD_MEMEN | PCIM_CMD_PORTEN;
versatile_pci_conf_write_4((slot << 11) + PCIR_COMMAND, val);
}
ofw_bus_setup_iinfo(node, &sc->pci_iinfo, sizeof(cell_t));
device_add_child(dev, "pci", -1);
return (bus_generic_attach(dev));
}
static int
versatile_pci_read_ivar(device_t dev, device_t child, int which,
uintptr_t *result)
{
struct versatile_pci_softc *sc = device_get_softc(dev);
switch (which) {
case PCIB_IVAR_DOMAIN:
*result = 0;
return (0);
case PCIB_IVAR_BUS:
*result = sc->busno;
return (0);
}
return (ENOENT);
}
static int
versatile_pci_write_ivar(device_t dev, device_t child, int which,
uintptr_t result)
{
struct versatile_pci_softc * sc = device_get_softc(dev);
switch (which) {
case PCIB_IVAR_BUS:
sc->busno = result;
return (0);
}
return (ENOENT);
}
static struct resource *
versatile_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
{
struct versatile_pci_softc *sc = device_get_softc(bus);
struct resource *rv;
struct rman *rm;
dprintf("Alloc resources %d, %08lx..%08lx, %ld\n", type, start, end, count);
switch (type) {
case SYS_RES_IOPORT:
rm = &sc->io_rman;
break;
case SYS_RES_IRQ:
rm = NULL;
break;
case SYS_RES_MEMORY:
rm = &sc->mem_rman;
break;
default:
return (NULL);
}
if (rm == NULL)
return (BUS_ALLOC_RESOURCE(device_get_parent(bus),
child, type, rid, start, end, count, flags));
rv = rman_reserve_resource(rm, start, end, count, flags, child);
if (rv == NULL)
return (NULL);
rman_set_rid(rv, *rid);
if (flags & RF_ACTIVE) {
if (bus_activate_resource(child, type, *rid, rv)) {
rman_release_resource(rv);
return (NULL);
}
}
return (rv);
}
static int
versatile_pci_activate_resource(device_t bus, device_t child, int type, int rid,
struct resource *r)
{
vm_offset_t vaddr;
int res;
switch(type) {
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
vaddr = (vm_offset_t)pmap_mapdev(rman_get_start(r),
rman_get_size(r));
rman_set_bushandle(r, vaddr);
rman_set_bustag(r, fdtbus_bs_tag);
res = rman_activate_resource(r);
break;
case SYS_RES_IRQ:
res = (BUS_ACTIVATE_RESOURCE(device_get_parent(bus),
child, type, rid, r));
break;
default:
res = ENXIO;
break;
}
return (res);
}
static int
versatile_pci_setup_intr(device_t bus, device_t child, struct resource *ires,
int flags, driver_filter_t *filt, driver_intr_t *handler,
void *arg, void **cookiep)
{
return BUS_SETUP_INTR(device_get_parent(bus), bus, ires, flags,
filt, handler, arg, cookiep);
}
static int
versatile_pci_teardown_intr(device_t dev, device_t child, struct resource *ires,
void *cookie)
{
return BUS_TEARDOWN_INTR(device_get_parent(dev), dev, ires, cookie);
}
static int
versatile_pci_maxslots(device_t dev)
{
return (PCI_SLOTMAX);
}
static int
versatile_pci_route_interrupt(device_t bus, device_t dev, int pin)
{
struct versatile_pci_softc *sc;
struct ofw_pci_register reg;
uint32_t pintr, mintr[4];
phandle_t iparent;
int intrcells;
sc = device_get_softc(bus);
pintr = pin;
bzero(&reg, sizeof(reg));
reg.phys_hi = (pci_get_bus(dev) << OFW_PCI_PHYS_HI_BUSSHIFT) |
(pci_get_slot(dev) << OFW_PCI_PHYS_HI_DEVICESHIFT) |
(pci_get_function(dev) << OFW_PCI_PHYS_HI_FUNCTIONSHIFT);
intrcells = ofw_bus_lookup_imap(ofw_bus_get_node(dev),
&sc->pci_iinfo, &reg, sizeof(reg), &pintr, sizeof(pintr),
mintr, sizeof(mintr), &iparent);
if (intrcells) {
pintr = ofw_bus_map_intr(dev, iparent, intrcells, mintr);
return (pintr);
}
device_printf(bus, "could not route pin %d for device %d.%d\n",
pin, pci_get_slot(dev), pci_get_function(dev));
return (PCI_INVALID_IRQ);
}
static uint32_t
versatile_pci_read_config(device_t dev, u_int bus, u_int slot, u_int func,
u_int reg, int bytes)
{
struct versatile_pci_softc *sc = device_get_softc(dev);
uint32_t data;
uint32_t shift, mask;
uint32_t addr;
if (sc->pcib_slot == slot) {
switch (bytes) {
case 4:
return (0xffffffff);
break;
case 2:
return (0xffff);
break;
case 1:
return (0xff);
break;
}
}
addr = (bus << 16) | (slot << 11) | (func << 8) | (reg & ~3);
/* register access is 32-bit aligned */
shift = (reg & 3) * 8;
/* Create a mask based on the width, post-shift */
if (bytes == 2)
mask = 0xffff;
else if (bytes == 1)
mask = 0xff;
else
mask = 0xffffffff;
dprintf("%s: tag (%x, %x, %x) reg %d(%d)\n", __func__, bus, slot,
func, reg, bytes);
mtx_lock_spin(&sc->mtx);
data = versatile_pci_conf_read_4(addr);
mtx_unlock_spin(&sc->mtx);
/* get request bytes from 32-bit word */
data = (data >> shift) & mask;
dprintf("%s: read 0x%x\n", __func__, data);
return (data);
}
static void
versatile_pci_write_config(device_t dev, u_int bus, u_int slot, u_int func,
u_int reg, uint32_t data, int bytes)
{
struct versatile_pci_softc *sc = device_get_softc(dev);
uint32_t addr;
dprintf("%s: tag (%x, %x, %x) reg %d(%d)\n", __func__, bus, slot,
func, reg, bytes);
if (sc->pcib_slot == slot)
return;
addr = (bus << 16) | (slot << 11) | (func << 8) | reg;
mtx_lock_spin(&sc->mtx);
switch (bytes) {
case 4:
versatile_pci_conf_write_4(addr, data);
break;
case 2:
versatile_pci_conf_write_2(addr, data);
break;
case 1:
versatile_pci_conf_write_1(addr, data);
break;
}
mtx_unlock_spin(&sc->mtx);
}
static device_method_t versatile_pci_methods[] = {
DEVMETHOD(device_probe, versatile_pci_probe),
DEVMETHOD(device_attach, versatile_pci_attach),
/* Bus interface */
DEVMETHOD(bus_read_ivar, versatile_pci_read_ivar),
DEVMETHOD(bus_write_ivar, versatile_pci_write_ivar),
DEVMETHOD(bus_alloc_resource, versatile_pci_alloc_resource),
DEVMETHOD(bus_release_resource, bus_generic_release_resource),
DEVMETHOD(bus_activate_resource, versatile_pci_activate_resource),
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
DEVMETHOD(bus_setup_intr, versatile_pci_setup_intr),
DEVMETHOD(bus_teardown_intr, versatile_pci_teardown_intr),
/* pcib interface */
DEVMETHOD(pcib_maxslots, versatile_pci_maxslots),
DEVMETHOD(pcib_read_config, versatile_pci_read_config),
DEVMETHOD(pcib_write_config, versatile_pci_write_config),
DEVMETHOD(pcib_route_interrupt, versatile_pci_route_interrupt),
DEVMETHOD(pcib_request_feature, pcib_request_feature_allow),
DEVMETHOD_END
};
static driver_t versatile_pci_driver = {
"pcib",
versatile_pci_methods,
sizeof(struct versatile_pci_softc),
};
static devclass_t versatile_pci_devclass;
DRIVER_MODULE(versatile_pci, simplebus, versatile_pci_driver, versatile_pci_devclass, 0, 0);

View File

@ -1,144 +0,0 @@
/*
* Copyright (c) 2017 Oleksandr Tymoshenko <gonzo@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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Ben Gray.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY BEN GRAY ``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 BEN GRAY 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.
*/
/*
* SCM - System Control Module
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/resource.h>
#include <sys/rman.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include "versatile_scm.h"
struct versatile_scm_softc {
device_t sc_dev;
struct resource * sc_mem_res;
};
static struct versatile_scm_softc *versatile_scm_sc;
#define versatile_scm_read_4(sc, reg) \
bus_read_4((sc)->sc_mem_res, (reg))
#define versatile_scm_write_4(sc, reg, val) \
bus_write_4((sc)->sc_mem_res, (reg), (val))
static int
versatile_scm_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "syscon"))
return (ENXIO);
if (versatile_scm_sc) {
return (EEXIST);
}
device_set_desc(dev, "Versatile Control Module");
return (BUS_PROBE_DEFAULT);
}
static int
versatile_scm_attach(device_t dev)
{
struct versatile_scm_softc *sc;
int rid;
sc = device_get_softc(dev);
sc->sc_dev = dev;
rid = 0;
sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (sc->sc_mem_res == NULL) {
device_printf(dev, "could not allocate memory resources\n");
return (ENXIO);
}
versatile_scm_sc = sc;
return (0);
}
int
versatile_scm_reg_read_4(uint32_t reg, uint32_t *val)
{
if (!versatile_scm_sc)
return (ENXIO);
*val = versatile_scm_read_4(versatile_scm_sc, reg);
return (0);
}
int
versatile_scm_reg_write_4(uint32_t reg, uint32_t val)
{
if (!versatile_scm_sc)
return (ENXIO);
versatile_scm_write_4(versatile_scm_sc, reg, val);
return (0);
}
static device_method_t versatile_scm_methods[] = {
DEVMETHOD(device_probe, versatile_scm_probe),
DEVMETHOD(device_attach, versatile_scm_attach),
DEVMETHOD_END
};
static driver_t versatile_scm_driver = {
"scm",
versatile_scm_methods,
sizeof(struct versatile_scm_softc),
};
static devclass_t versatile_scm_devclass;
EARLY_DRIVER_MODULE(versatile_scm, simplebus, versatile_scm_driver, versatile_scm_devclass, 0, 0,
BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2017 Oleksandr Tymoshenko <gonzo@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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Ben Gray.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY BEN GRAY ``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 BEN GRAY 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 _VERSATILE_SCM_H_
#define _VERSATILE_SCM_H_
#define SCM_PCICTL 0x44
#define SCM_CLCD 0x50
#define SCM_CLCD_CLCDID_SHIFT 0x08
#define SCM_CLCD_CLCDID_MASK 0x1f
#define SCM_CLCD_PWR3V5VSWITCH (1 << 4)
#define SCM_CLCD_VDDPOSSWITCH (1 << 3)
#define SCM_CLCD_NLCDIOON (1 << 2)
#define SCM_CLCD_LCD_MODE_MASK 0x03
int versatile_scm_reg_read_4(uint32_t reg, uint32_t *val);
int versatile_scm_reg_write_4(uint32_t reg, uint32_t val);
#endif /* _VERSATILE_SCM_H_ */

View File

@ -1,324 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo@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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include "pic_if.h"
#ifdef DEBUG
#define dprintf(fmt, args...) printf(fmt, ##args)
#else
#define dprintf(fmt, args...)
#endif
#define SIC_STATUS 0x00
#define SIC_RAWSTAT 0x04
#define SIC_ENABLE 0x08
#define SIC_ENSET 0x08
#define SIC_ENCLR 0x0C
#define SIC_SOFTINTSET 0x10
#define SIC_SOFTINTCLR 0x14
#define SIC_PICENABLE 0x20
#define SIC_PICENSET 0x20
#define SIC_PICENCLR 0x24
#define SIC_NIRQS 32
struct versatile_sic_irqsrc {
struct intr_irqsrc isrc;
u_int irq;
};
struct versatile_sic_softc {
device_t dev;
struct mtx mtx;
struct resource * mem_res;
struct resource * irq_res;
void *intrh;
struct versatile_sic_irqsrc isrcs[SIC_NIRQS];
};
#define SIC_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx)
#define SIC_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx)
#define SIC_READ_4(sc, reg) \
bus_read_4(sc->mem_res, (reg))
#define SIC_WRITE_4(sc, reg, val) \
bus_write_4(sc->mem_res, (reg), (val))
/*
* Driver stuff
*/
static int versatile_sic_probe(device_t);
static int versatile_sic_attach(device_t);
static int versatile_sic_detach(device_t);
static void
versatile_sic_disable_intr(device_t dev, struct intr_irqsrc *isrc)
{
struct versatile_sic_softc *sc;
struct versatile_sic_irqsrc *src;
sc = device_get_softc(dev);
src = (struct versatile_sic_irqsrc *)isrc;
SIC_LOCK(sc);
SIC_WRITE_4(sc, SIC_ENCLR, (1 << src->irq));
SIC_UNLOCK(sc);
}
static void
versatile_sic_enable_intr(device_t dev, struct intr_irqsrc *isrc)
{
struct versatile_sic_softc *sc;
struct versatile_sic_irqsrc *src;
sc = device_get_softc(dev);
src = (struct versatile_sic_irqsrc *)isrc;
SIC_LOCK(sc);
SIC_WRITE_4(sc, SIC_ENSET, (1 << src->irq));
SIC_UNLOCK(sc);
}
static int
versatile_sic_map_intr(device_t dev, struct intr_map_data *data,
struct intr_irqsrc **isrcp)
{
struct intr_map_data_fdt *daf;
struct versatile_sic_softc *sc;
if (data->type != INTR_MAP_DATA_FDT)
return (ENOTSUP);
daf = (struct intr_map_data_fdt *)data;
if (daf->ncells != 1 || daf->cells[0] >= SIC_NIRQS)
return (EINVAL);
sc = device_get_softc(dev);
*isrcp = &sc->isrcs[daf->cells[0]].isrc;
return (0);
}
static void
versatile_sic_pre_ithread(device_t dev, struct intr_irqsrc *isrc)
{
versatile_sic_disable_intr(dev, isrc);
}
static void
versatile_sic_post_ithread(device_t dev, struct intr_irqsrc *isrc)
{
struct versatile_sic_irqsrc *src;
src = (struct versatile_sic_irqsrc *)isrc;
arm_irq_memory_barrier(src->irq);
versatile_sic_enable_intr(dev, isrc);
}
static void
versatile_sic_post_filter(device_t dev, struct intr_irqsrc *isrc)
{
struct versatile_sic_irqsrc *src;
src = (struct versatile_sic_irqsrc *)isrc;
arm_irq_memory_barrier(src->irq);
}
static int
versatile_sic_setup_intr(device_t dev, struct intr_irqsrc *isrc,
struct resource *res, struct intr_map_data *data)
{
return (0);
}
static int
versatile_sic_filter(void *arg)
{
struct versatile_sic_softc *sc;
struct intr_irqsrc *isrc;
uint32_t i, interrupts;
sc = arg;
SIC_LOCK(sc);
interrupts = SIC_READ_4(sc, SIC_STATUS);
SIC_UNLOCK(sc);
for (i = 0; interrupts != 0; i++, interrupts >>= 1) {
if ((interrupts & 0x1) == 0)
continue;
isrc = &sc->isrcs[i].isrc;
if (intr_isrc_dispatch(isrc, curthread->td_intr_frame) != 0) {
versatile_sic_disable_intr(sc->dev, isrc);
versatile_sic_post_filter(sc->dev, isrc);
device_printf(sc->dev, "Stray irq %u disabled\n", i);
}
}
return (FILTER_HANDLED);
}
static int
versatile_sic_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "arm,versatile-sic"))
return (ENXIO);
device_set_desc(dev, "ARM Versatile SIC");
return (BUS_PROBE_DEFAULT);
}
static int
versatile_sic_attach(device_t dev)
{
struct versatile_sic_softc *sc = device_get_softc(dev);
int rid, error;
uint32_t irq;
const char *name;
struct versatile_sic_irqsrc *isrcs;
sc->dev = dev;
mtx_init(&sc->mtx, device_get_nameunit(dev), "sic",
MTX_SPIN);
/* Request memory resources */
rid = 0;
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (sc->mem_res == NULL) {
device_printf(dev, "Error: could not allocate memory resources\n");
return (ENXIO);
}
/* Request memory resources */
rid = 0;
sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);
if (sc->irq_res == NULL) {
device_printf(dev, "could not allocate IRQ resources\n");
versatile_sic_detach(dev);
return (ENXIO);
}
if ((bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC,
versatile_sic_filter, NULL, sc, &sc->intrh))) {
device_printf(dev,
"unable to register interrupt handler\n");
versatile_sic_detach(dev);
return (ENXIO);
}
/* Disable all interrupts on SIC */
SIC_WRITE_4(sc, SIC_ENCLR, 0xffffffff);
/* PIC attachment */
isrcs = sc->isrcs;
name = device_get_nameunit(sc->dev);
for (irq = 0; irq < SIC_NIRQS; irq++) {
isrcs[irq].irq = irq;
error = intr_isrc_register(&isrcs[irq].isrc, sc->dev,
0, "%s,%u", name, irq);
if (error != 0)
return (error);
}
intr_pic_register(dev, OF_xref_from_node(ofw_bus_get_node(dev)));
return (0);
}
static int
versatile_sic_detach(device_t dev)
{
struct versatile_sic_softc *sc;
sc = device_get_softc(dev);
if (sc->intrh)
bus_teardown_intr(dev, sc->irq_res, sc->intrh);
if (sc->mem_res == NULL)
bus_release_resource(dev, SYS_RES_MEMORY,
rman_get_rid(sc->mem_res), sc->mem_res);
if (sc->irq_res == NULL)
bus_release_resource(dev, SYS_RES_IRQ,
rman_get_rid(sc->irq_res), sc->irq_res);
mtx_destroy(&sc->mtx);
return (0);
}
static device_method_t versatile_sic_methods[] = {
DEVMETHOD(device_probe, versatile_sic_probe),
DEVMETHOD(device_attach, versatile_sic_attach),
DEVMETHOD(device_detach, versatile_sic_detach),
DEVMETHOD(pic_disable_intr, versatile_sic_disable_intr),
DEVMETHOD(pic_enable_intr, versatile_sic_enable_intr),
DEVMETHOD(pic_map_intr, versatile_sic_map_intr),
DEVMETHOD(pic_post_filter, versatile_sic_post_filter),
DEVMETHOD(pic_post_ithread, versatile_sic_post_ithread),
DEVMETHOD(pic_pre_ithread, versatile_sic_pre_ithread),
DEVMETHOD(pic_setup_intr, versatile_sic_setup_intr),
DEVMETHOD_END
};
static driver_t versatile_sic_driver = {
"sic",
versatile_sic_methods,
sizeof(struct versatile_sic_softc),
};
static devclass_t versatile_sic_devclass;
DRIVER_MODULE(sic, simplebus, versatile_sic_driver, versatile_sic_devclass, 0, 0);