Remove variables from .data section

Update code base to remove variables from the .data section,
mainly by using const static data where possible and adding
the const specifier as required. Most changes are to the IO
subsystem, including the framework APIs. The FVP power
management code is also affected.

Delay initialization of the global static variable,
next_image_type in bl31_main.c, until it is realy needed.
Doing this moves the variable from the .data to the .bss
section.

Also review the IO interface for inconsistencies, using
uintptr_t where possible instead of void *. Remove the
io_handle and io_dev_handle typedefs, which were
unnecessary, replacing instances with uintptr_t.

Fixes ARM-software/tf-issues#107.

Change-Id: I085a62197c82410b566e4698e5590063563ed304
diff --git a/lib/io_storage.c b/lib/io_storage.c
index 01ca1c6..204310a 100644
--- a/lib/io_storage.c
+++ b/lib/io_storage.c
@@ -64,9 +64,9 @@
 
 
 /* Return a boolean value indicating whether a device handle is valid */
-static int is_valid_dev(io_dev_handle handle)
+static int is_valid_dev(const uintptr_t dev_handle)
 {
-	const io_dev_info_t *dev = handle;
+	const io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
 	int result = (dev != NULL) && (dev->funcs != NULL) &&
 			(dev->funcs->type != NULL) &&
 			(dev->funcs->type() < IO_TYPE_MAX);
@@ -75,10 +75,11 @@
 
 
 /* Return a boolean value indicating whether an IO entity is valid */
-static int is_valid_entity(io_handle handle)
+static int is_valid_entity(const uintptr_t handle)
 {
-	const io_entity_t *entity = handle;
-	int result = (entity != NULL) && (is_valid_dev(entity->dev_handle));
+	const io_entity_t *entity = (io_entity_t *)handle;
+	int result = (entity != NULL) &&
+			(is_valid_dev((uintptr_t)entity->dev_handle));
 	return result;
 }
 
@@ -93,7 +94,7 @@
 
 
 /* Open a connection to a specific device */
-static int dev_open(const io_dev_connector_t *dev_con, void *dev_spec,
+static int dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
 		io_dev_info_t **dev_info)
 {
 	int result = IO_FAIL;
@@ -106,15 +107,15 @@
 
 
 /* Set a handle to track an entity */
-static void set_handle(io_handle *handle, io_entity_t *entity)
+static void set_handle(uintptr_t *handle, io_entity_t *entity)
 {
 	assert(handle != NULL);
-	*handle = entity;
+	*handle = (uintptr_t)entity;
 }
 
 
 /* Locate an entity in the pool, specified by address */
-static int find_first_entity(struct io_entity *entity, unsigned int *index_out)
+static int find_first_entity(const io_entity_t *entity, unsigned int *index_out)
 {
 	int result = IO_FAIL;
 	for (int index = 0; index < MAX_IO_HANDLES; ++index) {
@@ -129,7 +130,7 @@
 
 
 /* Allocate an entity from the pool and return a pointer to it */
-static int allocate_entity(struct io_entity **entity)
+static int allocate_entity(io_entity_t **entity)
 {
 	int result = IO_FAIL;
 	assert(entity != NULL);
@@ -148,7 +149,7 @@
 
 
 /* Release an entity back to the pool */
-static int free_entity(struct io_entity *entity)
+static int free_entity(const io_entity_t *entity)
 {
 	int result = IO_FAIL;
 	unsigned int index = 0;
@@ -168,7 +169,7 @@
 
 
 /* Initialise the IO layer */
-void io_init(struct io_plat_data *data)
+void io_init(io_plat_data_t *data)
 {
 	assert(data != NULL);
 	platform_data = data;
@@ -176,7 +177,7 @@
 
 
 /* Register a device driver */
-int io_register_device(struct io_dev_info *dev_info)
+int io_register_device(const io_dev_info_t *dev_info)
 {
 	int result = IO_FAIL;
 	assert(dev_info != NULL);
@@ -197,26 +198,26 @@
 
 
 /* Open a connection to an IO device */
-int io_dev_open(struct io_dev_connector *dev_con, void *dev_spec,
-		io_dev_handle *handle)
+int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
+		uintptr_t *handle)
 {
 	int result = IO_FAIL;
 	assert(handle != NULL);
 
-	result = dev_open(dev_con, dev_spec, handle);
+	result = dev_open(dev_con, dev_spec, (io_dev_info_t **)handle);
 	return result;
 }
 
 
 /* Initialise an IO device explicitly - to permit lazy initialisation or
  * re-initialisation */
-int io_dev_init(struct io_dev_info *dev_handle, const void *init_params)
+int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params)
 {
 	int result = IO_FAIL;
-	assert(dev_handle != NULL);
+	assert(dev_handle != (uintptr_t)NULL);
 	assert(is_valid_dev(dev_handle));
 
-	io_dev_info_t *dev = dev_handle;
+	io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
 
 	if (dev->funcs->dev_init != NULL) {
 		result = dev->funcs->dev_init(dev, init_params);
@@ -231,13 +232,13 @@
 /* TODO: Consider whether an explicit "shutdown" API should be included */
 
 /* Close a connection to a device */
-int io_dev_close(io_dev_handle dev_handle)
+int io_dev_close(uintptr_t dev_handle)
 {
 	int result = IO_FAIL;
-	assert(dev_handle != NULL);
+	assert(dev_handle != (uintptr_t)NULL);
 	assert(is_valid_dev(dev_handle));
 
-	io_dev_info_t *dev = dev_handle;
+	io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
 
 	if (dev->funcs->dev_close != NULL) {
 		result = dev->funcs->dev_close(dev);
@@ -254,13 +255,13 @@
 
 
 /* Open an IO entity */
-int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle)
+int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle)
 {
 	int result = IO_FAIL;
-	assert((spec != NULL) && (handle != NULL));
+	assert((spec != (uintptr_t)NULL) && (handle != NULL));
 	assert(is_valid_dev(dev_handle));
 
-	io_dev_info_t *dev = dev_handle;
+	io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
 	io_entity_t *entity;
 
 	result = allocate_entity(&entity);
@@ -270,7 +271,7 @@
 		result = dev->funcs->open(dev, spec, entity);
 
 		if (result == IO_SUCCESS) {
-			entity->dev_handle = dev_handle;
+			entity->dev_handle = dev;
 			set_handle(handle, entity);
 		} else
 			free_entity(entity);
@@ -280,12 +281,12 @@
 
 
 /* Seek to a specific position in an IO entity */
-int io_seek(io_handle handle, io_seek_mode_t mode, ssize_t offset)
+int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset)
 {
 	int result = IO_FAIL;
 	assert(is_valid_entity(handle) && is_valid_seek_mode(mode));
 
-	io_entity_t *entity = handle;
+	io_entity_t *entity = (io_entity_t *)handle;
 
 	io_dev_info_t *dev = entity->dev_handle;
 
@@ -299,12 +300,12 @@
 
 
 /* Determine the length of an IO entity */
-int io_size(io_handle handle, size_t *length)
+int io_size(uintptr_t handle, size_t *length)
 {
 	int result = IO_FAIL;
 	assert(is_valid_entity(handle) && (length != NULL));
 
-	io_entity_t *entity = handle;
+	io_entity_t *entity = (io_entity_t *)handle;
 
 	io_dev_info_t *dev = entity->dev_handle;
 
@@ -318,12 +319,15 @@
 
 
 /* Read data from an IO entity */
-int io_read(io_handle handle, void *buffer, size_t length, size_t *length_read)
+int io_read(uintptr_t handle,
+		uintptr_t buffer,
+		size_t length,
+		size_t *length_read)
 {
 	int result = IO_FAIL;
-	assert(is_valid_entity(handle) && (buffer != NULL));
+	assert(is_valid_entity(handle) && (buffer != (uintptr_t)NULL));
 
-	io_entity_t *entity = handle;
+	io_entity_t *entity = (io_entity_t *)handle;
 
 	io_dev_info_t *dev = entity->dev_handle;
 
@@ -337,13 +341,15 @@
 
 
 /* Write data to an IO entity */
-int io_write(io_handle handle, const void *buffer, size_t length,
+int io_write(uintptr_t handle,
+		const uintptr_t buffer,
+		size_t length,
 		size_t *length_written)
 {
 	int result = IO_FAIL;
-	assert(is_valid_entity(handle) && (buffer != NULL));
+	assert(is_valid_entity(handle) && (buffer != (uintptr_t)NULL));
 
-	io_entity_t *entity = handle;
+	io_entity_t *entity = (io_entity_t *)handle;
 
 	io_dev_info_t *dev = entity->dev_handle;
 
@@ -358,12 +364,12 @@
 
 
 /* Close an IO entity */
-int io_close(io_handle handle)
+int io_close(uintptr_t handle)
 {
 	int result = IO_FAIL;
 	assert(is_valid_entity(handle));
 
-	io_entity_t *entity = handle;
+	io_entity_t *entity = (io_entity_t *)handle;
 
 	io_dev_info_t *dev = entity->dev_handle;