Add basic AppHint support

AppHints are the basic configuration mechanism. On linux they can be
modified and read using debugfs, but Fuchsia doesn't have anything like
that yet. So we just set them all to their default values.

Change-Id: I66878d7ed3154ad43e44e66c0fdf9917eb8e6ad0
diff --git a/services/server/env/fuchsia/km_apphint.cc b/services/server/env/fuchsia/km_apphint.cc
index ef48dcc..7d09a96 100644
--- a/services/server/env/fuchsia/km_apphint.cc
+++ b/services/server/env/fuchsia/km_apphint.cc
@@ -29,10 +29,15 @@
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */ /**************************************************************************/
 
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "magma_util/macros.h"
+
 extern "C" {
 /* Common and SO layer */
 #include "img_defs.h"
-//#include "sofunc_pvr.h"
 
 /* for action device access */
 #include "pvrsrv.h"
@@ -42,77 +47,120 @@
 
 #include "km_apphint_defs.h"
 #include "km_apphint.h"
-}
 
-#define NOT_IMPLEMENTED() fprintf(stderr, "msd-img-rgx-mtk: Not implemented in %s:%s:%d\n", __func__, __FILE__, __LINE__);
+#include "htbuffer_sf.h"
+#include "htbuffer_types.h"
+}
 
 /*
 *******************************************************************************
- Public interface
+ Data types
 ******************************************************************************/
+union apphint_value {
+	IMG_UINT64 UINT64;
+	IMG_UINT32 UINT32;
+	bool BOOL;
+	const IMG_CHAR *STRING;
+};
+
+struct apphint_action
+{
+	union apphint_value stored;
+};
+
+/*
+ *******************************************************************************
+  Global state
+ ******************************************************************************/
+static struct apphint_state
+{
+	struct apphint_action val[APPHINT_ID_MAX];
+
+} apphint = {
+/* statically initialise default values to ensure that any module_params
+ * provided on the command line are not overwritten by defaults.
+ */
+	.val =
+		{
+#define UINT32Bitfield UINT32
+#define UINT32List UINT32
+#define X(a, b, c, d, e) { { .b = d } },
+			APPHINT_LIST_ALL
+#undef X
+#undef UINT32Bitfield
+#undef UINT32List
+		},
+};
+
+
+/*
+ *******************************************************************************
+  Public interface
+ ******************************************************************************/
 int
 pvr_apphint_init(void)
 {
-	NOT_IMPLEMENTED();
-	return -1;
+	return 0;
 }
 
 int
 pvr_apphint_device_register(PVRSRV_DEVICE_NODE *device)
 {
-	NOT_IMPLEMENTED();
-	return -1;
+	return 0;
 }
 
+
 void
 pvr_apphint_device_unregister(PVRSRV_DEVICE_NODE *device)
 {
-	NOT_IMPLEMENTED();
 }
 
 void
 pvr_apphint_deinit(void)
 {
-	NOT_IMPLEMENTED();
 }
 
 void
 pvr_apphint_dump_state(void)
 {
-	NOT_IMPLEMENTED();
 }
 
 int
-pvr_apphint_get_uint64(APPHINT_ID ue, IMG_UINT64 *pVal)
+pvr_apphint_get_uint64(APPHINT_ID apphint_id, IMG_UINT64 *pVal)
 {
-	NOT_IMPLEMENTED();
-	int error = -1;
-	return error;
+	DASSERT(apphint_id < APPHINT_ID_MAX);
+	*pVal = apphint.val[apphint_id].stored.UINT64;
+	return 0;
 }
 
 int
-pvr_apphint_get_uint32(APPHINT_ID ue, IMG_UINT32 *pVal)
+pvr_apphint_get_uint32(APPHINT_ID apphint_id, IMG_UINT32 *pVal)
 {
-	NOT_IMPLEMENTED();
-	int error = -1;
-	return error;
+	DASSERT(apphint_id < APPHINT_ID_MAX);
+	*pVal = apphint.val[apphint_id].stored.UINT32;
+	return 0;
 }
 
 int
-pvr_apphint_get_bool(APPHINT_ID ue, IMG_BOOL *pVal)
+pvr_apphint_get_bool(APPHINT_ID apphint_id, IMG_BOOL *pVal)
 {
-	NOT_IMPLEMENTED();
-	int error = -1;
-
-	return error;
+	DASSERT(apphint_id < APPHINT_ID_MAX);
+	*pVal = (IMG_BOOL)apphint.val[apphint_id].stored.BOOL;
+	return 0;
 }
 
 int
-pvr_apphint_get_string(APPHINT_ID ue, IMG_CHAR *pBuffer, size_t size)
+pvr_apphint_get_string(APPHINT_ID apphint_id, IMG_CHAR *pBuffer, size_t size)
 {
-	NOT_IMPLEMENTED();
-	int error = -1;
-
+	DASSERT(apphint_id < APPHINT_ID_MAX);
+	int error = -ERANGE;
+	if (apphint.val[apphint_id].stored.STRING)
+	{
+		if (strlcpy(pBuffer, apphint.val[apphint_id].stored.STRING, size) < size)
+		{
+			error = 0;
+		}
+	}
 	return error;
 }
 
@@ -124,7 +172,9 @@
 	const PVRSRV_DEVICE_NODE *device,
 	const void *private_data)
 {
-	NOT_IMPLEMENTED();
+	// AppHints can't be queryed (from outside the driver) or changed, so the callbacks aren't
+	// used.
+	// TODO(MA-589): Implement.
 }
 
 void
@@ -135,7 +185,9 @@
 	const PVRSRV_DEVICE_NODE *device,
 	const void *private_data)
 {
-	NOT_IMPLEMENTED();
+	// AppHints can't be queryed (from outside the driver) or changed, so the callbacks aren't
+	// used.
+	// TODO(MA-589): Implement.
 }
 
 void
@@ -146,7 +198,9 @@
 	const PVRSRV_DEVICE_NODE *device,
 	const void *private_data)
 {
-	NOT_IMPLEMENTED();
+	// AppHints can't be queryed (from outside the driver) or changed, so the callbacks aren't
+	// used.
+	// TODO(MA-589): Implement.
 }
 
 void
@@ -157,7 +211,9 @@
 	const PVRSRV_DEVICE_NODE *device,
 	const void *private_data)
 {
-	NOT_IMPLEMENTED();
+	// AppHints can't be queryed (from outside the driver) or changed, so the callbacks aren't
+	// used.
+	// TODO(MA-589): Implement.
 }
 
 /* EOF */