Skip to contentSkip to conversation

VTPM mini-os: Add ioread() and iowrite() functions to mini-os

PATCH In review Matthew Fioravante 2 participants 4 messages Mar 11, 2011 – Mar 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 3/12 VTPM mini-os: Add ioread() and iowrite() functions to mini-os

Mini-os currently doesn't have very many facilities for reading and writing to hardware io memory. This patch addes a new header file iorw.h which when included gives access to the ioread8(), iread32(), iowrite8(), iowrite32() family of functions. Each has a separate implementation
for each architecture supported by mini-os.

Currently only x86 has been implemented. ia64 is stubbed out for now.

Signed off by: Matthew Fioravante <[email protected]>

extras/mini-os/arch/ia64/iorw.c +23 -0
diff -Naur xen-unstable-trp-sdp-pristine/extras/mini-os/arch/ia64/iorw.c xen-unstable-trp-sdp/extras/mini-os/arch/ia64/iorw.c
@@ -0,0 +1,23 @@
+#include <mini-os/iorw.h>
+#include <mini-os/console.h>
+
+void iowrite8(void* addr, uint8_t val)
+{
+   printk("iorw not implemented!!\n");
+}
+void iowrite32(void* addr, uint32_t val)
+{
+   printk("iorw not implemented!!\n");
+}
+
+uint8_t ioread8(void* addr)
+{
+   printk("iorw not implemented!!\n");
+   return 0;
+}
+uint32_t ioread32(void* addr)
+{
+   printk("iorw not implemented!!\n");
+   return 0;
+}
+
extras/mini-os/arch/x86/iorw.c +20 -0
diff -Naur xen-unstable-trp-sdp-pristine/extras/mini-os/arch/x86/iorw.c xen-unstable-trp-sdp/extras/mini-os/arch/x86/iorw.c
@@ -0,0 +1,20 @@
+#include <mini-os/iorw.h>
+
+void iowrite8(void* addr, uint8_t val)
+{
+   *((uint8_t*)addr) = val;
+}
+void iowrite32(void* addr, uint32_t val)
+{
+   *((uint32_t*)addr) = val;
+}
+
+uint8_t ioread8(void* addr)
+{
+   return *((uint8_t*) addr);
+}
+uint32_t ioread32(void* addr)
+{
+   return *((uint32_t*) addr);
+}
+
extras/mini-os/include/iorw.h +12 -0
diff -Naur xen-unstable-trp-sdp-pristine/extras/mini-os/include/iorw.h xen-unstable-trp-sdp/extras/mini-os/include/iorw.h
@@ -0,0 +1,12 @@
+#ifndef MINIOS_IORW_H
+#define MINIOS_IORW_H
+
+#include <mini-os/types.h>
+
+void iowrite8(void* addr, uint8_t val);
+void iowrite32(void* addr, uint32_t val);
+
+uint8_t ioread8(void* addr);
+uint32_t ioread32(void* addr);
+
+#endif

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 6 lines · Matthew Fioravante, le Fri 11 Mar 2011 17:38:32 -0500, a écrit :

Mini-os currently doesn't have very many facilities for reading and writing to hardware io memory. This patch addes a new header file iorw.h which when included gives access to
the ioread8(), iread32(), iowrite8(), iowrite32() family of functions.

extras/mini-os/arch/x86/iorw.c line 10

Quoted 8 lines
extras/mini-os/arch/x86/iorw.c +8 -0
+void iowrite8(void* addr, uint8_t val)
+{
+   *((uint8_t*)addr) = val;
+}
+void iowrite32(void* addr, uint32_t val)
+{
+   *((uint32_t*)addr) = val;
+}

Don't you need a volatile qualifier on the cast pointer to not let the compiler optimize it away?

Samuel

#2 lore raw

Yeah your right, sorry about that! Heres a patch that applies on top of the previous one to add volatile.

Signed off by: Matthew Fioravante <[email protected]>

Quoted 17 lines · Samuel Thibault

Review

Quoted 13 lines · Matthew Fioravante, le Fri 11 Mar 2011 17:38:32 -0500, a écrit :

Mini-os currently doesn't have very many facilities for reading and writing to hardware io memory. This patch addes a new header file iorw.h which when included gives access to
the ioread8(), iread32(), iowrite8(), iowrite32() family of functions.

(quoted diff) +8 -0
+void iowrite8(void* addr, uint8_t val)
+{
+   *((uint8_t*)addr) = val;
+}
+void iowrite32(void* addr, uint32_t val)
+{
+   *((uint32_t*)addr) = val;
+}

Don't you need a volatile qualifier on the cast pointer to not let the compiler optimize it away?

Quoted 1 line

Samuel

extras/mini-os/arch/ia64/iorw.c +4 -4
diff -r 01c0d5a14e11 extras/mini-os/arch/ia64/iorw.c
@@ -1,21 +1,21 @@
 #include <mini-os/iorw.h>
 #include <mini-os/console.h>
 
-void iowrite8(void* addr, uint8_t val)
+void iowrite8(volatile void* addr, uint8_t val)
 {
    printk("iorw not implemented!!\n");
 }
-void iowrite32(void* addr, uint32_t val)
+void iowrite32(volatile void* addr, uint32_t val)
 {
    printk("iorw not implemented!!\n");
 }
 
-uint8_t ioread8(void* addr)
+uint8_t ioread8(volatile void* addr)
 {
    printk("iorw not implemented!!\n");
    return 0;
 }
-uint32_t ioread32(void* addr)
+uint32_t ioread32(volatile void* addr)
 {
    printk("iorw not implemented!!\n");
    return 0;
extras/mini-os/arch/x86/iorw.c +8 -8
diff -r 01c0d5a14e11 extras/mini-os/arch/x86/iorw.c
@@ -1,20 +1,20 @@
 #include <mini-os/iorw.h>
 
-void iowrite8(void* addr, uint8_t val)
+void iowrite8(volatile void* addr, uint8_t val)
 {
-   *((uint8_t*)addr) = val;
+   *((volatile uint8_t*)addr) = val;
 }
-void iowrite32(void* addr, uint32_t val)
+void iowrite32(volatile void* addr, uint32_t val)
 {
-   *((uint32_t*)addr) = val;
+   *((volatile uint32_t*)addr) = val;
 }
 
-uint8_t ioread8(void* addr)
+uint8_t ioread8(volatile void* addr)
 {
-   return *((uint8_t*) addr);
+   return *((volatile uint8_t*) addr);
 }
-uint32_t ioread32(void* addr)
+uint32_t ioread32(volatile void* addr)
 {
-   return *((uint32_t*) addr);
+   return *((volatile uint32_t*) addr);
 }
 
extras/mini-os/include/iorw.h +4 -4
diff -r 01c0d5a14e11 extras/mini-os/include/iorw.h
@@ -3,10 +3,10 @@
 
 #include <mini-os/types.h>
 
-void iowrite8(void* addr, uint8_t val);
-void iowrite32(void* addr, uint32_t val);
+void iowrite8(volatile void* addr, uint8_t val);
+void iowrite32(volatile void* addr, uint32_t val);
 
-uint8_t ioread8(void* addr);
-uint32_t ioread32(void* addr);
+uint8_t ioread8(volatile void* addr);
+uint32_t ioread32(volatile void* addr);
 
 #endif

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 2 lines · Matthew Fioravante, le Mon 14 Mar 2011 13:10:54 -0400, a écrit :

Yeah your right, sorry about that! Heres a patch that applies on top of the previous one to add volatile.

Ok, but you'll rather have to submit an updated patch instead.

Samuel