15605a99eSRyan Stone /*
2aea992e1SRyan Stone * Copyright (c) 2014 Sandvine Inc. All rights reserved.
35605a99eSRyan Stone * All rights reserved.
45605a99eSRyan Stone *
55605a99eSRyan Stone * Redistribution and use in source and binary forms, with or without
65605a99eSRyan Stone * modification, are permitted provided that the following conditions
75605a99eSRyan Stone * are met:
85605a99eSRyan Stone * 1. Redistributions of source code must retain the above copyright
95605a99eSRyan Stone * notice, this list of conditions and the following disclaimer.
105605a99eSRyan Stone * 2. Redistributions in binary form must reproduce the above copyright
115605a99eSRyan Stone * notice, this list of conditions and the following disclaimer in the
125605a99eSRyan Stone * documentation and/or other materials provided with the distribution.
135605a99eSRyan Stone *
145605a99eSRyan Stone * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
155605a99eSRyan Stone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
165605a99eSRyan Stone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
175605a99eSRyan Stone * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
185605a99eSRyan Stone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
195605a99eSRyan Stone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
205605a99eSRyan Stone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
215605a99eSRyan Stone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
225605a99eSRyan Stone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
235605a99eSRyan Stone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
245605a99eSRyan Stone * SUCH DAMAGE.
255605a99eSRyan Stone */
265605a99eSRyan Stone
275605a99eSRyan Stone #include <sys/cdefs.h>
285605a99eSRyan Stone /*
295605a99eSRyan Stone * Support functions for the PCI:PCI bridge driver. This has to be in a
305605a99eSRyan Stone * separate file because kernel configurations end up referencing the functions
315605a99eSRyan Stone * here even when pci support is compiled out of the kernel.
325605a99eSRyan Stone */
335605a99eSRyan Stone
345605a99eSRyan Stone #include <sys/param.h>
355605a99eSRyan Stone #include <sys/bus.h>
365605a99eSRyan Stone #include <sys/kernel.h>
375605a99eSRyan Stone #include <sys/malloc.h>
385605a99eSRyan Stone #include <sys/module.h>
395605a99eSRyan Stone #include <sys/rman.h>
405605a99eSRyan Stone #include <sys/sysctl.h>
415605a99eSRyan Stone #include <sys/systm.h>
425605a99eSRyan Stone
435605a99eSRyan Stone #include <dev/pci/pcivar.h>
445605a99eSRyan Stone #include <dev/pci/pcireg.h>
455605a99eSRyan Stone #include <dev/pci/pcib_private.h>
465605a99eSRyan Stone
475605a99eSRyan Stone #include "pcib_if.h"
485605a99eSRyan Stone
4955d3ea17SRyan Stone int
pcib_maxfuncs(device_t dev)5055d3ea17SRyan Stone pcib_maxfuncs(device_t dev)
5155d3ea17SRyan Stone {
5255d3ea17SRyan Stone return (PCI_FUNCMAX);
5355d3ea17SRyan Stone }
5455d3ea17SRyan Stone
55d7be980dSAndrew Turner int
pcib_get_id(device_t pcib,device_t dev,enum pci_id_type type,uintptr_t * id)56d7be980dSAndrew Turner pcib_get_id(device_t pcib, device_t dev, enum pci_id_type type, uintptr_t *id)
575605a99eSRyan Stone {
585605a99eSRyan Stone uint8_t bus, slot, func;
595605a99eSRyan Stone
60b7672a70SRuslan Bukin if (type == PCI_ID_OFW_IOMMU)
61b7672a70SRuslan Bukin return (PCI_GET_ID(device_get_parent(pcib), dev, type, id));
62b7672a70SRuslan Bukin
63d7be980dSAndrew Turner if (type != PCI_ID_RID)
64d7be980dSAndrew Turner return (ENXIO);
65d7be980dSAndrew Turner
665605a99eSRyan Stone bus = pci_get_bus(dev);
675605a99eSRyan Stone slot = pci_get_slot(dev);
685605a99eSRyan Stone func = pci_get_function(dev);
695605a99eSRyan Stone
70d7be980dSAndrew Turner *id = (PCI_RID(bus, slot, func));
71d7be980dSAndrew Turner return (0);
725605a99eSRyan Stone }
735605a99eSRyan Stone
742397d2d8SRyan Stone void
pcib_decode_rid(device_t pcib,uint16_t rid,int * bus,int * slot,int * func)752397d2d8SRyan Stone pcib_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot,
762397d2d8SRyan Stone int *func)
772397d2d8SRyan Stone {
782397d2d8SRyan Stone
792397d2d8SRyan Stone *bus = PCI_RID2BUS(rid);
802397d2d8SRyan Stone *slot = PCI_RID2SLOT(rid);
812397d2d8SRyan Stone *func = PCI_RID2FUNC(rid);
822397d2d8SRyan Stone }
83