Patchwork [1/3] kvm-unit-tests: add x86 port io accessors

login
register
mail settings
Submitter Anthony Liguori
Date Feb. 24, 2011, 9:48 p.m.
Message ID <1298584085-13129-2-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/84492/
State New
Headers show

Comments

Anthony Liguori - Feb. 24, 2011, 9:48 p.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Avi Kivity - Feb. 27, 2011, 12:44 p.m.
On 02/24/2011 11:48 PM, Anthony Liguori wrote:
> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>
> diff --git a/lib/x86/io.h b/lib/x86/io.h
> new file mode 100644
> index 0000000..bd6341c
> --- /dev/null
> +++ b/lib/x86/io.h
> @@ -0,0 +1,40 @@
> +#ifndef IO_H
> +#define IO_H
> +
> +static inline unsigned char inb(unsigned short port)
> +{
> +    unsigned char value;
> +    asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port));
> +    return value;
> +}

Are those %[wb] really needed?  gcc should do the right thing based on 
the argument type.

Might as well put all of that into processor.h.
Anthony Liguori - Feb. 27, 2011, 2:01 p.m.
On 02/27/2011 06:44 AM, Avi Kivity wrote:
> On 02/24/2011 11:48 PM, Anthony Liguori wrote:
>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>
>> diff --git a/lib/x86/io.h b/lib/x86/io.h
>> new file mode 100644
>> index 0000000..bd6341c
>> --- /dev/null
>> +++ b/lib/x86/io.h
>> @@ -0,0 +1,40 @@
>> +#ifndef IO_H
>> +#define IO_H
>> +
>> +static inline unsigned char inb(unsigned short port)
>> +{
>> +    unsigned char value;
>> +    asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port));
>> +    return value;
>> +}
>
> Are those %[wb] really needed?  gcc should do the right thing based on 
> the argument type.

It's just a little extra type safety.

>
> Might as well put all of that into processor.h.

Seems reasonable.

Regards,

Anthony Liguori
Avi Kivity - Feb. 27, 2011, 3:32 p.m.
On 02/27/2011 04:01 PM, Anthony Liguori wrote:
> On 02/27/2011 06:44 AM, Avi Kivity wrote:
>> On 02/24/2011 11:48 PM, Anthony Liguori wrote:
>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>>
>>> diff --git a/lib/x86/io.h b/lib/x86/io.h
>>> new file mode 100644
>>> index 0000000..bd6341c
>>> --- /dev/null
>>> +++ b/lib/x86/io.h
>>> @@ -0,0 +1,40 @@
>>> +#ifndef IO_H
>>> +#define IO_H
>>> +
>>> +static inline unsigned char inb(unsigned short port)
>>> +{
>>> +    unsigned char value;
>>> +    asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port));
>>> +    return value;
>>> +}
>>
>> Are those %[wb] really needed?  gcc should do the right thing based 
>> on the argument type.
>
> It's just a little extra type safety.

Yeah, but those constraints aren't really documented.  Linux does use 
them in a handful of places so they're unlikely to go away though.

Patch

diff --git a/lib/x86/io.h b/lib/x86/io.h
new file mode 100644
index 0000000..bd6341c
--- /dev/null
+++ b/lib/x86/io.h
@@ -0,0 +1,40 @@ 
+#ifndef IO_H
+#define IO_H
+
+static inline unsigned char inb(unsigned short port)
+{
+    unsigned char value;
+    asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port));
+    return value;
+}
+
+static inline unsigned short inw(unsigned short port)
+{
+    unsigned short value;
+    asm volatile("inw %w1, %0" : "=a" (value) : "Nd" (port));
+    return value;
+}
+
+static inline unsigned int inl(unsigned short port)
+{
+    unsigned int value;
+    asm volatile("inl %w1, %0" : "=a" (value) : "Nd" (port));
+    return value;
+}
+
+static inline void outb(unsigned char value, unsigned short port)
+{
+    asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port));
+}
+
+static inline void outw(unsigned short value, unsigned short port)
+{
+    asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port));
+}
+
+static inline void outl(unsigned int value, unsigned short port)
+{
+    asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port));
+}
+
+#endif