Skip to content

Commit

Permalink
Merge 1496807 into 9ba83ec
Browse files Browse the repository at this point in the history
  • Loading branch information
fpgamatt committed Jan 19, 2024
2 parents 9ba83ec + 1496807 commit d8f6257
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
20 changes: 19 additions & 1 deletion binaries/opae.io/opae/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,24 @@ def chown_pci_sva(pci_addr, uid, gid):
os.chown(sva_bind_dev, uid, gid)


def vfio_init(pci_addr, new_owner='', force=False):
def enable_sriov(enable):
sriov = '/sys/module/vfio_pci/parameters/enable_sriov'
if not os.path.exists(sriov):
return False

LOG.info('Enabling SR-IOV for vfio-pci')
try:
with open(sriov, 'w') as outf:
outf.write('Y' if enable else 'N')
except OSError:
return False
return True


def vfio_init(pci_addr, new_owner='', force=False, **kwargs):
vid_did = pci.vid_did_for_address(pci_addr)
driver = get_bound_driver(pci_addr)
init_sriov = kwargs.get('enable_sriov')

msg = '(0x{:04x},0x{:04x}) at {}'.format(
int(vid_did[0], 16), int(vid_did[1], 16), pci_addr)
Expand Down Expand Up @@ -214,6 +229,9 @@ def vfio_init(pci_addr, new_owner='', force=False):
os.chmod(device, 0o660)
chown_pci_sva(pci_addr, user, group)

if init_sriov:
enable_sriov(True)


def vfio_release(pci_addr):
vid_did = pci.vid_did_for_address(pci_addr)
Expand Down
10 changes: 9 additions & 1 deletion binaries/opae.io/pymain.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,22 @@ class init_action(base_action):
init.add_argument('-d', '--device', dest='sdevice',
metavar='DEVICE', type=pci.pci_address,
help='the PCIe address of the FPGA device')
init.add_argument('-e', '--enable-sriov', action='store_true',
default=False,
help='enable SR-IOV during initialization')
init.add_argument('-f', '--force', action='store_true',
default=False,
help='force the driver to unbind, '
'even if saving the previous driver fails')
init.add_argument('user_group', nargs='?', default='root:root',
help='the user:group for assigning device permissions')
def execute(self, args):
if not self.device:
raise SystemExit('Need device for init.')
utils.vfio_init(self.device, args.user_group)
kw = {'enable_sriov': args.enable_sriov}
utils.vfio_init(self.device, args.user_group, force=args.force, **kw)
raise SystemExit(0)
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Jinja2==3.1.1
requests==2.31.0
docutils==0.14
pygments==2.15.0
sphinx==4.5.0
sphinx==5.0.0
sphinx-rtd-theme==1.0.0
sphinx_fontawesome==0.0.6
sphinx-markdown==1.0.2
Expand Down
2 changes: 2 additions & 0 deletions include/opae/cxx/core/shared_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class shared_buffer {
/** shared_buffer factory method - allocate a shared_buffer.
* @param[in] handle The handle used to allocate the buffer.
* @param[in] len The length in bytes of the requested buffer.
* @param[in] read_only Set to true for a read only buffer.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
Expand All @@ -74,6 +75,7 @@ class shared_buffer {
* @param[in] base The base of the pre-allocated memory.
* @param[in] len The size of the pre-allocated memory,
* which must be a multiple of the page size.
* @param[in] read_only Set to true for a read only buffer.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
Expand Down
4 changes: 2 additions & 2 deletions include/opae/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ fpga_result fpgaGetMetricsByName(fpga_handle handle,
* Retrieve metrics / sendor threshold information and values
*
* @param[in] handle Handle to previously opened fpga resource
* @param[inout] metrics_threshold pointer to array of metric thresholds
* @param[inout] metric_thresholds Pointer to array of metric thresholds
* user allocates threshold array memory
* Number of thresholds returns enumerated thresholds if user pass
* NULL metrics_thresholds
* @param[inout] num_thresholds number of thresholds
* @param[inout] num_thresholds Number of thresholds
*
*
* @returns FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not
Expand Down
1 change: 1 addition & 0 deletions include/opae/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ enum opae_vfio_buffer_flags {
* to ignore.
* @param[out] iova Optional pointer to receive the IOVA address
* for the buffer. Pass NULL to ignore.
* @param[in] flags Flags for allocation (e.g. OPAE_VFIO_BUF_PREALLOCATED).
* @returns Non-zero on error. Zero on success.
*
* Example
Expand Down

0 comments on commit d8f6257

Please sign in to comment.