Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.24
      1  1.24       rin /* $NetBSD: pci_machdep.c,v 1.24 2019/08/09 08:04:16 rin Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.5       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5   1.3       cgd  * All rights reserved.
      6   1.1       cgd  *
      7   1.3       cgd  * Author: Chris G. Demetriou
      8  1.19      matt  *
      9   1.3       cgd  * Permission to use, copy, modify and distribute this software and
     10   1.3       cgd  * its documentation is hereby granted, provided that both the copyright
     11   1.3       cgd  * notice and this permission notice appear in all copies of the
     12   1.3       cgd  * software, derivative works or modified versions, and any portions
     13   1.3       cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.19      matt  *
     15  1.19      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.19      matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.3       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.19      matt  *
     19   1.3       cgd  * Carnegie Mellon requests users of this software to return to
     20   1.1       cgd  *
     21   1.3       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.3       cgd  *  School of Computer Science
     23   1.3       cgd  *  Carnegie Mellon University
     24   1.3       cgd  *  Pittsburgh PA 15213-3890
     25   1.3       cgd  *
     26   1.3       cgd  * any improvements or extensions that they make and grant Carnegie the
     27   1.3       cgd  * rights to redistribute these changes.
     28   1.1       cgd  */
     29   1.1       cgd 
     30   1.1       cgd /*
     31   1.1       cgd  * Machine-specific functions for PCI autoconfiguration.
     32   1.1       cgd  */
     33   1.9       cgd 
     34  1.10       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     35  1.10       cgd 
     36  1.24       rin __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.24 2019/08/09 08:04:16 rin Exp $");
     37   1.1       cgd 
     38   1.1       cgd #include <sys/types.h>
     39   1.1       cgd #include <sys/param.h>
     40   1.1       cgd #include <sys/time.h>
     41   1.1       cgd #include <sys/systm.h>
     42   1.1       cgd #include <sys/errno.h>
     43   1.1       cgd #include <sys/device.h>
     44  1.14       mrg 
     45   1.1       cgd #include <dev/isa/isavar.h>
     46   1.3       cgd #include <dev/pci/pcireg.h>
     47   1.1       cgd #include <dev/pci/pcivar.h>
     48   1.2       cgd #include <dev/pci/pcidevs.h>
     49   1.1       cgd 
     50   1.7       cgd #include "vga_pci.h"
     51   1.7       cgd #if NVGA_PCI
     52  1.13  drochner #include <dev/ic/mc6845reg.h>
     53  1.13  drochner #include <dev/ic/pcdisplayvar.h>
     54  1.12  drochner #include <dev/pci/vga_pcivar.h>
     55   1.3       cgd #endif
     56   1.3       cgd 
     57   1.2       cgd #include "tga.h"
     58   1.3       cgd #if NTGA
     59  1.12  drochner #include <dev/pci/tgavar.h>
     60   1.3       cgd #endif
     61   1.1       cgd 
     62  1.20   tsutsui #include <machine/rpb.h>
     63  1.20   tsutsui 
     64   1.1       cgd void
     65  1.17       dsl pci_display_console(bus_space_tag_t iot, bus_space_tag_t memt, pci_chipset_tag_t pc, int bus, int device, int function)
     66   1.1       cgd {
     67  1.23  uebayasi #if NVGA_PCI || NTGA
     68   1.4       cgd 	pcitag_t tag;
     69  1.24       rin 	pcireg_t id;
     70   1.4       cgd 	int match, nmatch;
     71  1.23  uebayasi #endif
     72  1.24       rin #if NVGA_PCI
     73  1.24       rin 	pcireg_t class;
     74  1.24       rin #endif
     75  1.16       dsl 	int (*fn)(bus_space_tag_t, bus_space_tag_t, pci_chipset_tag_t,
     76  1.16       dsl 	    int, int, int);
     77   1.1       cgd 
     78  1.23  uebayasi #if NVGA_PCI || NTGA
     79   1.4       cgd 	tag = pci_make_tag(pc, bus, device, function);
     80   1.4       cgd 	id = pci_conf_read(pc, tag, PCI_ID_REG);
     81   1.2       cgd 	if (id == 0 || id == 0xffffffff)
     82   1.2       cgd 		panic("pci_display_console: no device at %d/%d/%d",
     83   1.2       cgd 		    bus, device, function);
     84  1.24       rin #  if NVGA_PCI
     85   1.4       cgd 	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
     86  1.24       rin #  endif
     87   1.4       cgd 
     88  1.23  uebayasi 	match = 0;
     89  1.23  uebayasi #endif
     90   1.4       cgd 	fn = NULL;
     91   1.2       cgd 
     92   1.7       cgd #if NVGA_PCI
     93   1.7       cgd 	nmatch = DEVICE_IS_VGA_PCI(class, id);
     94   1.4       cgd 	if (nmatch > match) {
     95   1.4       cgd 		match = nmatch;
     96  1.12  drochner 		fn = vga_pci_cnattach;
     97   1.2       cgd 	}
     98   1.3       cgd #endif
     99   1.2       cgd #if NTGA
    100   1.4       cgd 	nmatch = DEVICE_IS_TGA(class, id);
    101  1.15     elric 	if (nmatch > match)
    102  1.15     elric 		nmatch = tga_cnmatch(iot, memt, pc, tag);
    103   1.4       cgd 	if (nmatch > match) {
    104   1.4       cgd 		match = nmatch;
    105  1.12  drochner 		fn = tga_cnattach;
    106   1.2       cgd 	}
    107   1.3       cgd #endif
    108   1.2       cgd 
    109   1.4       cgd 	if (fn != NULL)
    110   1.6       cgd 		(*fn)(iot, memt, pc, bus, device, function);
    111   1.4       cgd 	else
    112   1.4       cgd 		panic("pci_display_console: unconfigured device at %d/%d/%d",
    113   1.2       cgd 		    bus, device, function);
    114   1.1       cgd }
    115  1.20   tsutsui 
    116  1.20   tsutsui void
    117  1.20   tsutsui device_pci_register(device_t dev, void *aux)
    118  1.20   tsutsui {
    119  1.20   tsutsui 	struct pci_attach_args *pa = aux;
    120  1.20   tsutsui 	struct ctb *ctb;
    121  1.20   tsutsui 	prop_dictionary_t dict;
    122  1.20   tsutsui 
    123  1.20   tsutsui 	/* set properties for PCI framebuffers */
    124  1.20   tsutsui 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
    125  1.20   tsutsui 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
    126  1.20   tsutsui 	    ctb->ctb_term_type == CTB_GRAPHICS) {
    127  1.20   tsutsui 		/* XXX should consider multiple displays? */
    128  1.20   tsutsui 		dict = device_properties(dev);
    129  1.20   tsutsui 		prop_dictionary_set_bool(dict, "is_console", true);
    130  1.20   tsutsui 	}
    131  1.20   tsutsui }
    132