FreeBSD kernel amd64 PCI device code
pci_iov.c File Reference
#include <sys/cdefs.h>
#include "opt_bus.h"
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/fcntl.h>
#include <sys/ioccom.h>
#include <sys/iov.h>
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/pciio.h>
#include <sys/queue.h>
#include <sys/rman.h>
#include <sys/sysctl.h>
#include <machine/bus.h>
#include <machine/stdarg.h>
#include <sys/nv.h>
#include <sys/iov_schema.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pci_iov.h>
#include <dev/pci/pci_private.h>
#include <dev/pci/pci_iov_private.h>
#include <dev/pci/schema_private.h>
#include "pcib_if.h"
Include dependency graph for pci_iov.c:

Go to the source code of this file.

Macros

#define IOV_READ(d, r, w)    pci_read_config((d)->cfg.dev, (d)->cfg.iov->iov_pos + r, w)
 
#define IOV_WRITE(d, r, v, w)    pci_write_config((d)->cfg.dev, (d)->cfg.iov->iov_pos + r, v, w)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_SRIOV, "sr_iov", "PCI SR-IOV allocations")
 
 SYSCTL_DECL (_hw_pci)
 
 SYSCTL_ULONG (_hw_pci, OID_AUTO, iov_max_config, CTLFLAG_RWTUN, &pci_iov_max_config, 0, "Maximum allowed size of SR-IOV configuration.")
 
static nvlist_t * pci_iov_build_schema (nvlist_t **pf_schema, nvlist_t **vf_schema)
 
static void pci_iov_build_pf_schema (nvlist_t *schema, nvlist_t **driver_schema)
 
static void pci_iov_build_vf_schema (nvlist_t *schema, nvlist_t **driver_schema)
 
static int pci_iov_delete_iov_children (struct pci_devinfo *dinfo)
 
static nvlist_t * pci_iov_get_pf_subsystem_schema (void)
 
static nvlist_t * pci_iov_get_vf_subsystem_schema (void)
 
int pci_iov_attach_name (device_t dev, struct nvlist *pf_schema, struct nvlist *vf_schema, const char *fmt,...)
 
int pci_iov_attach_method (device_t bus, device_t dev, nvlist_t *pf_schema, nvlist_t *vf_schema, const char *name)
 
int pci_iov_detach_method (device_t bus, device_t dev)
 
static int pci_iov_alloc_bar (struct pci_devinfo *dinfo, int bar, pci_addr_t bar_shift)
 
static void pci_iov_add_bars (struct pcicfg_iov *iov, struct pci_devinfo *dinfo)
 
static int pci_iov_parse_config (struct pcicfg_iov *iov, struct pci_iov_arg *arg, nvlist_t **ret)
 
static int pci_iov_set_ari (device_t bus)
 
static int pci_iov_config_page_size (struct pci_devinfo *dinfo)
 
static int pci_iov_init (device_t dev, uint16_t num_vfs, const nvlist_t *config)
 
static int pci_iov_init_rman (device_t pf, struct pcicfg_iov *iov)
 
static int pci_iov_alloc_bar_ea (struct pci_devinfo *dinfo, int bar)
 
static int pci_iov_setup_bars (struct pci_devinfo *dinfo)
 
static void pci_iov_enumerate_vfs (struct pci_devinfo *dinfo, const nvlist_t *config, uint16_t first_rid, uint16_t rid_stride)
 
static int pci_iov_config (struct cdev *cdev, struct pci_iov_arg *arg)
 
void pci_iov_cfg_restore (device_t dev, struct pci_devinfo *dinfo)
 
void pci_iov_cfg_save (device_t dev, struct pci_devinfo *dinfo)
 
static int pci_iov_is_child_vf (struct pcicfg_iov *pf, device_t child)
 
static int pci_iov_delete (struct cdev *cdev)
 
static int pci_iov_get_schema_ioctl (struct cdev *cdev, struct pci_iov_schema *output)
 
static int pci_iov_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
 
struct resource * pci_vf_alloc_mem_resource (device_t dev, device_t child, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
 
int pci_vf_release_mem_resource (device_t dev, device_t child, int rid, struct resource *r)
 

Variables

static d_ioctl_t pci_iov_ioctl
 
static struct cdevsw iov_cdevsw
 
static u_long pci_iov_max_config = 1024 * 1024
 

Macro Definition Documentation

◆ IOV_READ

#define IOV_READ (   d,
  r,
 
)     pci_read_config((d)->cfg.dev, (d)->cfg.iov->iov_pos + r, w)

Definition at line 86 of file pci_iov.c.

◆ IOV_WRITE

#define IOV_WRITE (   d,
  r,
  v,
 
)     pci_write_config((d)->cfg.dev, (d)->cfg.iov->iov_pos + r, v, w)

Definition at line 89 of file pci_iov.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_SRIOV  ,
"sr_iov"  ,
"PCI SR-IOV allocations"   
)
static

◆ pci_iov_add_bars()

static void pci_iov_add_bars ( struct pcicfg_iov iov,
struct pci_devinfo *  dinfo 
)
static

Definition at line 371 of file pci_iov.c.

References pci_iov_bar::bar_shift, pci_iov_bar::bar_size, pcicfg_iov::iov_bar, pci_add_bar(), PCIR_BAR, PCIR_MAX_BAR_0, and pci_iov_bar::res.

Referenced by pci_iov_enumerate_vfs().

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

◆ pci_iov_alloc_bar()

static int pci_iov_alloc_bar ( struct pci_devinfo *  dinfo,
int  bar,
pci_addr_t  bar_shift 
)
static

Definition at line 340 of file pci_iov.c.

References pci_iov_bar::bar_shift, pci_iov_bar::bar_size, bus, dev, pcicfg_iov::iov_bar, pcicfg_iov::iov_num_vfs, pcicfg_iov::iov_pos, pci_alloc_multi_resource(), PCIR_SRIOV_BAR, pci_iov_bar::res, rid, pcicfg_iov::rman, and start.

Referenced by pci_iov_setup_bars().

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

◆ pci_iov_alloc_bar_ea()

static int pci_iov_alloc_bar_ea ( struct pci_devinfo *  dinfo,
int  bar 
)
static

Definition at line 543 of file pci_iov.c.

References pci_iov_bar::bar_shift, pci_iov_bar::bar_size, pcicfg_iov::iov_bar, pcicfg_iov::iov_num_vfs, pcicfg_iov::iov_pos, pci_mapsize(), PCIR_SRIOV_BAR, pci_iov_bar::res, pcicfg_iov::rman, and start.

Referenced by pci_iov_setup_bars().

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

◆ pci_iov_attach_method()

int pci_iov_attach_method ( device_t  bus,
device_t  dev,
nvlist_t *  pf_schema,
nvlist_t *  vf_schema,
const char *  name 
)

◆ pci_iov_attach_name()

int pci_iov_attach_name ( device_t  dev,
struct nvlist *  pf_schema,
struct nvlist *  vf_schema,
const char *  fmt,
  ... 
)

Definition at line 103 of file pci_iov.c.

References dev, pf_schema, and vf_schema.

◆ pci_iov_build_pf_schema()

static void pci_iov_build_pf_schema ( nvlist_t *  schema,
nvlist_t **  driver_schema 
)
static

Definition at line 261 of file pci_iov.c.

References pcicfg_iov::iov_schema, pci_iov_get_pf_subsystem_schema(), pci_iov_schema_alloc_node(), and pf_schema.

Referenced by pci_iov_build_schema().

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

◆ pci_iov_build_schema()

static nvlist_t * pci_iov_build_schema ( nvlist_t **  pf_schema,
nvlist_t **  vf_schema 
)
static

Definition at line 231 of file pci_iov.c.

References pci_iov_build_pf_schema(), pci_iov_build_vf_schema(), pci_iov_schema_alloc_node(), and pf.

Referenced by pci_iov_attach_method().

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

◆ pci_iov_build_vf_schema()

static void pci_iov_build_vf_schema ( nvlist_t *  schema,
nvlist_t **  driver_schema 
)
static

Definition at line 286 of file pci_iov.c.

References pcicfg_iov::iov_schema, pci_iov_get_vf_subsystem_schema(), pci_iov_schema_alloc_node(), and vf_schema.

Referenced by pci_iov_build_schema().

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

◆ pci_iov_cfg_restore()

void pci_iov_cfg_restore ( device_t  dev,
struct pci_devinfo *  dinfo 
)

Definition at line 796 of file pci_iov.c.

References pcicfg_iov::iov_ctl, pcicfg_iov::iov_num_vfs, pcicfg_iov::iov_page_size, IOV_WRITE, PCIR_SRIOV_CTL, PCIR_SRIOV_NUM_VFS, and PCIR_SRIOV_PAGE_SIZE.

Referenced by pci_cfg_restore().

Here is the caller graph for this function:

◆ pci_iov_cfg_save()

void pci_iov_cfg_save ( device_t  dev,
struct pci_devinfo *  dinfo 
)

Definition at line 808 of file pci_iov.c.

References pcicfg_iov::iov_ctl, pcicfg_iov::iov_page_size, IOV_READ, PCIR_SRIOV_CTL, and PCIR_SRIOV_PAGE_SIZE.

Referenced by pci_cfg_save().

Here is the caller graph for this function:

◆ pci_iov_config()

◆ pci_iov_config_page_size()

static int pci_iov_config_page_size ( struct pci_devinfo *  dinfo)
static

Definition at line 489 of file pci_iov.c.

References IOV_READ, IOV_WRITE, PCI_SRIOV_BASE_PAGE_SHIFT, PCIR_SRIOV_PAGE_CAP, and PCIR_SRIOV_PAGE_SIZE.

Referenced by pci_iov_config().

Here is the caller graph for this function:

◆ pci_iov_delete()

static int pci_iov_delete ( struct cdev *  cdev)
static

Definition at line 908 of file pci_iov.c.

References IOV_BUSY, pcicfg_iov::iov_flags, pcicfg_iov::iov_num_vfs, and pci_iov_delete_iov_children().

Referenced by pci_iov_ioctl().

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

◆ pci_iov_delete_iov_children()

static int pci_iov_delete_iov_children ( struct pci_devinfo *  dinfo)
static

◆ pci_iov_detach_method()

int pci_iov_detach_method ( device_t  bus,
device_t  dev 
)

Definition at line 190 of file pci_iov.c.

References dev, IOV_BUSY, pcicfg_iov::iov_cdev, pcicfg_iov::iov_flags, pcicfg_iov::iov_schema, and pci_iov_delete_iov_children().

Here is the call graph for this function:

◆ pci_iov_enumerate_vfs()

static void pci_iov_enumerate_vfs ( struct pci_devinfo *  dinfo,
const nvlist_t *  config,
uint16_t  first_rid,
uint16_t  rid_stride 
)
static

Definition at line 622 of file pci_iov.c.

References bus, config, dev, did, pcicfg_iov::iov_num_vfs, IOV_READ, pci_iov_add_bars(), PCIR_SRIOV_VF_DID, and vid.

Referenced by pci_iov_config().

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

◆ pci_iov_get_pf_subsystem_schema()

static nvlist_t * pci_iov_get_pf_subsystem_schema ( void  )
static

Definition at line 311 of file pci_iov.c.

References pci_iov_schema_add_string(), pci_iov_schema_add_uint16(), pci_iov_schema_alloc_node(), and pf.

Referenced by pci_iov_build_pf_schema().

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

◆ pci_iov_get_schema_ioctl()

static int pci_iov_get_schema_ioctl ( struct cdev *  cdev,
struct pci_iov_schema *  output 
)
static

Definition at line 935 of file pci_iov.c.

Referenced by pci_iov_ioctl().

Here is the caller graph for this function:

◆ pci_iov_get_vf_subsystem_schema()

static nvlist_t * pci_iov_get_vf_subsystem_schema ( void  )
static

Definition at line 326 of file pci_iov.c.

References pci_iov_schema_add_bool(), and pci_iov_schema_alloc_node().

Referenced by pci_iov_build_vf_schema().

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

◆ pci_iov_init()

static int pci_iov_init ( device_t  dev,
uint16_t  num_vfs,
const nvlist_t *  config 
)
static

Definition at line 513 of file pci_iov.c.

References config, dev, and num_vfs.

Referenced by pci_iov_config().

Here is the caller graph for this function:

◆ pci_iov_init_rman()

static int pci_iov_init_rman ( device_t  pf,
struct pcicfg_iov iov 
)
static

Definition at line 523 of file pci_iov.c.

References pcicfg_iov::iov_flags, IOV_RMAN_INITED, pf, pcicfg_iov::rman, and pcicfg_iov::rman_name.

Referenced by pci_iov_config().

Here is the caller graph for this function:

◆ pci_iov_ioctl()

static int pci_iov_ioctl ( struct cdev *  dev,
u_long  cmd,
caddr_t  data,
int  fflag,
struct thread *  td 
)
static

Definition at line 980 of file pci_iov.c.

References data, dev, pci_iov_config(), pci_iov_delete(), and pci_iov_get_schema_ioctl().

Here is the call graph for this function:

◆ pci_iov_is_child_vf()

static int pci_iov_is_child_vf ( struct pcicfg_iov pf,
device_t  child 
)
static

Definition at line 820 of file pci_iov.c.

References child, PCICFG_VF, and pf.

Referenced by pci_iov_delete_iov_children().

Here is the caller graph for this function:

◆ pci_iov_parse_config()

static int pci_iov_parse_config ( struct pcicfg_iov iov,
struct pci_iov_arg *  arg,
nvlist_t **  ret 
)
static

Definition at line 390 of file pci_iov.c.

References config, pcicfg_iov::iov_schema, pci_iov_max_config, and pci_iov_schema_validate_config().

Referenced by pci_iov_config().

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

◆ pci_iov_set_ari()

static int pci_iov_set_ari ( device_t  bus)
static

Definition at line 440 of file pci_iov.c.

References bus, PCIM_SRIOV_ARI_EN, PCIR_SRIOV_CTL, and PCIZ_SRIOV.

Referenced by pci_iov_config().

Here is the caller graph for this function:

◆ pci_iov_setup_bars()

static int pci_iov_setup_bars ( struct pci_devinfo *  dinfo)
static

Definition at line 574 of file pci_iov.c.

References dev, pcicfg_iov::iov_pos, pci_add_resources_ea(), pci_ea_is_enabled(), pci_iov_alloc_bar(), pci_iov_alloc_bar_ea(), pci_mapsize(), pci_read_bar(), PCIR_MAX_BAR_0, and PCIR_SRIOV_BAR.

Referenced by pci_iov_config().

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

◆ pci_vf_alloc_mem_resource()

struct resource * pci_vf_alloc_mem_resource ( device_t  dev,
device_t  child,
int *  rid,
rman_res_t  start,
rman_res_t  end,
rman_res_t  count,
u_int  flags 
)

Definition at line 998 of file pci_iov.c.

References child, count, pci_find_bar(), pci_map::pm_size, pci_map::pm_value, rid, pcicfg_iov::rman, and start.

Referenced by pci_alloc_resource().

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

◆ pci_vf_release_mem_resource()

int pci_vf_release_mem_resource ( device_t  dev,
device_t  child,
int  rid,
struct resource *  r 
)

Definition at line 1061 of file pci_iov.c.

References child, and rid.

Referenced by pci_release_resource().

Here is the caller graph for this function:

◆ SYSCTL_DECL()

SYSCTL_DECL ( _hw_pci  )

◆ SYSCTL_ULONG()

SYSCTL_ULONG ( _hw_pci  ,
OID_AUTO  ,
iov_max_config  ,
CTLFLAG_RWTUN  ,
pci_iov_max_config,
,
"Maximum allowed size of SR-IOV configuration."   
)

Variable Documentation

◆ iov_cdevsw

struct cdevsw iov_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_name = "iov",
.d_ioctl = pci_iov_ioctl
}
static d_ioctl_t pci_iov_ioctl
Definition: pci_iov.c:67

Definition at line 69 of file pci_iov.c.

Referenced by pci_iov_attach_method().

◆ pci_iov_ioctl

d_ioctl_t pci_iov_ioctl
static

Definition at line 67 of file pci_iov.c.

◆ pci_iov_max_config

u_long pci_iov_max_config = 1024 * 1024
static

Definition at line 82 of file pci_iov.c.

Referenced by pci_iov_parse_config().