FreeBSD kernel amd64 PCI device code
pci_dw.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/devmap.h>
#include <sys/proc.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <machine/resource.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofwpci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcib_private.h>
#include <dev/pci/pci_dw.h>
#include "pcib_if.h"
#include "pci_dw_if.h"
Include dependency graph for pci_dw.c:

Go to the source code of this file.

Macros

#define debugf(fmt, args...)
 
#define DBI_WR1(sc, reg, val)   pci_dw_dbi_wr1((sc)->dev, reg, val)
 
#define DBI_WR2(sc, reg, val)   pci_dw_dbi_wr2((sc)->dev, reg, val)
 
#define DBI_WR4(sc, reg, val)   pci_dw_dbi_wr4((sc)->dev, reg, val)
 
#define DBI_RD1(sc, reg)   pci_dw_dbi_rd1((sc)->dev, reg)
 
#define DBI_RD2(sc, reg)   pci_dw_dbi_rd2((sc)->dev, reg)
 
#define DBI_RD4(sc, reg)   pci_dw_dbi_rd4((sc)->dev, reg)
 
#define IATU_UR_WR4(sc, reg, val)    bus_write_4((sc)->iatu_ur_res, (sc)->iatu_ur_offset + (reg), (val))
 
#define IATU_UR_RD4(sc, reg)    bus_read_4((sc)->iatu_ur_res, (sc)->iatu_ur_offset + (reg))
 
#define PCI_BUS_SHIFT   20
 
#define PCI_SLOT_SHIFT   15
 
#define PCI_FUNC_SHIFT   12
 
#define PCI_BUS_MASK   0xFF
 
#define PCI_SLOT_MASK   0x1F
 
#define PCI_FUNC_MASK   0x07
 
#define PCI_REG_MASK   0xFFF
 
#define IATU_CFG_BUS(bus)   ((uint64_t)((bus) & 0xff) << 24)
 
#define IATU_CFG_SLOT(slot)   ((uint64_t)((slot) & 0x1f) << 19)
 
#define IATU_CFG_FUNC(func)   ((uint64_t)((func) & 0x07) << 16)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static uint32_t pci_dw_dbi_read (device_t dev, u_int reg, int width)
 
static void pci_dw_dbi_write (device_t dev, u_int reg, uint32_t val, int width)
 
static void pci_dw_dbi_protect (struct pci_dw_softc *sc, bool protect)
 
static bool pci_dw_check_dev (struct pci_dw_softc *sc, u_int bus, u_int slot, u_int func, u_int reg)
 
static bool pci_dw_detect_atu_unroll (struct pci_dw_softc *sc)
 
static int pci_dw_detect_out_atu_regions_unroll (struct pci_dw_softc *sc)
 
static int pci_dw_detect_out_atu_regions_legacy (struct pci_dw_softc *sc)
 
static int pci_dw_detect_out_atu_regions (struct pci_dw_softc *sc)
 
static int pci_dw_map_out_atu_unroll (struct pci_dw_softc *sc, int idx, int type, uint64_t pa, uint64_t pci_addr, uint32_t size)
 
static int pci_dw_map_out_atu_legacy (struct pci_dw_softc *sc, int idx, int type, uint64_t pa, uint64_t pci_addr, uint32_t size)
 
static int pci_dw_map_out_atu (struct pci_dw_softc *sc, int idx, int type, uint64_t pa, uint64_t pci_addr, uint32_t size)
 
static int pci_dw_setup_hw (struct pci_dw_softc *sc)
 
static int pci_dw_decode_ranges (struct pci_dw_softc *sc, struct ofw_pci_range *ranges, int nranges)
 
static uint32_t pci_dw_read_config (device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes)
 
static void pci_dw_write_config (device_t dev, u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int bytes)
 
static int pci_dw_alloc_msi (device_t pci, device_t child, int count, int maxcount, int *irqs)
 
static int pci_dw_release_msi (device_t pci, device_t child, int count, int *irqs)
 
static int pci_dw_map_msi (device_t pci, device_t child, int irq, uint64_t *addr, uint32_t *data)
 
static int pci_dw_alloc_msix (device_t pci, device_t child, int *irq)
 
static int pci_dw_release_msix (device_t pci, device_t child, int irq)
 
static int pci_dw_get_id (device_t pci, device_t child, enum pci_id_type type, uintptr_t *id)
 
static bus_dma_tag_t pci_dw_get_dma_tag (device_t dev, device_t child)
 
int pci_dw_init (device_t dev)
 
 DEFINE_CLASS_1 (pcib, pci_dw_driver, pci_dw_methods, sizeof(struct pci_dw_softc), ofw_pcib_driver)
 

Variables

static device_method_t pci_dw_methods []
 

Macro Definition Documentation

◆ DBI_RD1

#define DBI_RD1 (   sc,
  reg 
)    pci_dw_dbi_rd1((sc)->dev, reg)

Definition at line 71 of file pci_dw.c.

◆ DBI_RD2

#define DBI_RD2 (   sc,
  reg 
)    pci_dw_dbi_rd2((sc)->dev, reg)

Definition at line 72 of file pci_dw.c.

◆ DBI_RD4

#define DBI_RD4 (   sc,
  reg 
)    pci_dw_dbi_rd4((sc)->dev, reg)

Definition at line 73 of file pci_dw.c.

◆ DBI_WR1

#define DBI_WR1 (   sc,
  reg,
  val 
)    pci_dw_dbi_wr1((sc)->dev, reg, val)

Definition at line 68 of file pci_dw.c.

◆ DBI_WR2

#define DBI_WR2 (   sc,
  reg,
  val 
)    pci_dw_dbi_wr2((sc)->dev, reg, val)

Definition at line 69 of file pci_dw.c.

◆ DBI_WR4

#define DBI_WR4 (   sc,
  reg,
  val 
)    pci_dw_dbi_wr4((sc)->dev, reg, val)

Definition at line 70 of file pci_dw.c.

◆ debugf

#define debugf (   fmt,
  args... 
)

Definition at line 65 of file pci_dw.c.

◆ IATU_CFG_BUS

#define IATU_CFG_BUS (   bus)    ((uint64_t)((bus) & 0xff) << 24)

Definition at line 88 of file pci_dw.c.

◆ IATU_CFG_FUNC

#define IATU_CFG_FUNC (   func)    ((uint64_t)((func) & 0x07) << 16)

Definition at line 90 of file pci_dw.c.

◆ IATU_CFG_SLOT

#define IATU_CFG_SLOT (   slot)    ((uint64_t)((slot) & 0x1f) << 19)

Definition at line 89 of file pci_dw.c.

◆ IATU_UR_RD4

#define IATU_UR_RD4 (   sc,
  reg 
)     bus_read_4((sc)->iatu_ur_res, (sc)->iatu_ur_offset + (reg))

Definition at line 77 of file pci_dw.c.

◆ IATU_UR_WR4

#define IATU_UR_WR4 (   sc,
  reg,
  val 
)     bus_write_4((sc)->iatu_ur_res, (sc)->iatu_ur_offset + (reg), (val))

Definition at line 75 of file pci_dw.c.

◆ PCI_BUS_MASK

#define PCI_BUS_MASK   0xFF

Definition at line 83 of file pci_dw.c.

◆ PCI_BUS_SHIFT

#define PCI_BUS_SHIFT   20

Definition at line 80 of file pci_dw.c.

◆ PCI_FUNC_MASK

#define PCI_FUNC_MASK   0x07

Definition at line 85 of file pci_dw.c.

◆ PCI_FUNC_SHIFT

#define PCI_FUNC_SHIFT   12

Definition at line 82 of file pci_dw.c.

◆ PCI_REG_MASK

#define PCI_REG_MASK   0xFFF

Definition at line 86 of file pci_dw.c.

◆ PCI_SLOT_MASK

#define PCI_SLOT_MASK   0x1F

Definition at line 84 of file pci_dw.c.

◆ PCI_SLOT_SHIFT

#define PCI_SLOT_SHIFT   15

Definition at line 81 of file pci_dw.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DEFINE_CLASS_1()

DEFINE_CLASS_1 ( pcib  ,
pci_dw_driver  ,
pci_dw_methods  ,
sizeof(struct pci_dw_softc ,
ofw_pcib_driver   
)

◆ pci_dw_alloc_msi()

static int pci_dw_alloc_msi ( device_t  pci,
device_t  child,
int  count,
int  maxcount,
int *  irqs 
)
static

Definition at line 599 of file pci_dw.c.

References child, count, irqs, maxcount, and pci.

◆ pci_dw_alloc_msix()

static int pci_dw_alloc_msix ( device_t  pci,
device_t  child,
int *  irq 
)
static

Definition at line 643 of file pci_dw.c.

References child, irq, and pci.

◆ pci_dw_check_dev()

static bool pci_dw_check_dev ( struct pci_dw_softc sc,
u_int  bus,
u_int  slot,
u_int  func,
u_int  reg 
)
static

Definition at line 151 of file pci_dw.c.

References bus, pci_dw_softc::bus_end, pci_dw_softc::bus_start, pci_dw_softc::dev, func, PCI_FUNCMAX, PCI_SLOTMAX, PCIE_REGMAX, reg, pci_dw_softc::root_bus, slot, and status.

Referenced by pci_dw_read_config(), and pci_dw_write_config().

Here is the caller graph for this function:

◆ pci_dw_dbi_protect()

static void pci_dw_dbi_protect ( struct pci_dw_softc sc,
bool  protect 
)
static

Definition at line 138 of file pci_dw.c.

References DBI_RD4, DBI_RO_WR_EN, DBI_WR4, DW_MISC_CONTROL_1, and reg.

Referenced by pci_dw_setup_hw().

Here is the caller graph for this function:

◆ pci_dw_dbi_read()

static uint32_t pci_dw_dbi_read ( device_t  dev,
u_int  reg,
int  width 
)
static

Definition at line 93 of file pci_dw.c.

References pci_dw_softc::dbi_res, pci_dw_softc::dev, dev, reg, and width.

◆ pci_dw_dbi_write()

static void pci_dw_dbi_write ( device_t  dev,
u_int  reg,
uint32_t  val,
int  width 
)
static

Definition at line 114 of file pci_dw.c.

References pci_dw_softc::dbi_res, pci_dw_softc::dev, dev, reg, val, and width.

◆ pci_dw_decode_ranges()

static int pci_dw_decode_ranges ( struct pci_dw_softc sc,
struct ofw_pci_range *  ranges,
int  nranges 
)
static

Definition at line 434 of file pci_dw.c.

References pci_dw_softc::dev, pci_dw_softc::io_range, pci_dw_softc::mem_ranges, and pci_dw_softc::num_mem_ranges.

Referenced by pci_dw_init().

Here is the caller graph for this function:

◆ pci_dw_detect_atu_unroll()

static bool pci_dw_detect_atu_unroll ( struct pci_dw_softc sc)
static

Definition at line 176 of file pci_dw.c.

References DBI_RD4, and DW_IATU_VIEWPORT.

Referenced by pci_dw_init().

Here is the caller graph for this function:

◆ pci_dw_detect_out_atu_regions()

static int pci_dw_detect_out_atu_regions ( struct pci_dw_softc sc)
static

Definition at line 238 of file pci_dw.c.

References pci_dw_softc::iatu_ur_res, pci_dw_detect_out_atu_regions_legacy(), and pci_dw_detect_out_atu_regions_unroll().

Referenced by pci_dw_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_dw_detect_out_atu_regions_legacy()

static int pci_dw_detect_out_atu_regions_legacy ( struct pci_dw_softc sc)
static

Definition at line 203 of file pci_dw.c.

References DBI_RD4, DBI_WR4, pci_dw_softc::dev, DW_IATU_LWR_TARGET_ADDR, DW_IATU_VIEWPORT, IATU_REGION_INDEX, pci_dw_softc::num_out_regions, and reg.

Referenced by pci_dw_detect_out_atu_regions().

Here is the caller graph for this function:

◆ pci_dw_detect_out_atu_regions_unroll()

static int pci_dw_detect_out_atu_regions_unroll ( struct pci_dw_softc sc)
static

Definition at line 182 of file pci_dw.c.

References DW_IATU_UR_REG, DW_IATU_UR_STEP, IATU_UR_RD4, pci_dw_softc::iatu_ur_size, IATU_UR_WR4, pci_dw_softc::num_out_regions, and reg.

Referenced by pci_dw_detect_out_atu_regions().

Here is the caller graph for this function:

◆ pci_dw_get_dma_tag()

static bus_dma_tag_t pci_dw_get_dma_tag ( device_t  dev,
device_t  child 
)
static

Definition at line 696 of file pci_dw.c.

References dev, and pci_dw_softc::dmat.

◆ pci_dw_get_id()

static int pci_dw_get_id ( device_t  pci,
device_t  child,
enum pci_id_type  type,
uintptr_t *  id 
)
static

Definition at line 669 of file pci_dw.c.

References child, pci, PCI_ID_MSI, pcib_get_id, rid, and type.

◆ pci_dw_init()

◆ pci_dw_map_msi()

static int pci_dw_map_msi ( device_t  pci,
device_t  child,
int  irq,
uint64_t *  addr,
uint32_t *  data 
)
static

Definition at line 628 of file pci_dw.c.

References addr, child, data, irq, and pci.

◆ pci_dw_map_out_atu()

static int pci_dw_map_out_atu ( struct pci_dw_softc sc,
int  idx,
int  type,
uint64_t  pa,
uint64_t  pci_addr,
uint32_t  size 
)
static

Definition at line 318 of file pci_dw.c.

References pci_dw_softc::iatu_ur_res, pci_dw_map_out_atu_legacy(), pci_dw_map_out_atu_unroll(), and type.

Referenced by pci_dw_read_config(), pci_dw_setup_hw(), and pci_dw_write_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_dw_map_out_atu_legacy()

static int pci_dw_map_out_atu_legacy ( struct pci_dw_softc sc,
int  idx,
int  type,
uint64_t  pa,
uint64_t  pci_addr,
uint32_t  size 
)
static

◆ pci_dw_map_out_atu_unroll()

static int pci_dw_map_out_atu_unroll ( struct pci_dw_softc sc,
int  idx,
int  type,
uint64_t  pa,
uint64_t  pci_addr,
uint32_t  size 
)
static

Definition at line 247 of file pci_dw.c.

References pci_dw_softc::dev, DW_IATU_UR_REG, IATU_CTRL1_TYPE, IATU_CTRL2_REGION_EN, IATU_UR_RD4, IATU_UR_WR4, reg, and type.

Referenced by pci_dw_map_out_atu().

Here is the caller graph for this function:

◆ pci_dw_read_config()

static uint32_t pci_dw_read_config ( device_t  dev,
u_int  bus,
u_int  slot,
u_int  func,
u_int  reg,
int  bytes 
)
static

◆ pci_dw_release_msi()

static int pci_dw_release_msi ( device_t  pci,
device_t  child,
int  count,
int *  irqs 
)
static

Definition at line 615 of file pci_dw.c.

References child, count, irqs, and pci.

◆ pci_dw_release_msix()

static int pci_dw_release_msix ( device_t  pci,
device_t  child,
int  irq 
)
static

Definition at line 656 of file pci_dw.c.

References child, irq, and pci.

◆ pci_dw_setup_hw()

◆ pci_dw_write_config()

static void pci_dw_write_config ( device_t  dev,
u_int  bus,
u_int  slot,
u_int  func,
u_int  reg,
uint32_t  val,
int  bytes 
)
static

Variable Documentation

◆ pci_dw_methods

device_method_t pci_dw_methods[]
static
Initial value:
= {
DEVMETHOD(bus_get_dma_tag, pci_dw_get_dma_tag),
DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
DEVMETHOD_END
}
static int pci_dw_release_msi(device_t pci, device_t child, int count, int *irqs)
Definition: pci_dw.c:615
static void pci_dw_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int bytes)
Definition: pci_dw.c:555
static int pci_dw_alloc_msix(device_t pci, device_t child, int *irq)
Definition: pci_dw.c:643
static uint32_t pci_dw_dbi_read(device_t dev, u_int reg, int width)
Definition: pci_dw.c:93
static int pci_dw_alloc_msi(device_t pci, device_t child, int count, int maxcount, int *irqs)
Definition: pci_dw.c:599
static int pci_dw_release_msix(device_t pci, device_t child, int irq)
Definition: pci_dw.c:656
static uint32_t pci_dw_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes)
Definition: pci_dw.c:506
static bus_dma_tag_t pci_dw_get_dma_tag(device_t dev, device_t child)
Definition: pci_dw.c:696
static int pci_dw_get_id(device_t pci, device_t child, enum pci_id_type type, uintptr_t *id)
Definition: pci_dw.c:669
static int pci_dw_map_msi(device_t pci, device_t child, int irq, uint64_t *addr, uint32_t *data)
Definition: pci_dw.c:628
static void pci_dw_dbi_write(device_t dev, u_int reg, uint32_t val, int width)
Definition: pci_dw.c:114
static uint32_t pcib_read_config(device_t dev, u_int b, u_int s, u_int f, u_int reg, int width)
Definition: pci_pci.c:2698
int pcib_alloc_msix(device_t pcib, device_t dev, int *irq)
Definition: pci_pci.c:2797
int pcib_release_msix(device_t pcib, device_t dev, int irq)
Definition: pci_pci.c:2810
int pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs)
Definition: pci_pci.c:2773
int pcib_release_msi(device_t pcib, device_t dev, int count, int *irqs)
Definition: pci_pci.c:2787
int pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data)
Definition: pci_pci.c:2820
static void pcib_write_config(device_t dev, u_int b, u_int s, u_int f, u_int reg, uint32_t val, int width)
Definition: pci_pci.c:2721
DEFAULT pcib_get_id
Definition: pcib_if.m:187

Definition at line 835 of file pci_dw.c.