Re: [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-15 Thread Laurent Vivier
Le 15/01/2020 à 16:53, Filip Bozuta a écrit :
> This patch implements functionalities of following ioctls:
> 
> RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate
> 
> Read and set the frequency for periodic interrupts, for RTCs
> that support periodic interrupts. The periodic interrupt must
> be separately enabled or disabled using the RTC_PIE_ON,
> RTC_PIE_OFF requests. The third ioctl's argument is an
> unsigned long * or an unsigned long, respectively. The value
> is the frequency in interrupts per second. The set of allow‐
> able frequencies is the multiples of two in the range 2 to
> 8192. Only a privileged process (i.e., one having the
> CAP_SYS_RESOURCE capability) can set frequencies above the
> value specified in /proc/sys/dev/rtc/max-user-freq. (This
> file contains the value 64 by default.)
> 
> RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch
> 
> Many RTCs encode the year in an 8-bit register which is either
> interpreted as an 8-bit binary number or as a BCD number. In
> both cases, the number is interpreted relative to this RTC's
> Epoch. The RTC's Epoch is initialized to 1900 on most systems
> but on Alpha and MIPS it might also be initialized to 1952,
> 1980, or 2000, depending on the value of an RTC register for
> the year. With some RTCs, these operations can be used to
> read or to set the RTC's Epoch, respectively. The third
> ioctl's argument is an unsigned long * or an unsigned long,
> respectively, and the value returned (or assigned) is the
> Epoch. To set the RTC's Epoch the process must be privileged
> (i.e., have the CAP_SYS_TIME capability).
> 
> Implementation notes:
> 
> All ioctls in this patch have a pointer to 'ulong' as their
> third argument. That is the reason why corresponding parts
> of added code in linux-user/syscall_defs.h contain special
> handling related to 'ulong' type: they use 'abi_ulong' type
> to make sure that ioctl's code is calculated correctly for
> both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
> is used for the similar reason in linux-user/ioctls.h.
> Because ioctls RTC_IRQP_SET and RTC_EPOCH_SET are ioctls of
> type IOW(writing type) that have unsigned long as their
> third argument, a case statement for "TYPE_ULONG" was added
> in the appropriate place for function "abi_ulong do_ioctl"
> in file "syscall.c". There were no implemented ioctls of
> type IOW with unsigned long as third argument before this
> patch, which is the reason why this case statement was added
> now for the first time.
> 
> Signed-off-by: Filip Bozuta 
> ---
>  linux-user/ioctls.h   | 4 
>  linux-user/syscall.c  | 1 +
>  linux-user/syscall_defs.h | 4 
>  3 files changed, 9 insertions(+)
> 
...
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 74c3c08..c0b7314 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5175,6 +5175,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
>  break;
>  case TYPE_PTRVOID:
>  case TYPE_INT:
> +case TYPE_ULONG:
>  ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
>  break;
>  case TYPE_PTR:

I think this can go in a separate patch as it's a fix.

You should also add TYPE_LONG.

Thanks,
Laurent



[PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts. The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests. The third ioctl's argument is an
unsigned long * or an unsigned long, respectively. The value
is the frequency in interrupts per second. The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq. (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number. In
both cases, the number is interpreted relative to this RTC's
Epoch. The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year. With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively. The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch. To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.
Because ioctls RTC_IRQP_SET and RTC_EPOCH_SET are ioctls of
type IOW(writing type) that have unsigned long as their
third argument, a case statement for "TYPE_ULONG" was added
in the appropriate place for function "abi_ulong do_ioctl"
in file "syscall.c". There were no implemented ioctls of
type IOW with unsigned long as third argument before this
patch, which is the reason why this case statement was added
now for the first time.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall.c  | 1 +
 linux-user/syscall_defs.h | 4 
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 74c3c08..c0b7314 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5175,6 +5175,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
 break;
 case TYPE_PTRVOID:
 case TYPE_INT:
+case TYPE_ULONG:
 ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
 break;
 case TYPE_PTR:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




Re: [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-14 Thread Laurent Vivier
Le 09/01/2020 à 13:59, Filip Bozuta a écrit :
> This patch implements functionalities of following ioctls:
> 
> RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate
> 
> Read and set the frequency for periodic interrupts, for RTCs
> that support periodic interrupts. The periodic interrupt must
> be separately enabled or disabled using the RTC_PIE_ON,
> RTC_PIE_OFF requests. The third ioctl's argument is an
> unsigned long * or an unsigned long, respectively. The value
> is the frequency in interrupts per second. The set of allow‐
> able frequencies is the multiples of two in the range 2 to
> 8192. Only a privileged process (i.e., one having the
> CAP_SYS_RESOURCE capability) can set frequencies above the
> value specified in /proc/sys/dev/rtc/max-user-freq. (This
> file contains the value 64 by default.)
> 
> RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch
> 
> Many RTCs encode the year in an 8-bit register which is either
> interpreted as an 8-bit binary number or as a BCD number. In
> both cases, the number is interpreted relative to this RTC's
> Epoch. The RTC's Epoch is initialized to 1900 on most systems
> but on Alpha and MIPS it might also be initialized to 1952,
> 1980, or 2000, depending on the value of an RTC register for
> the year. With some RTCs, these operations can be used to
> read or to set the RTC's Epoch, respectively. The third
> ioctl's argument is an unsigned long * or an unsigned long,
> respectively, and the value returned (or assigned) is the
> Epoch. To set the RTC's Epoch the process must be privileged
> (i.e., have the CAP_SYS_TIME capability).
> 
> Implementation notes:
> 
> All ioctls in this patch have a pointer to 'ulong' as their
> third argument. That is the reason why corresponding parts
> of added code in linux-user/syscall_defs.h contain special
> handling related to 'ulong' type: they use 'abi_ulong' type
> to make sure that ioctl's code is calculated correctly for
> both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
> is used for the similar reason in linux-user/ioctls.h.
> 
> Signed-off-by: Filip Bozuta 
> ---
>  linux-user/ioctls.h   | 4 
>  linux-user/syscall_defs.h | 4 
>  2 files changed, 8 insertions(+)
> 
> diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
> index f472794..accbdee 100644
> --- a/linux-user/ioctls.h
> +++ b/linux-user/ioctls.h
> @@ -81,6 +81,10 @@
>   IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
>   IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
>   IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
> + IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
> + IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
> + IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
> + IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
>  
>   IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
>   IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index f0bf09d..bbfa935 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -776,6 +776,10 @@ struct target_pollfd {
>  #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
>  #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
>  #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
> +#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
> +#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
> +#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
> +#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
>  
>  #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||  
>   \
> defined(TARGET_XTENSA)
> 

Reviewed-by: Laurent Vivier 



[PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts. The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests. The third ioctl's argument is an
unsigned long * or an unsigned long, respectively. The value
is the frequency in interrupts per second. The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq. (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number. In
both cases, the number is interpreted relative to this RTC's
Epoch. The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year. With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively. The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch. To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4