2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-18 14:26:50 +00:00
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
2003-10-24 15:44:10 +00:00
|
|
|
* Copyright (C) 2003
|
|
|
|
* Hidetoshi Shimokawa. 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 Hidetoshi Shimokawa.
|
|
|
|
*
|
|
|
|
* 4. Neither the name of the author nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $Id: dcons_crom.c,v 1.8 2003/10/23 15:47:21 simokawa Exp $
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.
EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).
As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.
LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).
No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
|
|
|
#include <sys/eventhandler.h>
|
2003-10-24 15:44:10 +00:00
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2003-10-24 15:44:10 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
|
|
|
#include <dev/firewire/iec13213.h>
|
|
|
|
#include <dev/dcons/dcons.h>
|
2004-10-13 05:38:42 +00:00
|
|
|
#include <dev/dcons/dcons_os.h>
|
2003-10-24 15:44:10 +00:00
|
|
|
|
2004-02-16 07:25:46 +00:00
|
|
|
#include <sys/cons.h>
|
|
|
|
|
2015-01-21 19:53:52 +00:00
|
|
|
#if (defined(__i386__) || defined(__amd64__))
|
2007-06-08 04:33:25 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <machine/segments.h> /* for idt */
|
|
|
|
#endif
|
2015-01-21 19:53:52 +00:00
|
|
|
|
2003-10-24 15:44:10 +00:00
|
|
|
static bus_addr_t dcons_paddr;
|
|
|
|
|
2007-05-27 14:00:34 +00:00
|
|
|
static int force_console = 0;
|
2004-02-16 07:25:46 +00:00
|
|
|
TUNABLE_INT("hw.firewire.dcons_crom.force_console", &force_console);
|
2003-10-24 15:44:10 +00:00
|
|
|
|
|
|
|
#define ADDR_HI(x) (((x) >> 24) & 0xffffff)
|
|
|
|
#define ADDR_LO(x) ((x) & 0xffffff)
|
|
|
|
|
|
|
|
struct dcons_crom_softc {
|
|
|
|
struct firewire_dev_comm fd;
|
|
|
|
struct crom_chunk unit;
|
|
|
|
struct crom_chunk spec;
|
|
|
|
struct crom_chunk ver;
|
|
|
|
bus_dma_tag_t dma_tag;
|
|
|
|
bus_dmamap_t dma_map;
|
|
|
|
bus_addr_t bus_addr;
|
2007-06-08 00:54:44 +00:00
|
|
|
eventhandler_tag ehand;
|
2003-10-24 15:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
dcons_crom_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
BUS_ADD_CHILD(parent, 0, "dcons_crom", device_get_unit(parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dcons_crom_probe(device_t dev)
|
|
|
|
{
|
|
|
|
device_t pa;
|
|
|
|
|
|
|
|
pa = device_get_parent(dev);
|
|
|
|
if(device_get_unit(dev) != device_get_unit(pa)){
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_set_desc(dev, "dcons configuration ROM");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-01-21 19:53:52 +00:00
|
|
|
#if (defined(__i386__) || defined(__amd64__))
|
2007-06-08 04:33:25 +00:00
|
|
|
static void
|
|
|
|
dcons_crom_expose_idt(struct dcons_crom_softc *sc)
|
|
|
|
{
|
|
|
|
static off_t idt_paddr;
|
|
|
|
|
|
|
|
/* XXX */
|
i386 4/4G split.
The change makes the user and kernel address spaces on i386
independent, giving each almost the full 4G of usable virtual addresses
except for one PDE at top used for trampoline and per-CPU trampoline
stacks, and system structures that must be always mapped, namely IDT,
GDT, common TSS and LDT, and process-private TSS and LDT if allocated.
By using 1:1 mapping for the kernel text and data, it appeared
possible to eliminate assembler part of the locore.S which bootstraps
initial page table and KPTmap. The code is rewritten in C and moved
into the pmap_cold(). The comment in vmparam.h explains the KVA
layout.
There is no PCID mechanism available in protected mode, so each
kernel/user switch forth and back completely flushes the TLB, except
for the trampoline PTD region. The TLB invalidations for userspace
becomes trivial, because IPI handlers switch page tables. On the other
hand, context switches no longer need to reload %cr3.
copyout(9) was rewritten to use vm_fault_quick_hold(). An issue for
new copyout(9) is compatibility with wiring user buffers around sysctl
handlers. This explains two kind of locks for copyout ptes and
accounting of the vslock() calls. The vm_fault_quick_hold() AKA slow
path, is only tried after the 'fast path' failed, which temporary
changes mapping to the userspace and copies the data to/from small
per-cpu buffer in the trampoline. If a page fault occurs during the
copy, it is short-circuit by exception.s to not even reach C code.
The change was motivated by the need to implement the Meltdown
mitigation, but instead of KPTI the full split is done. The i386
architecture already shows the sizing problems, in particular, it is
impossible to link clang and lld with debugging. I expect that the
issues due to the virtual address space limits would only exaggerate
and the split gives more liveness to the platform.
Tested by: pho
Discussed with: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D14633
2018-04-13 20:30:49 +00:00
|
|
|
#ifdef __amd64__
|
2007-06-08 04:33:25 +00:00
|
|
|
idt_paddr = (char *)idt - (char *)KERNBASE;
|
i386 4/4G split.
The change makes the user and kernel address spaces on i386
independent, giving each almost the full 4G of usable virtual addresses
except for one PDE at top used for trampoline and per-CPU trampoline
stacks, and system structures that must be always mapped, namely IDT,
GDT, common TSS and LDT, and process-private TSS and LDT if allocated.
By using 1:1 mapping for the kernel text and data, it appeared
possible to eliminate assembler part of the locore.S which bootstraps
initial page table and KPTmap. The code is rewritten in C and moved
into the pmap_cold(). The comment in vmparam.h explains the KVA
layout.
There is no PCID mechanism available in protected mode, so each
kernel/user switch forth and back completely flushes the TLB, except
for the trampoline PTD region. The TLB invalidations for userspace
becomes trivial, because IPI handlers switch page tables. On the other
hand, context switches no longer need to reload %cr3.
copyout(9) was rewritten to use vm_fault_quick_hold(). An issue for
new copyout(9) is compatibility with wiring user buffers around sysctl
handlers. This explains two kind of locks for copyout ptes and
accounting of the vslock() calls. The vm_fault_quick_hold() AKA slow
path, is only tried after the 'fast path' failed, which temporary
changes mapping to the userspace and copies the data to/from small
per-cpu buffer in the trampoline. If a page fault occurs during the
copy, it is short-circuit by exception.s to not even reach C code.
The change was motivated by the need to implement the Meltdown
mitigation, but instead of KPTI the full split is done. The i386
architecture already shows the sizing problems, in particular, it is
impossible to link clang and lld with debugging. I expect that the
issues due to the virtual address space limits would only exaggerate
and the split gives more liveness to the platform.
Tested by: pho
Discussed with: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D14633
2018-04-13 20:30:49 +00:00
|
|
|
#else /* __i386__ */
|
|
|
|
idt_paddr = (off_t)pmap_kextract((vm_offset_t)idt);
|
|
|
|
#endif
|
2007-06-08 04:33:25 +00:00
|
|
|
|
|
|
|
crom_add_entry(&sc->unit, DCONS_CSR_KEY_RESET_HI, ADDR_HI(idt_paddr));
|
|
|
|
crom_add_entry(&sc->unit, DCONS_CSR_KEY_RESET_LO, ADDR_LO(idt_paddr));
|
|
|
|
}
|
|
|
|
#endif
|
2015-01-21 19:53:52 +00:00
|
|
|
|
2003-10-24 15:44:10 +00:00
|
|
|
static void
|
|
|
|
dcons_crom_post_busreset(void *arg)
|
|
|
|
{
|
|
|
|
struct dcons_crom_softc *sc;
|
|
|
|
struct crom_src *src;
|
|
|
|
struct crom_chunk *root;
|
|
|
|
|
|
|
|
sc = (struct dcons_crom_softc *) arg;
|
|
|
|
src = sc->fd.fc->crom_src;
|
|
|
|
root = sc->fd.fc->crom_root;
|
|
|
|
|
|
|
|
bzero(&sc->unit, sizeof(struct crom_chunk));
|
|
|
|
|
|
|
|
crom_add_chunk(src, root, &sc->unit, CROM_UDIR);
|
|
|
|
crom_add_entry(&sc->unit, CSRKEY_SPEC, CSRVAL_VENDOR_PRIVATE);
|
|
|
|
crom_add_simple_text(src, &sc->unit, &sc->spec, "FreeBSD");
|
|
|
|
crom_add_entry(&sc->unit, CSRKEY_VER, DCONS_CSR_VAL_VER);
|
|
|
|
crom_add_simple_text(src, &sc->unit, &sc->ver, "dcons");
|
|
|
|
crom_add_entry(&sc->unit, DCONS_CSR_KEY_HI, ADDR_HI(dcons_paddr));
|
|
|
|
crom_add_entry(&sc->unit, DCONS_CSR_KEY_LO, ADDR_LO(dcons_paddr));
|
2015-01-21 19:53:52 +00:00
|
|
|
#if (defined(__i386__) || defined(__amd64__))
|
2007-06-08 04:33:25 +00:00
|
|
|
dcons_crom_expose_idt(sc);
|
|
|
|
#endif
|
2003-10-24 15:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dmamap_cb(void *arg, bus_dma_segment_t *segments, int seg, int error)
|
|
|
|
{
|
2003-11-08 16:26:22 +00:00
|
|
|
struct dcons_crom_softc *sc;
|
2003-10-24 15:44:10 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
printf("dcons_dmamap_cb: error=%d\n", error);
|
|
|
|
|
2003-11-08 16:26:22 +00:00
|
|
|
sc = (struct dcons_crom_softc *)arg;
|
|
|
|
sc->bus_addr = segments[0].ds_addr;
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->dma_tag, sc->dma_map, BUS_DMASYNC_PREWRITE);
|
|
|
|
device_printf(sc->fd.dev,
|
|
|
|
"bus_addr 0x%jx\n", (uintmax_t)sc->bus_addr);
|
|
|
|
if (dcons_paddr != 0) {
|
|
|
|
/* XXX */
|
|
|
|
device_printf(sc->fd.dev, "dcons_paddr is already set\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-02-16 07:25:46 +00:00
|
|
|
dcons_conf->dma_tag = sc->dma_tag;
|
|
|
|
dcons_conf->dma_map = sc->dma_map;
|
2003-11-08 16:26:22 +00:00
|
|
|
dcons_paddr = sc->bus_addr;
|
2004-02-16 07:25:46 +00:00
|
|
|
|
|
|
|
/* Force to be the high-level console */
|
|
|
|
if (force_console)
|
|
|
|
cnselect(dcons_conf->cdev);
|
2003-10-24 15:44:10 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 00:54:44 +00:00
|
|
|
static void
|
|
|
|
dcons_crom_poll(void *p, int arg)
|
|
|
|
{
|
|
|
|
struct dcons_crom_softc *sc = (struct dcons_crom_softc *) p;
|
|
|
|
|
|
|
|
sc->fd.fc->poll(sc->fd.fc, -1, -1);
|
|
|
|
}
|
|
|
|
|
2003-10-24 15:44:10 +00:00
|
|
|
static int
|
|
|
|
dcons_crom_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct dcons_crom_softc *sc;
|
2009-01-07 21:25:44 +00:00
|
|
|
int error;
|
2003-10-24 15:44:10 +00:00
|
|
|
|
2009-01-07 21:25:44 +00:00
|
|
|
if (dcons_conf->buf == NULL)
|
|
|
|
return (ENXIO);
|
2003-10-24 15:44:10 +00:00
|
|
|
sc = (struct dcons_crom_softc *) device_get_softc(dev);
|
|
|
|
sc->fd.fc = device_get_ivars(dev);
|
|
|
|
sc->fd.dev = dev;
|
|
|
|
sc->fd.post_explore = NULL;
|
|
|
|
sc->fd.post_busreset = (void *) dcons_crom_post_busreset;
|
|
|
|
|
|
|
|
/* map dcons buffer */
|
2009-01-07 21:25:44 +00:00
|
|
|
error = bus_dma_tag_create(
|
2003-10-24 15:44:10 +00:00
|
|
|
/*parent*/ sc->fd.fc->dmat,
|
|
|
|
/*alignment*/ sizeof(u_int32_t),
|
|
|
|
/*boundary*/ 0,
|
|
|
|
/*lowaddr*/ BUS_SPACE_MAXADDR,
|
|
|
|
/*highaddr*/ BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
2004-02-16 07:25:46 +00:00
|
|
|
/*maxsize*/ dcons_conf->size,
|
2003-10-24 15:44:10 +00:00
|
|
|
/*nsegments*/ 1,
|
|
|
|
/*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/*flags*/ BUS_DMA_ALLOCNOW,
|
|
|
|
/*lockfunc*/busdma_lock_mutex,
|
|
|
|
/*lockarg*/&Giant,
|
|
|
|
&sc->dma_tag);
|
2009-01-07 21:25:44 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
error = bus_dmamap_create(sc->dma_tag, BUS_DMA_COHERENT, &sc->dma_map);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
error = bus_dmamap_load(sc->dma_tag, sc->dma_map,
|
2004-02-16 07:25:46 +00:00
|
|
|
(void *)dcons_conf->buf, dcons_conf->size,
|
2003-11-08 16:26:22 +00:00
|
|
|
dmamap_cb, sc, 0);
|
2009-01-07 21:25:44 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2007-06-08 00:54:44 +00:00
|
|
|
sc->ehand = EVENTHANDLER_REGISTER(dcons_poll, dcons_crom_poll,
|
|
|
|
(void *)sc, 0);
|
2003-10-24 15:44:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dcons_crom_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct dcons_crom_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct dcons_crom_softc *) device_get_softc(dev);
|
|
|
|
sc->fd.post_busreset = NULL;
|
|
|
|
|
2007-06-08 00:54:44 +00:00
|
|
|
if (sc->ehand)
|
|
|
|
EVENTHANDLER_DEREGISTER(dcons_poll, sc->ehand);
|
|
|
|
|
2003-10-24 15:44:10 +00:00
|
|
|
/* XXX */
|
2004-02-16 07:25:46 +00:00
|
|
|
if (dcons_conf->dma_tag == sc->dma_tag)
|
|
|
|
dcons_conf->dma_tag = NULL;
|
2003-10-24 15:44:10 +00:00
|
|
|
|
|
|
|
bus_dmamap_unload(sc->dma_tag, sc->dma_map);
|
|
|
|
bus_dmamap_destroy(sc->dma_tag, sc->dma_map);
|
|
|
|
bus_dma_tag_destroy(sc->dma_tag);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static devclass_t dcons_crom_devclass;
|
|
|
|
|
|
|
|
static device_method_t dcons_crom_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_identify, dcons_crom_identify),
|
|
|
|
DEVMETHOD(device_probe, dcons_crom_probe),
|
|
|
|
DEVMETHOD(device_attach, dcons_crom_attach),
|
|
|
|
DEVMETHOD(device_detach, dcons_crom_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t dcons_crom_driver = {
|
|
|
|
"dcons_crom",
|
|
|
|
dcons_crom_methods,
|
|
|
|
sizeof(struct dcons_crom_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(dcons_crom, firewire, dcons_crom_driver,
|
|
|
|
dcons_crom_devclass, 0, 0);
|
|
|
|
MODULE_VERSION(dcons_crom, 1);
|
|
|
|
MODULE_DEPEND(dcons_crom, dcons,
|
|
|
|
DCONS_VERSION, DCONS_VERSION, DCONS_VERSION);
|
|
|
|
MODULE_DEPEND(dcons_crom, firewire, 1, 1, 1);
|