1*c7fb772bSthorpej /* $NetBSD: amdpcib.c,v 1.5 2021/08/07 16:19:07 thorpej Exp $ */
27e8be191Sxtraeme
37e8be191Sxtraeme /*
47e8be191Sxtraeme * Copyright (c) 2006 Nicolas Joly
57e8be191Sxtraeme * All rights reserved.
67e8be191Sxtraeme *
77e8be191Sxtraeme * Redistribution and use in source and binary forms, with or without
87e8be191Sxtraeme * modification, are permitted provided that the following conditions
97e8be191Sxtraeme * are met:
107e8be191Sxtraeme * 1. Redistributions of source code must retain the above copyright
117e8be191Sxtraeme * notice, this list of conditions and the following disclaimer.
127e8be191Sxtraeme * 2. Redistributions in binary form must reproduce the above copyright
137e8be191Sxtraeme * notice, this list of conditions and the following disclaimer in the
147e8be191Sxtraeme * documentation and/or other materials provided with the distribution.
157e8be191Sxtraeme * 3. The name of the author may not be used to endorse or promote products
167e8be191Sxtraeme * derived from this software without specific prior written permission.
177e8be191Sxtraeme *
187e8be191Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
197e8be191Sxtraeme * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
207e8be191Sxtraeme * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
217e8be191Sxtraeme * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
227e8be191Sxtraeme * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
237e8be191Sxtraeme * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
247e8be191Sxtraeme * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
257e8be191Sxtraeme * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
267e8be191Sxtraeme * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
277e8be191Sxtraeme * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
287e8be191Sxtraeme * POSSIBILITY OF SUCH DAMAGE.
297e8be191Sxtraeme */
307e8be191Sxtraeme
317e8be191Sxtraeme #include <sys/cdefs.h>
32*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: amdpcib.c,v 1.5 2021/08/07 16:19:07 thorpej Exp $");
337e8be191Sxtraeme
347e8be191Sxtraeme #include <sys/systm.h>
357e8be191Sxtraeme #include <sys/device.h>
367e8be191Sxtraeme
377e8be191Sxtraeme #include <dev/pci/pcivar.h>
387e8be191Sxtraeme #include <dev/pci/pcireg.h>
397e8be191Sxtraeme #include <dev/pci/pcidevs.h>
404956be1fSmartin #include "pcibvar.h"
417e8be191Sxtraeme
427e8be191Sxtraeme struct amdpcib_softc {
434956be1fSmartin /* we are calling pcibattach(), which assumes this starts like this: */
444956be1fSmartin struct pcib_softc sc_pcib;
457e8be191Sxtraeme bus_space_tag_t sc_memt;
467e8be191Sxtraeme bus_space_handle_t sc_memh;
477e8be191Sxtraeme };
487e8be191Sxtraeme
49409a4c53Sxtraeme static int amdpcib_match(device_t, cfdata_t, void *);
50409a4c53Sxtraeme static void amdpcib_attach(device_t, device_t, void *);
517e8be191Sxtraeme static int amdpcib_search(device_t, cfdata_t, const int *, void *);
527e8be191Sxtraeme
53409a4c53Sxtraeme CFATTACH_DECL_NEW(amdpcib, sizeof(struct amdpcib_softc), amdpcib_match,
547e8be191Sxtraeme amdpcib_attach, NULL, NULL);
557e8be191Sxtraeme
567e8be191Sxtraeme static int
amdpcib_match(device_t parent,cfdata_t match,void * aux)57409a4c53Sxtraeme amdpcib_match(device_t parent, cfdata_t match, void *aux)
587e8be191Sxtraeme {
597e8be191Sxtraeme struct pci_attach_args *pa = aux;
607e8be191Sxtraeme
617e8be191Sxtraeme if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD) &&
627e8be191Sxtraeme (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PBC8111_LPC))
637e8be191Sxtraeme return 2;
647e8be191Sxtraeme
657e8be191Sxtraeme return 0;
667e8be191Sxtraeme }
677e8be191Sxtraeme
687e8be191Sxtraeme static void
amdpcib_attach(device_t parent,device_t self,void * aux)69409a4c53Sxtraeme amdpcib_attach(device_t parent, device_t self, void *aux)
707e8be191Sxtraeme {
71409a4c53Sxtraeme struct pci_attach_args *pa = aux;
727e8be191Sxtraeme
737e8be191Sxtraeme pcibattach(parent, self, aux);
742685996bSthorpej
752685996bSthorpej config_search(self, pa,
76*c7fb772bSthorpej CFARGS(.search = amdpcib_search,
77*c7fb772bSthorpej .iattr = "amdpcib"));
787e8be191Sxtraeme }
797e8be191Sxtraeme
807e8be191Sxtraeme static int
amdpcib_search(device_t parent,cfdata_t cf,const int * locs,void * aux)817e8be191Sxtraeme amdpcib_search(device_t parent, cfdata_t cf, const int *locs, void *aux)
827e8be191Sxtraeme {
837e8be191Sxtraeme
842685996bSthorpej if (config_probe(parent, cf, aux))
852685996bSthorpej config_attach(parent, cf, aux, NULL,
86*c7fb772bSthorpej CFARGS(.locators = locs));
877e8be191Sxtraeme
887e8be191Sxtraeme return 0;
897e8be191Sxtraeme }
90