11.6Sthorpej/* $NetBSD: mq200_pci.c,v 1.6 2023/12/20 14:50:02 thorpej Exp $ */ 21.1Stakemura 31.1Stakemura/*- 41.1Stakemura * Copyright (c) 2002 TAKEMURA Shin 51.1Stakemura * All rights reserved. 61.1Stakemura * 71.1Stakemura * Redistribution and use in source and binary forms, with or without 81.1Stakemura * modification, are permitted provided that the following conditions 91.1Stakemura * are met: 101.1Stakemura * 1. Redistributions of source code must retain the above copyright 111.1Stakemura * notice, this list of conditions and the following disclaimer. 121.1Stakemura * 2. Redistributions in binary form must reproduce the above copyright 131.1Stakemura * notice, this list of conditions and the following disclaimer in the 141.1Stakemura * documentation and/or other materials provided with the distribution. 151.1Stakemura * 3. The name of the author may not be used to endorse or promote products 161.1Stakemura * derived from this software without specific prior written permission. 171.1Stakemura * 181.1Stakemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 191.1Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201.1Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211.1Stakemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 221.1Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231.1Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241.1Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251.1Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261.1Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Stakemura * SUCH DAMAGE. 291.1Stakemura * 301.1Stakemura */ 311.1Stakemura 321.1Stakemura#include <sys/cdefs.h> 331.6Sthorpej__KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.6 2023/12/20 14:50:02 thorpej Exp $"); 341.1Stakemura 351.1Stakemura#include <sys/param.h> 361.1Stakemura#include <sys/systm.h> 371.1Stakemura#include <sys/kernel.h> 381.1Stakemura#include <sys/device.h> 391.1Stakemura 401.1Stakemura#include <dev/pci/pcireg.h> 411.1Stakemura#include <dev/pci/pcivar.h> 421.1Stakemura#include <dev/pci/pcidevs.h> 431.1Stakemura#include <dev/pci/pciio.h> 441.1Stakemura 451.1Stakemura#include <hpcmips/dev/mq200var.h> 461.1Stakemura 471.1Stakemurastruct mq200_pci_softc { 481.1Stakemura struct mq200_softc sc_mq200; 491.1Stakemura pci_chipset_tag_t sc_pc; 501.1Stakemura pcitag_t sc_pcitag; 511.1Stakemura}; 521.1Stakemura 531.5Schsint mq200_pci_match(device_t, cfdata_t, void *); 541.5Schsvoid mq200_pci_attach(device_t, device_t, void *); 551.1Stakemura 561.5SchsCFATTACH_DECL_NEW(mqvideo_pci, sizeof(struct mq200_pci_softc), 571.4Sthorpej mq200_pci_match, mq200_pci_attach, NULL, NULL); 581.1Stakemura 591.1Stakemuraint 601.5Schsmq200_pci_match(device_t parent, cfdata_t match, void *aux) 611.1Stakemura{ 621.1Stakemura struct pci_attach_args *pa = aux; 631.1Stakemura 641.1Stakemura /* check vendor id and product id */ 651.1Stakemura if (pa->pa_id != 661.1Stakemura PCI_ID_CODE(PCI_VENDOR_MEDIAQ, PCI_PRODUCT_MEDIAQ_MQ200)) 671.1Stakemura return (0); 681.1Stakemura 691.1Stakemura return (1); 701.1Stakemura} 711.1Stakemura 721.1Stakemuravoid 731.5Schsmq200_pci_attach(device_t parent, device_t self, void *aux) 741.1Stakemura{ 751.5Schs struct mq200_pci_softc *psc = device_private(self); 761.1Stakemura struct mq200_softc *sc = &psc->sc_mq200; 771.1Stakemura struct pci_attach_args *pa = aux; 781.1Stakemura int res; 791.1Stakemura 801.5Schs sc->sc_dev = self; 811.1Stakemura psc->sc_pc = pa->pa_pc; 821.1Stakemura psc->sc_pcitag = pa->pa_tag; 831.1Stakemura 841.1Stakemura /* check whether it is disabled by firmware */ 851.1Stakemura if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) & 861.1Stakemura PCI_COMMAND_MEM_ENABLE)) { 871.5Schs printf("%s: disabled\n", device_xname(sc->sc_dev)); 881.1Stakemura return; 891.1Stakemura } 901.1Stakemura 911.1Stakemura /* Base Address Register 0: base address of control registers */ 921.1Stakemura res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM, 931.1Stakemura 0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL); 941.1Stakemura if (res != 0) { 951.5Schs printf("%s: can't map registers\n", device_xname(sc->sc_dev)); 961.1Stakemura return; 971.1Stakemura } 981.1Stakemura 991.1Stakemura /* Base Address Register 1: base address of frame buffer */ 1001.1Stakemura res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4, 1011.1Stakemura PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL); 1021.1Stakemura if (res != 0) { 1031.5Schs printf("%s: can't map frame buffer\n", device_xname(sc->sc_dev)); 1041.1Stakemura return; 1051.1Stakemura } 1061.1Stakemura 1071.1Stakemura mq200_attach(sc); 1081.1Stakemura} 109