Blame opae-libs/include/opae/cxx/core/sysobject.h

Packit 534379
// Copyright(c) 2018, Intel Corporation
Packit 534379
//
Packit 534379
// Redistribution  and  use  in source  and  binary  forms,  with  or  without
Packit 534379
// modification, are permitted provided that the following conditions are met:
Packit 534379
//
Packit 534379
// * Redistributions of  source code  must retain the  above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer.
Packit 534379
// * Redistributions in binary form must reproduce the above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer in the documentation
Packit 534379
//   and/or other materials provided with the distribution.
Packit 534379
// * Neither the name  of Intel Corporation  nor the names of its contributors
Packit 534379
//   may be used to  endorse or promote  products derived  from this  software
Packit 534379
//   without specific prior written permission.
Packit 534379
//
Packit 534379
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 534379
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
Packit 534379
// IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 534379
// ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
Packit 534379
// LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
Packit 534379
// CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
Packit 534379
// SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
Packit 534379
// INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
Packit 534379
// CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
Packit 534379
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
Packit 534379
// POSSIBILITY OF SUCH DAMAGE.
Packit 534379
#pragma once
Packit 534379
#include <memory>
Packit 534379
#include <vector>
Packit 534379
Packit 534379
#include <opae/cxx/core/handle.h>
Packit 534379
#include <opae/cxx/core/token.h>
Packit 534379
#include <opae/types.h>
Packit 534379
Packit 534379
namespace opae {
Packit 534379
namespace fpga {
Packit 534379
namespace types {
Packit 534379
Packit 534379
/** Wraps the OPAE fpga_object primitive.
Packit 534379
 * sysobject's are created from a call to fpgaTokenGetObject,
Packit 534379
 * fpgaHandleGetObject, or fpgaObjectGetObject
Packit 534379
 */
Packit 534379
class sysobject {
Packit 534379
 public:
Packit 534379
  typedef std::shared_ptr<sysobject> ptr_t;
Packit 534379
Packit 534379
  sysobject() = delete;
Packit 534379
Packit 534379
  sysobject(const sysobject &o) = delete;
Packit 534379
Packit 534379
  sysobject &operator=(const sysobject &o) = delete;
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get a sysobject from a token. This will be read-only.
Packit 534379
   *
Packit 534379
   * @param[in] t Token object representing a resource.
Packit 534379
   * @param[in] name An identifier representing an object belonging to a
Packit 534379
   * resource represented by the token.
Packit 534379
   * @param[in] flags Control behavior of object identification and creation.
Packit 534379
   * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
   * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
   * created for objects one level down from the object identified by name.
Packit 534379
   * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all
Packit 534379
   * objects below the current object identified by name.
Packit 534379
   *
Packit 534379
   * @return A shared_ptr to a sysobject instance.
Packit 534379
   */
Packit 534379
  static sysobject::ptr_t get(token::ptr_t t, const std::string &name,
Packit 534379
                              int flags = 0);
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get a sysobject from a handle. This will be read-write.
Packit 534379
   *
Packit 534379
   * @param[in] h Handle object representing an open resource.
Packit 534379
   * @param[in] name An identifier representing an object belonging to a
Packit 534379
   * resource represented by the handle.
Packit 534379
   * @param[in] flags Control behavior of object identification and creation.
Packit 534379
   * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
   * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
   * created for objects one level down from the object identified by name.
Packit 534379
   * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all
Packit 534379
   * objects below the current object identified by name.
Packit 534379
   *
Packit 534379
   * @return A shared_ptr to a sysobject instance.
Packit 534379
   */
Packit 534379
  static sysobject::ptr_t get(handle::ptr_t h, const std::string &name,
Packit 534379
                              int flags = 0);
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get a sysobject from an object. This will be read-write if its
Packit 534379
   * parent was created from a handle..
Packit 534379
   *
Packit 534379
   * @param[in] name An identifier representing an object belonging to this
Packit 534379
   * object.
Packit 534379
   * @param[in] flags Control behavior of object identification and creation.
Packit 534379
   * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
   * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
   * created for objects one level down from the object identified by name.
Packit 534379
   * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all
Packit 534379
   * objects. Flags are defaulted to 0 meaning no flags.
Packit 534379
   *
Packit 534379
   * @return A shared_ptr to a sysobject instance.
Packit 534379
   */
Packit 534379
  sysobject::ptr_t get(const std::string &name, int flags = 0);
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get a sysobject from a container object. This will be read-write if
Packit 534379
   * its parent was created from a handle..
Packit 534379
   *
Packit 534379
   * @param[in] index An index number to get.
Packit 534379
   *
Packit 534379
   * @return A shared_ptr to a sysobject instance.
Packit 534379
   */
Packit 534379
  sysobject::ptr_t get(int index);
Packit 534379
Packit 534379
  virtual ~sysobject();
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get the size (in bytes) of the object.
Packit 534379
   *
Packit 534379
   * @return The number of bytes that the object occupies in memory.
Packit 534379
   */
Packit 534379
  uint32_t size() const;
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Read a 64-bit value from an FPGA object.
Packit 534379
   * The value is assumed to be in string format and will be parsed. See flags
Packit 534379
   * below for changing that behavior.
Packit 534379
   *
Packit 534379
   * @param[in] flags Flags that control how the object is read
Packit 534379
   * If FPGA_OBJECT_SYNC is used then object will update its buffered copy
Packit 534379
   * before retrieving the data. If FPGA_OBJECT_RAW is used, then the data
Packit 534379
   * will be read as raw bytes into the uint64_t pointer variable. Flags
Packit 534379
   * are defaulted to 0 meaning no flags.
Packit 534379
   *
Packit 534379
   * @return A 64-bit value from the object.
Packit 534379
   */
Packit 534379
  uint64_t read64(int flags = 0) const;
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Write 64-bit value to an FPGA object.
Packit 534379
   * The value will be converted to string before writing. See flags below for
Packit 534379
   * changing that behavior.
Packit 534379
   *
Packit 534379
   * @param[in] value The value to write to the object.
Packit 534379
   * @param[in] flags Flags that control how the object is written
Packit 534379
   * If FPGA_OBJECT_RAW is used, then the value will be written as raw bytes.
Packit 534379
   * Flags are defaulted to 0 meaning no flags.
Packit 534379
   *
Packit 534379
   * @note This operation will force a sync operation to update its cached
Packit 534379
   * buffer
Packit 534379
   */
Packit 534379
  void write64(uint64_t value, int flags = 0) const;
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get all raw bytes from the object.
Packit 534379
   *
Packit 534379
   * @param[in] flags Flags that control how object is read
Packit 534379
   * If FPGA_OBJECT_SYNC is used then object will update its buffered copy
Packit 534379
   * before retrieving the data.
Packit 534379
   *
Packit 534379
   * @return A vector of all bytes in the object.
Packit 534379
   */
Packit 534379
  std::vector<uint8_t> bytes(int flags = 0) const;
Packit 534379
Packit 534379
  /**
Packit 534379
   * @brief Get a subset of raw bytes from the object.
Packit 534379
   *
Packit 534379
   * @param[in] offset The bytes offset for the start of the returned vector.
Packit 534379
   * @param[in] size The number of bytes for the returned vector.
Packit 534379
   * @param[in] flags Flags that control how object is read
Packit 534379
   * If FPGA_OBJECT_SYNC is used then object will update its buffered copy
Packit 534379
   * before retrieving the data.
Packit 534379
   *
Packit 534379
   * @return A vector of size bytes in the object starting at offset.
Packit 534379
   */
Packit 534379
  std::vector<uint8_t> bytes(uint32_t offset, uint32_t size,
Packit 534379
                             int flags = 0) const;
Packit 534379
Packit 534379
  /** Get the object type (attribute or container)
Packit 534379
   */
Packit 534379
  enum fpga_sysobject_type type() const;
Packit 534379
Packit 534379
  /** Retrieve the underlying fpga_object primitive.
Packit 534379
   */
Packit 534379
  fpga_object c_type() const { return sysobject_; }
Packit 534379
Packit 534379
  /** Retrieve the underlying fpga_object primitive.
Packit 534379
   */
Packit 534379
  operator fpga_object() const { return sysobject_; }
Packit 534379
Packit 534379
 private:
Packit 534379
  sysobject(fpga_object sysobj, token::ptr_t token, handle::ptr_t hnd);
Packit 534379
  fpga_object sysobject_;
Packit 534379
  token::ptr_t token_;
Packit 534379
  handle::ptr_t handle_;
Packit 534379
};
Packit 534379
Packit 534379
}  // end of namespace types
Packit 534379
}  // end of namespace fpga
Packit 534379
}  // end of namespace opae