1264007Srstone/*
2264013Srstone * Copyright (c) 2014 Sandvine Inc.  All rights reserved.
3264007Srstone * All rights reserved.
4264007Srstone *
5264007Srstone * Redistribution and use in source and binary forms, with or without
6264007Srstone * modification, are permitted provided that the following conditions
7264007Srstone * are met:
8264007Srstone * 1. Redistributions of source code must retain the above copyright
9264007Srstone *    notice, this list of conditions and the following disclaimer.
10264007Srstone * 2. Redistributions in binary form must reproduce the above copyright
11264007Srstone *    notice, this list of conditions and the following disclaimer in the
12264007Srstone *    documentation and/or other materials provided with the distribution.
13264007Srstone *
14264007Srstone * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15264007Srstone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16264007Srstone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17264007Srstone * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18264007Srstone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19264007Srstone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20264007Srstone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21264007Srstone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22264007Srstone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23264007Srstone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24264007Srstone * SUCH DAMAGE.
25264007Srstone */
26264007Srstone
27264007Srstone#include <sys/cdefs.h>
28264007Srstone__FBSDID("$FreeBSD$");
29264007Srstone
30264007Srstone/*
31264007Srstone * Support functions for the PCI:PCI bridge driver.  This has to be in a
32264007Srstone * separate file because kernel configurations end up referencing the functions
33264007Srstone * here even when pci support is compiled out of the kernel.
34264007Srstone */
35264007Srstone
36264007Srstone#include <sys/param.h>
37264007Srstone#include <sys/bus.h>
38264007Srstone#include <sys/kernel.h>
39264007Srstone#include <sys/malloc.h>
40264007Srstone#include <sys/module.h>
41264007Srstone#include <sys/rman.h>
42264007Srstone#include <sys/sysctl.h>
43264007Srstone#include <sys/systm.h>
44264007Srstone
45264007Srstone#include <dev/pci/pcivar.h>
46264007Srstone#include <dev/pci/pcireg.h>
47264007Srstone#include <dev/pci/pcib_private.h>
48264007Srstone
49264007Srstone#include "pcib_if.h"
50264007Srstone
51264011Srstoneint
52264011Srstonepcib_maxfuncs(device_t dev)
53264011Srstone{
54264011Srstone	return (PCI_FUNCMAX);
55264011Srstone}
56264011Srstone
57299929Sandrewint
58299929Sandrewpcib_get_id(device_t pcib, device_t dev, enum pci_id_type type, uintptr_t *id)
59264007Srstone{
60264007Srstone	uint8_t bus, slot, func;
61264007Srstone
62299929Sandrew	if (type != PCI_ID_RID)
63299929Sandrew		return (ENXIO);
64299929Sandrew
65264007Srstone	bus = pci_get_bus(dev);
66264007Srstone	slot = pci_get_slot(dev);
67264007Srstone	func = pci_get_function(dev);
68264007Srstone
69299929Sandrew	*id = (PCI_RID(bus, slot, func));
70299929Sandrew	return (0);
71264007Srstone}
72264007Srstone
73279443Srstonevoid
74279443Srstonepcib_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot,
75279443Srstone    int *func)
76279443Srstone{
77279443Srstone
78279443Srstone	*bus = PCI_RID2BUS(rid);
79279443Srstone	*slot = PCI_RID2SLOT(rid);
80279443Srstone	*func = PCI_RID2FUNC(rid);
81279443Srstone}
82279443Srstone
83