#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/extent.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <dev/cons.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <dev/pci/vga_pcivar.h>
#include "wsdisplay.h"
#if NWSDISPLAY > 0
#include <dev/wscons/wsdisplayvar.h>
#endif
#include "radeonfb.h"
extern int radeonfb_cnattach(bus_space_tag_t, bus_space_tag_t, pcitag_t, pcireg_t);
#include "sisfb.h"
extern int sisfb_cnattach(bus_space_tag_t, bus_space_tag_t, pcitag_t, pcireg_t);
#include "smfb.h"
extern int smfb_cnattach(bus_space_tag_t, bus_space_tag_t, pcitag_t, pcireg_t);
#include "vga.h"
#include "pckbc.h"
#if NPCKBC > 0
#include <dev/isa/isareg.h>
#include <dev/ic/i8042reg.h>
#include <dev/ic/pckbcvar.h>
#endif
#include "pckbd.h"
#include "ukbd.h"
#if NUKBD > 0
#include <dev/usb/ukbdvar.h>
#endif
#if NPCKBD > 0 || NUKBD > 0
#include <dev/wscons/wskbdvar.h>
#endif
cons_decl(ws);
#include <machine/pmon.h>
void
wscnprobe(struct consdev *cp)
{
pcitag_t tag;
pcireg_t id, class;
int maj, dev, bus, maxbus;
cp->cn_pri = CN_DEAD;
for (maj = 0; maj < nchrdev; maj++) {
if (cdevsw[maj].d_open == wsdisplayopen)
break;
}
if (maj == nchrdev) {
return;
}
if (loongson_ver >= 0x3a)
maxbus = 2;
else
maxbus = 1;
for (bus = 0; bus < maxbus; bus++) {
for (dev = 0; dev < 32; dev++) {
tag = pci_make_tag_early(bus, dev, 0);
id = pci_conf_read_early(tag, PCI_ID_REG);
if (id == 0 || PCI_VENDOR(id) == PCI_VENDOR_INVALID)
continue;
class = pci_conf_read_early(tag, PCI_CLASS_REG);
if (!DEVICE_IS_VGA_PCI(class) &&
!(PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_MISC))
continue;
cp->cn_dev = makedev(maj, 0);
cp->cn_pri = CN_MIDPRI;
return;
}
}
}
void
wscninit(struct consdev *cp)
{
static int initted;
pcitag_t tag;
pcireg_t id, class;
int dev, bus, maxbus, rc;
extern struct consdev pmoncons;
if (initted)
return;
initted = 1;
cn_tab = &pmoncons;
if (loongson_ver >= 0x3a)
maxbus = 2;
else
maxbus = 1;
for (bus = 0; bus < maxbus; bus++) {
for (dev = 0; dev < 32; dev++) {
tag = pci_make_tag_early(bus, dev, 0);
id = pci_conf_read_early(tag, PCI_ID_REG);
if (id == 0 || PCI_VENDOR(id) == PCI_VENDOR_INVALID)
continue;
class = pci_conf_read_early(tag, PCI_CLASS_REG);
if (!DEVICE_IS_VGA_PCI(class) &&
!(PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_MISC))
continue;
rc = ENXIO;
if (PCI_CLASS(class) == PCI_CLASS_DISPLAY) {
#if NRADEONFB > 0
if (rc != 0)
rc = radeonfb_cnattach(early_mem_t,
early_io_t, tag, id);
#endif
#if NSISFB > 0
if (rc != 0 && early_io_t != NULL)
rc = sisfb_cnattach(early_mem_t,
early_io_t, tag, id);
#endif
#if NSMFB > 0
if (rc != 0 && early_io_t != NULL)
rc = smfb_cnattach(early_mem_t,
early_io_t, tag, id);
#endif
}
#if NVGA > 0
if (rc != 0 && early_io_t != NULL) {
rc = vga_pci_cnattach(early_io_t,
early_mem_t, NULL, 0, dev, 0);
}
#endif
if (rc == 0)
goto setup_kbd;
}
}
cn_tab = cp;
return;
setup_kbd:
rc = ENXIO;
#if NPCKBC > 0
if (rc != 0 && early_io_t != NULL)
rc = pckbc_cnattach(early_io_t, IO_KBD, KBCMDP, 0);
#endif
#if NUKBD > 0
if (rc != 0)
rc = ukbd_cnattach();
#endif
cn_tab = cp;
}
void
wscnputc(dev_t dev, int i)
{
#if NWSDISPLAY > 0
wsdisplay_cnputc(dev, i);
#endif
}
int
wscngetc(dev_t dev)
{
#if NPCKBD > 0 || NUKBD > 0
int c;
wskbd_cnpollc(dev, 1);
c = wskbd_cngetc(dev);
wskbd_cnpollc(dev, 0);
return c;
#else
for (;;)
continue;
#endif
}
void
wscnpollc(dev_t dev, int on)
{
#if NPCKBD > 0 || NUKBD > 0
wskbd_cnpollc(dev, on);
#endif
}