/*
* Copyright (c) 2002, 2003 Valeriy E. Ushakov
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*/
/*
* Integraphics Systems IGA 168x and CyberPro series.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.25 2019/11/10 21:16:36 chs Exp $");
if (PCI_VENDOR(id) != PCI_VENDOR_INTEGRAPHICS)
return 0;
switch (PCI_PRODUCT(id)) {
case PCI_PRODUCT_INTEGRAPHICS_IGA1682: /* FALLTHROUGH */
case PCI_PRODUCT_INTEGRAPHICS_CYBERPRO2000: /* FALLTHROUGH */
case PCI_PRODUCT_INTEGRAPHICS_CYBERPRO2010:
return 1;
default:
return 0;
}
}
int
igsfb_pci_cnattach(bus_space_tag_t iot, bus_space_tag_t memt,
pci_chipset_tag_t pc,
int bus, int device, int function)
{
struct igsfb_devconfig *dc;
pcitag_t tag;
pcireg_t id;
int ret;
tag = pci_make_tag(pc, bus, device, function);
id = pci_conf_read(pc, tag, PCI_ID_REG);
if (igsfb_pci_match_by_id(id) == 0)
return 1;
dc = &igsfb_console_dc;
if (igsfb_pci_map_regs(dc, iot, memt, pc, tag, PCI_PRODUCT(id)) != 0)
return 1;
ret = igsfb_enable(dc->dc_iot, dc->dc_iobase, dc->dc_ioflags);
if (ret)
return ret;
ret = igsfb_cnattach_subr(dc);
if (ret)
return ret;
igsfb_pci_console = 1;
igsfb_pci_constag = tag;
return 0;
}
static int
igsfb_pci_is_console(pci_chipset_tag_t pc, pcitag_t tag)
{
#if defined(__sparc__) && !defined(KRUPS_FORCE_SERIAL_CONSOLE)
/* XXX: this doesn't belong here */
if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
{
int b, d, f;
/*
* Init memory and i/o bus space tags. Map device registers.
* Use memory space mapped i/o space access for i/o registers
* for CyberPro cards.
*/
static int
igsfb_pci_map_regs(struct igsfb_devconfig *dc,
bus_space_tag_t iot, bus_space_tag_t memt,
pci_chipset_tag_t pc, pcitag_t tag,
pci_product_id_t id)
{
dc->dc_id = id;
/*
* Configure memory space first since for CyberPro we use
* memory-mapped i/o access. Note that we are NOT mapping any
* of it yet. (XXX: search for memory BAR?)
*/
#define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
/*
* Configure I/O space. On CyberPro use MMIO. IGS 168x doesn't
* have a BAR for its i/o space, so we have to hardcode it.
*/
if (id >= PCI_PRODUCT_INTEGRAPHICS_CYBERPRO2000) {
dc->dc_iot = dc->dc_memt;
dc->dc_iobase = dc->dc_memaddr | IGS_MEM_MMIO_SELECT;
dc->dc_ioflags = dc->dc_memflags;
} else {
dc->dc_iot = iot;
dc->dc_iobase = 0;
dc->dc_ioflags = 0;
}
/*
* Map I/O registers. This is done in bus glue, not in common
* code because on e.g. ISA bus we'd need to access registers
* to obtain/program linear memory location.
*/
if (bus_space_map(dc->dc_iot,
dc->dc_iobase + IGS_REG_BASE, IGS_REG_SIZE,
dc->dc_ioflags,
&dc->dc_ioh) != 0)
{
printf("unable to map I/O registers\n");
return 1;
}