1*eb488f67Smacallan /* $NetBSD: pci_machdep.c,v 1.25 2015/02/18 16:47:59 macallan Exp $ */
26c3d30d2Ssoren
36c3d30d2Ssoren /*
46c3d30d2Ssoren * Copyright (c) 2000 Soren S. Jorvang
56c3d30d2Ssoren * All rights reserved.
66c3d30d2Ssoren *
76c3d30d2Ssoren * Redistribution and use in source and binary forms, with or without
86c3d30d2Ssoren * modification, are permitted provided that the following conditions
96c3d30d2Ssoren * are met:
106c3d30d2Ssoren * 1. Redistributions of source code must retain the above copyright
116c3d30d2Ssoren * notice, this list of conditions and the following disclaimer.
126c3d30d2Ssoren * 2. Redistributions in binary form must reproduce the above copyright
136c3d30d2Ssoren * notice, this list of conditions and the following disclaimer in the
146c3d30d2Ssoren * documentation and/or other materials provided with the distribution.
156c3d30d2Ssoren * 3. All advertising materials mentioning features or use of this software
166c3d30d2Ssoren * must display the following acknowledgement:
176c3d30d2Ssoren * This product includes software developed for the
1807147999Skeihan * NetBSD Project. See http://www.NetBSD.org/ for
196c3d30d2Ssoren * information about NetBSD.
206c3d30d2Ssoren * 4. The name of the author may not be used to endorse or promote products
216c3d30d2Ssoren * derived from this software without specific prior written permission.
226c3d30d2Ssoren *
236c3d30d2Ssoren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
246c3d30d2Ssoren * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
256c3d30d2Ssoren * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
266c3d30d2Ssoren * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
276c3d30d2Ssoren * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
286c3d30d2Ssoren * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
296c3d30d2Ssoren * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
306c3d30d2Ssoren * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
316c3d30d2Ssoren * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
326c3d30d2Ssoren * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
336c3d30d2Ssoren */
346c3d30d2Ssoren
35ed517291Slukem #include <sys/cdefs.h>
36*eb488f67Smacallan __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.25 2015/02/18 16:47:59 macallan Exp $");
37936c3743Stsutsui
38936c3743Stsutsui #include "opt_pci.h"
39936c3743Stsutsui #include "pci.h"
40ed517291Slukem
416c3d30d2Ssoren #include <sys/types.h>
426c3d30d2Ssoren #include <sys/param.h>
436c3d30d2Ssoren #include <sys/time.h>
446c3d30d2Ssoren #include <sys/systm.h>
456c3d30d2Ssoren #include <sys/errno.h>
466c3d30d2Ssoren #include <sys/device.h>
476c3d30d2Ssoren
48fa00dc59Smrg #include <uvm/uvm_extern.h>
496c3d30d2Ssoren
50cf10107dSdyoung #include <sys/bus.h>
516c3d30d2Ssoren #include <machine/intr.h>
52f7544642Ssekiya #include <machine/sysconf.h>
536c3d30d2Ssoren
546c3d30d2Ssoren #include <dev/pci/pcivar.h>
556c3d30d2Ssoren #include <dev/pci/pcireg.h>
566c3d30d2Ssoren #include <dev/pci/pcidevs.h>
57aa71bc78Srumble #include <dev/pci/pciconf.h>
586c3d30d2Ssoren
59*eb488f67Smacallan struct mips_bus_dma_tag pci_bus_dma_tag;
606c3d30d2Ssoren
616c3d30d2Ssoren void
pci_attach_hook(device_t parent,device_t self,struct pcibus_attach_args * pba)62cbab9cadSchs pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
636c3d30d2Ssoren {
64aa71bc78Srumble /*
65aa71bc78Srumble * PCI doesn't have any special needs; just use
66aa71bc78Srumble * the generic versions of these functions as
67aa71bc78Srumble * established in sgimips_bus_dma_init().
68aa71bc78Srumble */
69aa71bc78Srumble pci_bus_dma_tag = sgimips_default_bus_dma_tag; /* struct copy */
70aa71bc78Srumble
716c3d30d2Ssoren /* XXX */
726c3d30d2Ssoren
736c3d30d2Ssoren return;
746c3d30d2Ssoren }
756c3d30d2Ssoren
766c3d30d2Ssoren int
pci_bus_maxdevs(pci_chipset_tag_t pc,int busno)77551d2b9aSsekiya pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
786c3d30d2Ssoren {
79d330e7b6Stsutsui
80aa71bc78Srumble return (*pc->pc_bus_maxdevs)(pc, busno);
816c3d30d2Ssoren }
826c3d30d2Ssoren
836c3d30d2Ssoren pcitag_t
pci_make_tag(pci_chipset_tag_t pc,int bus,int device,int function)84551d2b9aSsekiya pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
856c3d30d2Ssoren {
86d330e7b6Stsutsui
876c3d30d2Ssoren return (bus << 16) | (device << 11) | (function << 8);
886c3d30d2Ssoren }
896c3d30d2Ssoren
906c3d30d2Ssoren void
pci_decompose_tag(pci_chipset_tag_t pc,pcitag_t tag,int * bp,int * dp,int * fp)91551d2b9aSsekiya pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
926c3d30d2Ssoren {
93d330e7b6Stsutsui
946c3d30d2Ssoren if (bp != NULL)
956c3d30d2Ssoren *bp = (tag >> 16) & 0xff;
966c3d30d2Ssoren if (dp != NULL)
976c3d30d2Ssoren *dp = (tag >> 11) & 0x1f;
986c3d30d2Ssoren if (fp != NULL)
996c3d30d2Ssoren *fp = (tag >> 8) & 0x07;
1006c3d30d2Ssoren }
1016c3d30d2Ssoren
1026c3d30d2Ssoren pcireg_t
pci_conf_read(pci_chipset_tag_t pc,pcitag_t tag,int reg)103551d2b9aSsekiya pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
1046c3d30d2Ssoren {
105d330e7b6Stsutsui
1066c3d30d2Ssoren return (*pc->pc_conf_read)(pc, tag, reg);
1076c3d30d2Ssoren }
1086c3d30d2Ssoren
1096c3d30d2Ssoren void
pci_conf_write(pci_chipset_tag_t pc,pcitag_t tag,int reg,pcireg_t data)110551d2b9aSsekiya pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
1116c3d30d2Ssoren {
112d330e7b6Stsutsui
1136c3d30d2Ssoren (*pc->pc_conf_write)(pc, tag, reg, data);
1146c3d30d2Ssoren }
1156c3d30d2Ssoren
1166c3d30d2Ssoren int
pci_intr_map(const struct pci_attach_args * pa,pci_intr_handle_t * ihp)1173d764674Sdyoung pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
1186c3d30d2Ssoren {
119aa71bc78Srumble return (*pa->pa_pc->pc_intr_map)(pa, ihp);
1206c3d30d2Ssoren }
1216c3d30d2Ssoren
1226c3d30d2Ssoren const char *
pci_intr_string(pci_chipset_tag_t pc,pci_intr_handle_t ih,char * buf,size_t len)123e58a356cSchristos pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
124e58a356cSchristos size_t len)
1256c3d30d2Ssoren {
126e58a356cSchristos return (*pc->pc_intr_string)(pc, ih, buf, len);
1276c3d30d2Ssoren }
1286c3d30d2Ssoren
1296c3d30d2Ssoren const struct evcnt *
pci_intr_evcnt(pci_chipset_tag_t pc,pci_intr_handle_t ih)130551d2b9aSsekiya pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
1316c3d30d2Ssoren {
1326c3d30d2Ssoren
1336c3d30d2Ssoren /* XXX for now, no evcnt parent reported */
1346c3d30d2Ssoren return NULL;
1356c3d30d2Ssoren }
1366c3d30d2Ssoren
13748ced055Sad int
pci_intr_setattr(pci_chipset_tag_t pc,pci_intr_handle_t * ih,int attr,uint64_t data)13848ced055Sad pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
13948ced055Sad int attr, uint64_t data)
14048ced055Sad {
14148ced055Sad
14248ced055Sad switch (attr) {
14348ced055Sad case PCI_INTR_MPSAFE:
14448ced055Sad return 0;
14548ced055Sad default:
14648ced055Sad return ENODEV;
14748ced055Sad }
14848ced055Sad }
14948ced055Sad
1506c3d30d2Ssoren void *
pci_intr_establish(pci_chipset_tag_t pc,pci_intr_handle_t ih,int level,int (* func)(void *),void * arg)151551d2b9aSsekiya pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
152551d2b9aSsekiya int (*func)(void *), void *arg)
1536c3d30d2Ssoren {
154d330e7b6Stsutsui
155aa71bc78Srumble return (void *)(*pc->intr_establish)(ih, 0, func, arg);
1566c3d30d2Ssoren }
1576c3d30d2Ssoren
1586c3d30d2Ssoren void
pci_intr_disestablish(pci_chipset_tag_t pc,void * cookie)159551d2b9aSsekiya pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
1606c3d30d2Ssoren {
1616c3d30d2Ssoren
162aa71bc78Srumble (*pc->intr_disestablish)(cookie);
1636c3d30d2Ssoren }
164936c3743Stsutsui
165936c3743Stsutsui #ifdef PCI_NETBSD_CONFIGURE
166aa71bc78Srumble int
pci_conf_hook(pci_chipset_tag_t pc,int bus,int device,int function,pcireg_t id)167aa71bc78Srumble pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function,
168aa71bc78Srumble pcireg_t id)
169aa71bc78Srumble {
170aa71bc78Srumble
171aa71bc78Srumble if (pc->pc_conf_hook)
172aa71bc78Srumble return (*pc->pc_conf_hook)(pc, bus, device, function, id);
173aa71bc78Srumble else
174aa71bc78Srumble return (PCI_CONF_DEFAULT);
175aa71bc78Srumble }
176aa71bc78Srumble
177936c3743Stsutsui void
pci_conf_interrupt(pci_chipset_tag_t pc,int bus,int dev,int pin,int swiz,int * iline)178936c3743Stsutsui pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
179936c3743Stsutsui int *iline)
180936c3743Stsutsui {
181936c3743Stsutsui
182936c3743Stsutsui return;
183936c3743Stsutsui }
184936c3743Stsutsui #endif
185