/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Driver for DEC PixelStamp graphics adapters (PMAG-C).
*/
/*
* Allocate memory for the packet buffers. It must be located below
* 8MB, since the STIC can't access outside that region. Also, due
* to the holes in STIC address space, each buffer mustn't cross a
* 32kB boundary.
*/
if (bootstrap) {
/*
* UVM won't be initialised at this point, so grab memory
* directly from vm_physmem[].
*/
bva = (char *)uvm_pageboot_alloc(PX_BUF_SIZE + PX_BUF_ALIGN);
bpa = (STIC_KSEG_TO_PHYS(bva) + PX_BUF_ALIGN - 1) &
~(PX_BUF_ALIGN - 1);
if (bpa + PX_BUF_SIZE > 8192*1024)
panic("px_init: allocation out of bounds");
} else {
if (uvm_pglistalloc(PX_BUF_SIZE, 0, 8192*1024, PX_BUF_ALIGN,
0, &pglist, 1, 0) != 0)
panic("px_init: allocation failure");
bpa = VM_PAGE_TO_PHYS(TAILQ_FIRST(&pglist));
}
si = cookie;
px = device_private(si->si_dv);
sr = si->si_stic;
state = sr->sr_ipdvint;
sxc = si->si_sxc;
/*
* Vertical-retrace condition.
*
* Clear the flag and flush out any waiting VDAC updates. We do
* this at retrace time to avoid producing `shearing' and other
* nasty artifacts.
*/
if ((state & STIC_INT_V) != 0) {
sr->sr_ipdvint = STIC_INT_V_WE | STIC_INT_V_EN;
tc_wmb();
stic_flush(si);
}
/*
* Error condition.
*
* Simply clear the flag and report the error.
*/
if ((state & STIC_INT_E) != 0) {
aprint_error_dev(px->px_dev, "error intr, %x %x %x %x %x",
sr->sr_ipdvint, sr->sr_sticsr, sr->sr_buscsr,
sr->sr_busadr, sr->sr_busdat);
sr->sr_ipdvint = STIC_INT_E_WE | STIC_INT_E_EN;
tc_wmb();
}
/*
* Check for queue stalls.
*/
if (sxc->sxc_tail != sxc->sxc_head && !sxc->sxc_busy)
state |= STIC_INT_P;
/*
* Packet-done condition.
*
* If packet queueing is enabled, clear the condition, and increment
* the tail (submitted) pointer.
*/
if ((si->si_hwflags & PXF_QUEUE) != 0 && (state & STIC_INT_P) != 0) {
sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN;
tc_wmb();
static int
px_pbuf_post(struct stic_info *si, uint32_t *buf)
{
volatile uint32_t *poll, junk;
volatile struct stic_regs *sr;
u_long v;
int c;
sr = si->si_stic;
/* Get address of poll register for this buffer. */
v = (u_long)STIC_KSEG_TO_PHYS(buf);
v = ((v & 0xffff8000) << 3) | (v & 0x7fff);
poll = (volatile uint32_t *)((char *)si->si_slotbase + (v >> 9));
/*
* Read the poll register and make sure the stamp wants to accept
* our packet. This read will initiate the DMA. Don't wait for
* ever, just in case something's wrong.
*/
tc_mb();
for (c = STAMP_RETRIES; c != 0; c--) {
if ((sr->sr_ipdvint & STIC_INT_P) != 0) {
sr->sr_ipdvint = STIC_INT_P_WE;
tc_wmb();
junk = *poll;
__USE(junk);
return (0);
}
DELAY(STAMP_DELAY);
}
/* STIC has lost the plot, punish it. */
stic_reset(si);
return (-1);
}
static int
px_ioctl(struct stic_info *si, u_long cmd, void *data, int flag,
struct lwp *l)
{
volatile struct stic_xcomm *sxc;
volatile struct stic_regs *sr;
struct stic_xinfo *sxi;
int rv, s;