xref: /freebsd/sys/dev/pci/pcib_support.c (revision aea992e1)
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 __FBSDID("$FreeBSD$");
295605a99eSRyan Stone 
305605a99eSRyan Stone /*
315605a99eSRyan Stone  * Support functions for the PCI:PCI bridge driver.  This has to be in a
325605a99eSRyan Stone  * separate file because kernel configurations end up referencing the functions
335605a99eSRyan Stone  * here even when pci support is compiled out of the kernel.
345605a99eSRyan Stone  */
355605a99eSRyan Stone 
365605a99eSRyan Stone #include <sys/param.h>
375605a99eSRyan Stone #include <sys/bus.h>
385605a99eSRyan Stone #include <sys/kernel.h>
395605a99eSRyan Stone #include <sys/malloc.h>
405605a99eSRyan Stone #include <sys/module.h>
415605a99eSRyan Stone #include <sys/rman.h>
425605a99eSRyan Stone #include <sys/sysctl.h>
435605a99eSRyan Stone #include <sys/systm.h>
445605a99eSRyan Stone 
455605a99eSRyan Stone #include <dev/pci/pcivar.h>
465605a99eSRyan Stone #include <dev/pci/pcireg.h>
475605a99eSRyan Stone #include <dev/pci/pcib_private.h>
485605a99eSRyan Stone 
495605a99eSRyan Stone #include "pcib_if.h"
505605a99eSRyan Stone 
5155d3ea17SRyan Stone int
5255d3ea17SRyan Stone pcib_maxfuncs(device_t dev)
5355d3ea17SRyan Stone {
5455d3ea17SRyan Stone 	return (PCI_FUNCMAX);
5555d3ea17SRyan Stone }
5655d3ea17SRyan Stone 
575605a99eSRyan Stone uint16_t
585605a99eSRyan Stone pcib_get_rid(device_t pcib, device_t dev)
595605a99eSRyan Stone {
605605a99eSRyan Stone 	uint8_t bus, slot, func;
615605a99eSRyan Stone 
625605a99eSRyan Stone 	bus = pci_get_bus(dev);
635605a99eSRyan Stone 	slot = pci_get_slot(dev);
645605a99eSRyan Stone 	func = pci_get_function(dev);
655605a99eSRyan Stone 
665605a99eSRyan Stone 	return (PCI_RID(bus, slot, func));
675605a99eSRyan Stone }
685605a99eSRyan Stone 
69