aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board-qemu/virtio-net/virtio-net.c11
-rw-r--r--include/helpers.h6
-rw-r--r--include/ppc970/cpu.h18
-rw-r--r--include/ppcp7/cpu.h15
-rw-r--r--lib/libvirtio/virtio-9p.c6
-rw-r--r--lib/libvirtio/virtio-blk.c8
-rw-r--r--lib/libvirtio/virtio-scsi.c7
-rw-r--r--slof/helpers.c1
8 files changed, 41 insertions, 31 deletions
diff --git a/board-qemu/virtio-net/virtio-net.c b/board-qemu/virtio-net/virtio-net.c
index 5536060..fe9990f 100644
--- a/board-qemu/virtio-net/virtio-net.c
+++ b/board-qemu/virtio-net/virtio-net.c
@@ -19,16 +19,13 @@
*/
#include <stdint.h>
+#include <cpu.h>
#include "netdriver_int.h"
#include <libhvcall.h>
#include <virtio.h>
#include <string.h>
#include "virtio-net.h"
-
-#define sync() asm volatile (" sync \n" ::: "memory")
-
-
struct virtio_device virtiodev;
struct vqs vq[2]; /* Information about virtqueues */
@@ -100,7 +97,7 @@ static int virtionet_init(void)
vq[VQ_RX].avail->ring[i] = i*2;
}
- sync();
+ mb();
vq[VQ_RX].avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
vq[VQ_RX].avail->idx = RX_QUEUE_SIZE;
@@ -184,7 +181,7 @@ static int virtionet_xmit(char *buf, int len)
desc->next = 0;
vq[VQ_TX].avail->ring[vq[VQ_TX].avail->idx % vq[VQ_TX].size] = id;
- sync();
+ mb();
vq[VQ_TX].avail->idx += 1;
/* Tell HV that TX queue is ready */
@@ -239,7 +236,7 @@ static int virtionet_receive(char *buf, int maxlen)
last_rx_idx = last_rx_idx + 1;
vq[VQ_RX].avail->ring[vq[VQ_RX].avail->idx % vq[VQ_RX].size] = id - 1;
- sync();
+ mb();
vq[VQ_RX].avail->idx += 1;
/* Tell HV that RX queue entry is ready */
diff --git a/include/helpers.h b/include/helpers.h
index e41d6a0..1a1f6e5 100644
--- a/include/helpers.h
+++ b/include/helpers.h
@@ -28,10 +28,4 @@ extern void SLOF_free_mem(void *addr, long size);
extern long SLOF_dma_map_in(void *virt, long size, int cacheable);
extern void SLOF_dma_map_out(long phys, void *virt, long size);
-static inline void barrier(void)
-{
- asm volatile("" : : : "memory");
-}
-#define cpu_relax() barrier()
-
#endif
diff --git a/include/ppc970/cpu.h b/include/ppc970/cpu.h
index a1a0932..0e66dff 100644
--- a/include/ppc970/cpu.h
+++ b/include/ppc970/cpu.h
@@ -86,14 +86,24 @@ clr_ci(void)
asm volatile(EXPAND(CLRCI(%0)) : "=r"(tmp) :: "memory", "cc");
}
-static inline void
-eieio(void)
+static inline void eieio(void)
{
asm volatile ("eieio":::"memory");
}
-static inline void
-flush_cache(void* r, long n)
+static inline void barrier(void)
+{
+ asm volatile("" : : : "memory");
+}
+#define cpu_relax() barrier()
+
+static inline void sync(void)
+{
+ asm volatile ("sync" ::: "memory");
+}
+#define mb() sync()
+
+static inline void flush_cache(void* r, long n)
{
asm volatile(EXPAND(FLUSH_CACHE(%0, %1)) : "+r"(r), "+r"(n) :: "memory", "cc", "r0", "ctr");
}
diff --git a/include/ppcp7/cpu.h b/include/ppcp7/cpu.h
index 042e64b..1b1fadd 100644
--- a/include/ppcp7/cpu.h
+++ b/include/ppcp7/cpu.h
@@ -44,12 +44,23 @@ static inline void flush_cache(void* r, long n)
:: "memory", "cc", "r0", "ctr");
}
-static inline void
-eieio(void)
+static inline void eieio(void)
{
asm volatile ("eieio":::"memory");
}
+static inline void barrier(void)
+{
+ asm volatile("" : : : "memory");
+}
+#define cpu_relax() barrier()
+
+static inline void sync(void)
+{
+ asm volatile ("sync" ::: "memory");
+}
+#define mb() sync()
+
#endif /* __ASSEMBLER__ */
#endif
diff --git a/lib/libvirtio/virtio-9p.c b/lib/libvirtio/virtio-9p.c
index 129a2b4..fd2a419 100644
--- a/lib/libvirtio/virtio-9p.c
+++ b/lib/libvirtio/virtio-9p.c
@@ -14,6 +14,7 @@
#include <string.h>
#include <stdint.h>
#include <byteorder.h>
+#include <cpu.h>
#include "virtio-9p.h"
#include "p9.h"
@@ -39,7 +40,6 @@ static int __buf_size;
#define ROOT_FID 1
#define FILE_FID 2
#define TAG_SIZE 128
-#define sync() asm volatile (" sync \n" ::: "memory")
#define MIN(a,b) ((a)>(b)?(b):(a))
@@ -129,7 +129,7 @@ static int virtio_9p_transact(void *opaque, uint8_t *tx, int tx_size, uint8_t *r
/* Tell HV that the queue is ready */
vq_avail->ring[vq_avail->idx % vq_size] = id;
- sync();
+ mb();
vq_avail->idx += 1;
virtio_queue_notify(dev, 0);
@@ -137,7 +137,7 @@ static int virtio_9p_transact(void *opaque, uint8_t *tx, int tx_size, uint8_t *r
i = 10000000;
while (*current_used_idx == last_used_idx && i-- > 0) {
// do something better
- sync();
+ mb();
}
if (i == 0) {
return -1;
diff --git a/lib/libvirtio/virtio-blk.c b/lib/libvirtio/virtio-blk.c
index e470968..6f21404 100644
--- a/lib/libvirtio/virtio-blk.c
+++ b/lib/libvirtio/virtio-blk.c
@@ -11,12 +11,10 @@
*****************************************************************************/
#include <stdio.h>
+#include <cpu.h>
#include "virtio.h"
#include "virtio-blk.h"
-#define sync() asm volatile (" sync \n" ::: "memory")
-
-
/**
* Initialize virtio-block device.
* @param dev pointer to virtio device information
@@ -140,7 +138,7 @@ virtioblk_read(struct virtio_device *dev, char *buf, long blocknum, long cnt)
desc->next = 0;
vq_avail->ring[vq_avail->idx % vq_size] = id;
- sync();
+ mb();
vq_avail->idx += 1;
/* Tell HV that the queue is ready */
@@ -150,7 +148,7 @@ virtioblk_read(struct virtio_device *dev, char *buf, long blocknum, long cnt)
i = 10000000;
while (*current_used_idx == last_used_idx && i-- > 0) {
// do something better
- sync();
+ mb();
}
if (status == 0)
diff --git a/lib/libvirtio/virtio-scsi.c b/lib/libvirtio/virtio-scsi.c
index dba0cff..53e869a 100644
--- a/lib/libvirtio/virtio-scsi.c
+++ b/lib/libvirtio/virtio-scsi.c
@@ -12,11 +12,10 @@
#include <stdio.h>
#include <string.h>
+#include <cpu.h>
#include "virtio.h"
#include "virtio-scsi.h"
-#define sync() asm volatile (" sync \n" ::: "memory")
-
int virtioscsi_send(struct virtio_device *dev,
struct virtio_scsi_req_cmd *req,
struct virtio_scsi_resp_cmd *resp,
@@ -69,7 +68,7 @@ int virtioscsi_send(struct virtio_device *dev,
desc->flags &= ~VRING_DESC_F_NEXT;
vq_avail->ring[vq_avail->idx % vq_size] = id;
- sync();
+ mb();
vq_avail->idx += 1;
/* Tell HV that the vq is ready */
@@ -79,7 +78,7 @@ int virtioscsi_send(struct virtio_device *dev,
i = 10000000;
while (*current_used_idx == last_used_idx && i-- > 0) {
// do something better
- sync();
+ mb();
}
return 0;
diff --git a/slof/helpers.c b/slof/helpers.c
index 7b497f1..564052f 100644
--- a/slof/helpers.c
+++ b/slof/helpers.c
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <string.h>
+#include <cpu.h>
#include "helpers.h"
#include "paflof.h"