Patchwork efi_runtime: add UEFI runtime service QueryCapsuleCapabilities interface

login
register
mail settings
Submitter Ivan Hu
Date Jan. 28, 2013, 8:43 a.m.
Message ID <1359362621-9997-1-git-send-email-ivan.hu@canonical.com>
Download mbox | patch
Permalink /patch/216121/
State Accepted
Headers show

Comments

Ivan Hu - Jan. 28, 2013, 8:43 a.m.
Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 efi_runtime/efi_runtime.c |   21 +++++++++++++++++++++
 efi_runtime/efi_runtime.h |   24 ++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
Colin King - Jan. 28, 2013, 2:42 p.m.
On 28/01/13 08:43, Ivan Hu wrote:
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   efi_runtime/efi_runtime.c |   21 +++++++++++++++++++++
>   efi_runtime/efi_runtime.h |   24 ++++++++++++++++++++++++
>   2 files changed, 45 insertions(+)
>
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index 4c34f10..9440aae 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -121,6 +121,8 @@ static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
>
>   	struct efi_getnexthighmonotoniccount __user *pgetnexthighmonotoniccount;
>
> +	struct efi_querycapsulecapabilities __user *pquerycapsulecapabilities;
> +
>   	switch (cmd) {
>   	case EFI_RUNTIME_GET_VARIABLE:
>   		pgetvariable = (struct efi_getvariable __user *)arg;
> @@ -297,6 +299,25 @@ static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
>   			return -EINVAL;
>
>   		return 0;
> +
> +	case EFI_RUNTIME_QUERY_CAPSULECAPABILITIES:
> +
> +		pquerycapsulecapabilities = (struct
> +				efi_querycapsulecapabilities __user *)arg;
> +
> +		status = efi.query_capsule_caps(
> +				(efi_capsule_header_t **)
> +				pquerycapsulecapabilities->CapsuleHeaderArray,
> +				pquerycapsulecapabilities->CapsuleCount,
> +				pquerycapsulecapabilities->MaximumCapsuleSize,
> +				(int *)pquerycapsulecapabilities->ResetType);
> +
> +		if (put_user(status, pquerycapsulecapabilities->status))
> +			return -EFAULT;
> +		if (status != EFI_SUCCESS)
> +			return -EINVAL;
> +
> +		return 0;
>   	}
>
>   	return -ENOTTY;
> diff --git a/efi_runtime/efi_runtime.h b/efi_runtime/efi_runtime.h
> index ad62aa7..c516bba 100644
> --- a/efi_runtime/efi_runtime.h
> +++ b/efi_runtime/efi_runtime.h
> @@ -21,6 +21,12 @@
>   #ifndef _EFI_RUNTIME_H_
>   #define _EFI_RUNTIME_H_
>
> +typedef enum {
> +	EfiResetCold,
> +	EfiResetWarm,
> +	EfiResetShutdown
> +} EFI_RESET_TYPE;
> +
>   typedef struct {
>   	uint32_t	Data1;
>   	uint16_t	Data2;
> @@ -48,6 +54,13 @@ typedef struct {
>   	uint8_t		SetsToZero;
>   } __attribute__ ((packed)) EFI_TIME_CAPABILITIES;
>
> +typedef struct {
> +	EFI_GUID CapsuleGuid;
> +	uint32_t HeaderSize;
> +	uint32_t Flags;
> +	uint32_t CapsuleImageSize;
> +} __attribute__ ((packed)) EFI_CAPSULE_HEADER;
> +
>   struct efi_getvariable {
>   	uint16_t	*VariableName;
>   	EFI_GUID	*VendorGuid;
> @@ -110,6 +123,14 @@ struct efi_getnexthighmonotoniccount {
>   	uint64_t	*status;
>   } __attribute__ ((packed));
>
> +struct efi_querycapsulecapabilities {
> +	EFI_CAPSULE_HEADER	**CapsuleHeaderArray;
> +	uint64_t		CapsuleCount;
> +	uint64_t		*MaximumCapsuleSize;
> +	EFI_RESET_TYPE		*ResetType;
> +	uint64_t		*status;
> +} __attribute__ ((packed));
> +
>   /* ioctl calls that are permitted to the /dev/efi_runtime interface. */
>   #define EFI_RUNTIME_GET_VARIABLE \
>   	_IOWR('p', 0x01, struct efi_getvariable)
> @@ -135,4 +156,7 @@ struct efi_getnexthighmonotoniccount {
>   #define EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT \
>   	_IOR('p', 0x09, struct efi_getnexthighmonotoniccount)
>
> +#define EFI_RUNTIME_QUERY_CAPSULECAPABILITIES \
> +	_IOR('p', 0x0A, struct efi_querycapsulecapabilities)
> +
>   #endif /* _EFI_RUNTIME_H_ */
>
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung - Jan. 31, 2013, 9:31 a.m.
On 01/28/2013 04:43 PM, Ivan Hu wrote:
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   efi_runtime/efi_runtime.c |   21 +++++++++++++++++++++
>   efi_runtime/efi_runtime.h |   24 ++++++++++++++++++++++++
>   2 files changed, 45 insertions(+)
>
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index 4c34f10..9440aae 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -121,6 +121,8 @@ static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
>
>   	struct efi_getnexthighmonotoniccount __user *pgetnexthighmonotoniccount;
>
> +	struct efi_querycapsulecapabilities __user *pquerycapsulecapabilities;
> +
>   	switch (cmd) {
>   	case EFI_RUNTIME_GET_VARIABLE:
>   		pgetvariable = (struct efi_getvariable __user *)arg;
> @@ -297,6 +299,25 @@ static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
>   			return -EINVAL;
>
>   		return 0;
> +
> +	case EFI_RUNTIME_QUERY_CAPSULECAPABILITIES:
> +
> +		pquerycapsulecapabilities = (struct
> +				efi_querycapsulecapabilities __user *)arg;
> +
> +		status = efi.query_capsule_caps(
> +				(efi_capsule_header_t **)
> +				pquerycapsulecapabilities->CapsuleHeaderArray,
> +				pquerycapsulecapabilities->CapsuleCount,
> +				pquerycapsulecapabilities->MaximumCapsuleSize,
> +				(int *)pquerycapsulecapabilities->ResetType);
> +
> +		if (put_user(status, pquerycapsulecapabilities->status))
> +			return -EFAULT;
> +		if (status != EFI_SUCCESS)
> +			return -EINVAL;
> +
> +		return 0;
>   	}
>
>   	return -ENOTTY;
> diff --git a/efi_runtime/efi_runtime.h b/efi_runtime/efi_runtime.h
> index ad62aa7..c516bba 100644
> --- a/efi_runtime/efi_runtime.h
> +++ b/efi_runtime/efi_runtime.h
> @@ -21,6 +21,12 @@
>   #ifndef _EFI_RUNTIME_H_
>   #define _EFI_RUNTIME_H_
>
> +typedef enum {
> +	EfiResetCold,
> +	EfiResetWarm,
> +	EfiResetShutdown
> +} EFI_RESET_TYPE;
> +
>   typedef struct {
>   	uint32_t	Data1;
>   	uint16_t	Data2;
> @@ -48,6 +54,13 @@ typedef struct {
>   	uint8_t		SetsToZero;
>   } __attribute__ ((packed)) EFI_TIME_CAPABILITIES;
>
> +typedef struct {
> +	EFI_GUID CapsuleGuid;
> +	uint32_t HeaderSize;
> +	uint32_t Flags;
> +	uint32_t CapsuleImageSize;
> +} __attribute__ ((packed)) EFI_CAPSULE_HEADER;
> +
>   struct efi_getvariable {
>   	uint16_t	*VariableName;
>   	EFI_GUID	*VendorGuid;
> @@ -110,6 +123,14 @@ struct efi_getnexthighmonotoniccount {
>   	uint64_t	*status;
>   } __attribute__ ((packed));
>
> +struct efi_querycapsulecapabilities {
> +	EFI_CAPSULE_HEADER	**CapsuleHeaderArray;
> +	uint64_t		CapsuleCount;
> +	uint64_t		*MaximumCapsuleSize;
> +	EFI_RESET_TYPE		*ResetType;
> +	uint64_t		*status;
> +} __attribute__ ((packed));
> +
>   /* ioctl calls that are permitted to the /dev/efi_runtime interface. */
>   #define EFI_RUNTIME_GET_VARIABLE \
>   	_IOWR('p', 0x01, struct efi_getvariable)
> @@ -135,4 +156,7 @@ struct efi_getnexthighmonotoniccount {
>   #define EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT \
>   	_IOR('p', 0x09, struct efi_getnexthighmonotoniccount)
>
> +#define EFI_RUNTIME_QUERY_CAPSULECAPABILITIES \
> +	_IOR('p', 0x0A, struct efi_querycapsulecapabilities)
> +
>   #endif /* _EFI_RUNTIME_H_ */
>
Acked-by: Alex Hung <alex.hung@canonical.com>

Patch

diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
index 4c34f10..9440aae 100644
--- a/efi_runtime/efi_runtime.c
+++ b/efi_runtime/efi_runtime.c
@@ -121,6 +121,8 @@  static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
 
 	struct efi_getnexthighmonotoniccount __user *pgetnexthighmonotoniccount;
 
+	struct efi_querycapsulecapabilities __user *pquerycapsulecapabilities;
+
 	switch (cmd) {
 	case EFI_RUNTIME_GET_VARIABLE:
 		pgetvariable = (struct efi_getvariable __user *)arg;
@@ -297,6 +299,25 @@  static long efi_runtime_ioctl(struct file *file, unsigned int cmd,
 			return -EINVAL;
 
 		return 0;
+
+	case EFI_RUNTIME_QUERY_CAPSULECAPABILITIES:
+
+		pquerycapsulecapabilities = (struct
+				efi_querycapsulecapabilities __user *)arg;
+
+		status = efi.query_capsule_caps(
+				(efi_capsule_header_t **)
+				pquerycapsulecapabilities->CapsuleHeaderArray,
+				pquerycapsulecapabilities->CapsuleCount,
+				pquerycapsulecapabilities->MaximumCapsuleSize,
+				(int *)pquerycapsulecapabilities->ResetType);
+
+		if (put_user(status, pquerycapsulecapabilities->status))
+			return -EFAULT;
+		if (status != EFI_SUCCESS)
+			return -EINVAL;
+
+		return 0;
 	}
 
 	return -ENOTTY;
diff --git a/efi_runtime/efi_runtime.h b/efi_runtime/efi_runtime.h
index ad62aa7..c516bba 100644
--- a/efi_runtime/efi_runtime.h
+++ b/efi_runtime/efi_runtime.h
@@ -21,6 +21,12 @@ 
 #ifndef _EFI_RUNTIME_H_
 #define _EFI_RUNTIME_H_
 
+typedef enum {
+	EfiResetCold,
+	EfiResetWarm,
+	EfiResetShutdown
+} EFI_RESET_TYPE;
+
 typedef struct {
 	uint32_t	Data1;
 	uint16_t	Data2;
@@ -48,6 +54,13 @@  typedef struct {
 	uint8_t		SetsToZero;
 } __attribute__ ((packed)) EFI_TIME_CAPABILITIES;
 
+typedef struct {
+	EFI_GUID CapsuleGuid;
+	uint32_t HeaderSize;
+	uint32_t Flags;
+	uint32_t CapsuleImageSize;
+} __attribute__ ((packed)) EFI_CAPSULE_HEADER;
+
 struct efi_getvariable {
 	uint16_t	*VariableName;
 	EFI_GUID	*VendorGuid;
@@ -110,6 +123,14 @@  struct efi_getnexthighmonotoniccount {
 	uint64_t	*status;
 } __attribute__ ((packed));
 
+struct efi_querycapsulecapabilities {
+	EFI_CAPSULE_HEADER	**CapsuleHeaderArray;
+	uint64_t		CapsuleCount;
+	uint64_t		*MaximumCapsuleSize;
+	EFI_RESET_TYPE		*ResetType;
+	uint64_t		*status;
+} __attribute__ ((packed));
+
 /* ioctl calls that are permitted to the /dev/efi_runtime interface. */
 #define EFI_RUNTIME_GET_VARIABLE \
 	_IOWR('p', 0x01, struct efi_getvariable)
@@ -135,4 +156,7 @@  struct efi_getnexthighmonotoniccount {
 #define EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT \
 	_IOR('p', 0x09, struct efi_getnexthighmonotoniccount)
 
+#define EFI_RUNTIME_QUERY_CAPSULECAPABILITIES \
+	_IOR('p', 0x0A, struct efi_querycapsulecapabilities)
+
 #endif /* _EFI_RUNTIME_H_ */