summaryrefslogtreecommitdiffstats
path: root/src/usr/devicefw/assoccontain.H
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-05-18 11:49:26 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-06-02 09:54:48 -0500
commit83e18669b6c2322c8eb5f8632ac823877d765e0d (patch)
tree780c62fbc578e5a3b6c362db40b84e468611dd13 /src/usr/devicefw/assoccontain.H
parent40d7b75141080adb8b42cc5ea058c91944e7621e (diff)
downloadblackbird-hostboot-83e18669b6c2322c8eb5f8632ac823877d765e0d.tar.gz
blackbird-hostboot-83e18669b6c2322c8eb5f8632ac823877d765e0d.zip
Device Framework support.
Change-Id: I133f58df309c7fc3a7faa261699eba66a6bae4be Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/98 Tested-by: Jenkins Server Reviewed-by: Thi N. Tran <thi@us.ibm.com> Reviewed-by: Andrew J. Geissler <andrewg@us.ibm.com>
Diffstat (limited to 'src/usr/devicefw/assoccontain.H')
-rw-r--r--src/usr/devicefw/assoccontain.H93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/usr/devicefw/assoccontain.H b/src/usr/devicefw/assoccontain.H
new file mode 100644
index 000000000..9786168e0
--- /dev/null
+++ b/src/usr/devicefw/assoccontain.H
@@ -0,0 +1,93 @@
+/** @file assoccontain.H
+ * @brief Provides a memory pool container for allocating blocks of
+ * associations for the device driver framework.
+ *
+ * This class exists because storing the information in a normal map or
+ * vector would be exceptionally big for the expected sparseness of the
+ * device driver associations.
+ */
+
+#ifndef __DEVICEFW_ASSOCCONTAIN_H
+#define __DEVICEFW_ASSOCCONTAIN_H
+
+#include <stdint.h>
+#include <builtins.h>
+
+namespace DeviceFW
+{
+ /** @struct AssociationData
+ * @brief Data about a particular association.
+ *
+ * Typically this is a offset (pointer) to another association and an
+ * optional flag for the associatior to use. This allows a user to
+ * construct a light-weight multi-dimensional sparse array.
+ *
+ * The purpose of the flag field is left to the user.
+ */
+ struct AssociationData
+ {
+ bool flag:1;
+ size_t offset:15;
+
+ AssociationData() : flag(false), offset(0) { };
+
+ AssociationData(bool i_flag, size_t i_off)
+ : flag(i_flag), offset(i_off) { };
+
+ } PACKED;
+
+ /** @class AssociationContainer
+ * @brief The memory pool container of AssociationData blocks.
+ *
+ * The typical usage of this will be to create a multi-dimensional sparse
+ * associative array (map). The first block allocated will be the first
+ * dimension of the array. Each AssociationData entry in the block is the
+ * offset of the block containing the AssociationData for the next
+ * dimension. At the lowest level this offset might be used as an offset
+ * into another container, such as an std::vector.
+ */
+ class AssociationContainer
+ {
+ public:
+ /**
+ * @brief Constructor for AssociationContainer.
+ *
+ * Initializes internal members to clean values.
+ */
+ AssociationContainer();
+
+ /**
+ * @brief Destructor for AssociationContainer.
+ *
+ * Releases memory associated with container. After this call
+ * all pointers previously obtained through operator[] are invalid.
+ */
+ ~AssociationContainer();
+
+ /**
+ * @brief Look up a particular association entry by offset.
+ * @return A pointer to the requested association block.
+ *
+ * @note Will return a NULL pointer if an invalid offset is given.
+ */
+ AssociationData* operator[](size_t) const;
+
+ /**
+ * @brief Allocate a new block into the pool.
+ * @return A offset to the newly allocated block.
+ *
+ * The blocks allocated will all be erased to 0's.
+ *
+ * @note This function can change the pointers previously
+ * returned by the operator[]. Treat this function
+ * as though all previous pointers are invalidated.
+ */
+ size_t allocate(size_t);
+
+ private:
+ AssociationData* iv_data;
+ size_t iv_size;
+ };
+};
+
+#endif
OpenPOWER on IntegriCloud