11.3Sandvar/* $NetBSD: gcscpcib_pci.c,v 1.3 2024/02/02 22:14:04 andvar Exp $ */ 21.1Sbouyer/* $OpenBSD: gcscpcib.c,v 1.6 2007/11/17 17:02:47 mbalmer Exp $ */ 31.1Sbouyer 41.1Sbouyer/* 51.1Sbouyer * Copyright (c) 2008 Yojiro UO <yuo@nui.org> 61.1Sbouyer * Copyright (c) 2007 Marc Balmer <mbalmer@openbsd.org> 71.1Sbouyer * Copyright (c) 2007 Michael Shalayeff 81.1Sbouyer * All rights reserved. 91.1Sbouyer * 101.1Sbouyer * Permission to use, copy, modify, and distribute this software for any 111.1Sbouyer * purpose with or without fee is hereby granted, provided that the above 121.1Sbouyer * copyright notice and this permission notice appear in all copies. 131.1Sbouyer * 141.1Sbouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 151.1Sbouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 161.1Sbouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 171.1Sbouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 181.1Sbouyer * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN 191.1Sbouyer * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 201.1Sbouyer * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 211.1Sbouyer */ 221.1Sbouyer 231.1Sbouyer/* 241.1Sbouyer * AMD CS5535/CS5536 series LPC bridge also containing timer, watchdog and GPIO. 251.3Sandvar * machine-dependent attachment. 261.1Sbouyer */ 271.1Sbouyer#include <sys/cdefs.h> 281.3Sandvar__KERNEL_RCSID(0, "$NetBSD: gcscpcib_pci.c,v 1.3 2024/02/02 22:14:04 andvar Exp $"); 291.1Sbouyer 301.1Sbouyer 311.1Sbouyer#include <sys/param.h> 321.1Sbouyer#include <sys/systm.h> 331.1Sbouyer#include <sys/device.h> 341.1Sbouyer#include <sys/gpio.h> 351.1Sbouyer#include <sys/timetc.h> 361.1Sbouyer#include <sys/wdog.h> 371.1Sbouyer 381.1Sbouyer#include <sys/bus.h> 391.1Sbouyer 401.1Sbouyer#include <dev/pci/pcireg.h> 411.1Sbouyer#include <dev/pci/pcivar.h> 421.1Sbouyer#include <dev/pci/pcidevs.h> 431.1Sbouyer 441.1Sbouyer#include <dev/gpio/gpiovar.h> 451.1Sbouyer#include <dev/sysmon/sysmonvar.h> 461.1Sbouyer#include <dev/ic/gcscpcibreg.h> 471.1Sbouyer#include <dev/ic/gcscpcibvar.h> 481.1Sbouyer 491.1Sbouyer#include <machine/cpufunc.h> 501.1Sbouyer#include <x86/pci/pcibvar.h> 511.1Sbouyer 521.1Sbouyerstruct gcscpcib_pci_softc { 531.1Sbouyer /* we call pcibattach() which assumes softc starts like this: */ 541.1Sbouyer struct pcib_softc sc_pcib; 551.1Sbouyer /* MI gcscpcib datas */ 561.1Sbouyer struct gcscpcib_softc sc_gcscpcib; 571.1Sbouyer}; 581.1Sbouyer 591.1Sbouyerstatic int gcscpcib_pci_match(device_t, cfdata_t, void *); 601.1Sbouyerstatic void gcscpcib_pci_attach(device_t, device_t, void *); 611.1Sbouyer 621.1SbouyerCFATTACH_DECL_NEW(gcscpcib_pci, sizeof(struct gcscpcib_pci_softc), 631.1Sbouyer gcscpcib_pci_match, gcscpcib_pci_attach, NULL, NULL); 641.1Sbouyer 651.1Sbouyer 661.1Sbouyerstatic int 671.1Sbouyergcscpcib_pci_match(device_t parent, cfdata_t match, void *aux) 681.1Sbouyer{ 691.1Sbouyer struct pci_attach_args *pa = aux; 701.1Sbouyer 711.1Sbouyer if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE || 721.1Sbouyer PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA) 731.1Sbouyer return 0; 741.1Sbouyer 751.1Sbouyer switch (PCI_PRODUCT(pa->pa_id)) { 761.1Sbouyer case PCI_PRODUCT_NS_CS5535_ISA: 771.1Sbouyer case PCI_PRODUCT_AMD_CS5536_PCIB: 781.1Sbouyer return 2; /* supersede pcib(4) */ 791.1Sbouyer } 801.1Sbouyer 811.1Sbouyer return 0; 821.1Sbouyer} 831.1Sbouyer 841.1Sbouyerstatic void 851.1Sbouyergcscpcib_pci_attach(device_t parent, device_t self, void *aux) 861.1Sbouyer{ 871.1Sbouyer struct gcscpcib_pci_softc *sc = device_private(self); 881.1Sbouyer struct pci_attach_args *pa = (struct pci_attach_args *)aux; 891.1Sbouyer 901.1Sbouyer sc->sc_pcib.sc_pc = pa->pa_pc; 911.1Sbouyer sc->sc_pcib.sc_tag = pa->pa_tag; 921.1Sbouyer /* Attach the PCI-ISA bridge at first */ 931.1Sbouyer pcibattach(parent, self, aux); 941.1Sbouyer /* then attach gcscpcib itself */ 951.2Sbouyer gcscpcib_attach(self, &sc->sc_gcscpcib, pa->pa_iot, 0); 961.1Sbouyer} 971.1Sbouyer 981.1Sbouyeruint64_t 991.1Sbouyergcsc_rdmsr(uint msr) 1001.1Sbouyer{ 1011.1Sbouyer return rdmsr(msr); 1021.1Sbouyer} 1031.1Sbouyer 1041.1Sbouyervoid 1051.1Sbouyergcsc_wrmsr(uint msr, uint64_t v) 1061.1Sbouyer{ 1071.1Sbouyer wrmsr(msr, v); 1081.1Sbouyer} 109