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/include/drivers/io_driver.h b/include/drivers/io_driver.h
index cc01d3b..f34c71d 100644
--- a/include/drivers/io_driver.h
+++ b/include/drivers/io_driver.h
@@ -39,7 +39,7 @@
 /* Generic IO entity structure,representing an accessible IO construct on the
  * device, such as a file */
 typedef struct io_entity {
-	io_dev_handle dev_handle;
+	struct io_dev_info *dev_handle;
 	uintptr_t info;
 } io_entity_t;
 
@@ -47,7 +47,7 @@
 /* Device info structure, providing device-specific functions and a means of
  * adding driver-specific state */
 typedef struct io_dev_info {
-	struct io_dev_funcs *funcs;
+	const struct io_dev_funcs *funcs;
 	uintptr_t info;
 } io_dev_info_t;
 
@@ -55,23 +55,23 @@
 /* Structure used to create a connection to a type of device */
 typedef struct io_dev_connector {
 	/* dev_open opens a connection to a particular device driver */
-	int (*dev_open)(void *spec, io_dev_info_t **dev_info);
+	int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info);
 } io_dev_connector_t;
 
 
 /* Structure to hold device driver function pointers */
 typedef struct io_dev_funcs {
 	io_type_t (*type)(void);
-	int (*open)(io_dev_info_t *dev_info, const void *spec,
+	int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
 			io_entity_t *entity);
 	int (*seek)(io_entity_t *entity, int mode, ssize_t offset);
 	int (*size)(io_entity_t *entity, size_t *length);
-	int (*read)(io_entity_t *entity, void *buffer, size_t length,
+	int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
 			size_t *length_read);
-	int (*write)(io_entity_t *entity, const void *buffer,
+	int (*write)(io_entity_t *entity, const uintptr_t buffer,
 			size_t length, size_t *length_written);
 	int (*close)(io_entity_t *entity);
-	int (*dev_init)(io_dev_info_t *dev_info, const void *init_params);
+	int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params);
 	int (*dev_close)(io_dev_info_t *dev_info);
 } io_dev_funcs_t;
 
@@ -79,7 +79,7 @@
 /* IO platform data - used to track devices registered for a specific
  * platform */
 typedef struct io_plat_data {
-	io_dev_info_t *devices[MAX_IO_DEVICES];
+	const io_dev_info_t *devices[MAX_IO_DEVICES];
 	unsigned int dev_count;
 } io_plat_data_t;
 
@@ -90,6 +90,6 @@
 void io_init(io_plat_data_t *data);
 
 /* Register a device driver */
-int io_register_device(io_dev_info_t *dev_info);
+int io_register_device(const io_dev_info_t *dev_info);
 
 #endif  /* __IO_DRIVER_H__ */
diff --git a/include/drivers/io_fip.h b/include/drivers/io_fip.h
index 212570d..90b2fd0 100644
--- a/include/drivers/io_fip.h
+++ b/include/drivers/io_fip.h
@@ -33,6 +33,6 @@
 
 struct io_dev_connector;
 
-int register_io_dev_fip(struct io_dev_connector **dev_con);
+int register_io_dev_fip(const struct io_dev_connector **dev_con);
 
 #endif /* __IO_FIP_H__ */
diff --git a/include/drivers/io_memmap.h b/include/drivers/io_memmap.h
index 0e59ecb..7ee60fe 100644
--- a/include/drivers/io_memmap.h
+++ b/include/drivers/io_memmap.h
@@ -33,6 +33,6 @@
 
 struct io_dev_connector;
 
-int register_io_dev_memmap(struct io_dev_connector **dev_con);
+int register_io_dev_memmap(const struct io_dev_connector **dev_con);
 
 #endif /* __IO_MEMMAP_H__ */
diff --git a/include/drivers/io_semihosting.h b/include/drivers/io_semihosting.h
index eab290a..8902a6f 100644
--- a/include/drivers/io_semihosting.h
+++ b/include/drivers/io_semihosting.h
@@ -33,6 +33,6 @@
 
 struct io_dev_connector;
 
-int register_io_dev_sh(struct io_dev_connector **dev_con);
+int register_io_dev_sh(const struct io_dev_connector **dev_con);
 
 #endif /* __IO_SH_H__ */
diff --git a/include/lib/io_storage.h b/include/lib/io_storage.h
index b6c5f9f..ae1158c 100644
--- a/include/lib/io_storage.h
+++ b/include/lib/io_storage.h
@@ -31,6 +31,7 @@
 #ifndef __IO_H__
 #define __IO_H__
 
+#include <stdint.h>
 #include <stdio.h> /* For ssize_t */
 
 
@@ -58,13 +59,6 @@
 /* Connector type, providing a means of identifying a device to open */
 struct io_dev_connector;
 
-/* Device handle, providing a client with access to a specific device */
-typedef struct io_dev_info *io_dev_handle;
-
-/* IO handle, providing a client with access to a specific source of data from
- * a device */
-typedef struct io_entity *io_handle;
-
 
 /* File specification - used to refer to data on a device supporting file-like
  * entities */
@@ -77,7 +71,7 @@
 /* Block specification - used to refer to data on a device supporting
  * block-like entities */
 typedef struct io_block_spec {
-	unsigned long offset;
+	size_t offset;
 	size_t length;
 } io_block_spec_t;
 
@@ -96,33 +90,35 @@
 
 
 /* Open a connection to a device */
-int io_dev_open(struct io_dev_connector *dev_con, void *dev_spec,
-		io_dev_handle *dev_handle);
+int io_dev_open(const struct io_dev_connector *dev_con,
+		const uintptr_t dev_spec,
+		uintptr_t *dev_handle);
 
 
 /* Initialise a device explicitly - to permit lazy initialisation or
  * re-initialisation */
-int io_dev_init(io_dev_handle dev_handle, const void *init_params);
+int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
 
 /* 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);
 
 
 /* Synchronous operations */
-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 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 io_size(io_handle handle, size_t *length);
+int io_size(uintptr_t handle, size_t *length);
 
-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 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 io_close(io_handle handle);
+int io_close(uintptr_t handle);
 
 
 #endif /* __IO_H__ */
diff --git a/include/lib/semihosting.h b/include/lib/semihosting.h
index 9d0b39f..b4eecc5 100644
--- a/include/lib/semihosting.h
+++ b/include/lib/semihosting.h
@@ -31,6 +31,7 @@
 #ifndef __SEMIHOSTING_H__
 #define __SEMIHOSTING_H__
 
+#include <stdint.h>
 #include <stdio.h> /* For ssize_t */
 
 
@@ -63,17 +64,17 @@
 long semihosting_connection_supported(void);
 long semihosting_file_open(const char *file_name, size_t mode);
 long semihosting_file_seek(long file_handle, ssize_t offset);
-long semihosting_file_read(long file_handle, size_t *length, void *buffer);
+long semihosting_file_read(long file_handle, size_t *length, uintptr_t buffer);
 long semihosting_file_write(long file_handle,
 			    size_t *length,
-			    const void *buffer);
+			    const uintptr_t buffer);
 long semihosting_file_close(long file_handle);
 long semihosting_file_length(long file_handle);
 long semihosting_system(char *command_line);
 long semihosting_get_flen(const char *file_name);
 long semihosting_download_file(const char *file_name,
 			       size_t buf_size,
-			       void *buf);
+			       uintptr_t buf);
 void semihosting_write_char(char character);
 void semihosting_write_string(char *string);
 char semihosting_read_char(void);