-/* $OpenBSD: bus.h,v 1.5 2022/12/29 11:35:01 kettenis Exp $ */
+/* $OpenBSD: bus.h,v 1.6 2024/03/27 23:10:18 kettenis Exp $ */
/*
* Copyright (c) 2003-2004 Opsycon AB Sweden. All rights reserved.
char *s = (char *)(h1 + o1);
char *d = (char *)(h2 + o2);
+ __asm volatile ("fence w,o" ::: "memory");
while (c--)
*d++ = *s++;
+ __asm volatile ("fence io,iwr" ::: "memory");
}
short *s = (short *)(h1 + o1);
short *d = (short *)(h2 + o2);
+ __asm volatile ("fence w,o" ::: "memory");
while (c--)
*d++ = *s++;
+ __asm volatile ("fence io,iwr" ::: "memory");
}
static __inline void
int *s = (int *)(h1 + o1);
int *d = (int *)(h2 + o2);
+ __asm volatile ("fence w,o" ::: "memory");
while (c--)
*d++ = *s++;
+ __asm volatile ("fence io,iwr" ::: "memory");
}
static __inline void
int64_t *s = (int64_t *)(h1 + o1);
int64_t *d = (int64_t *)(h2 + o2);
+ __asm volatile ("fence w,o" ::: "memory");
while (c--)
*d++ = *s++;
+ __asm volatile ("fence io,iwr" ::: "memory");
}
/*----------------------------------------------------------------------------*/
-/* $OpenBSD: bus_space.c,v 1.2 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: bus_space.c,v 1.3 2024/03/27 23:10:18 kettenis Exp $ */
/*
* Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com)
uint8_t
generic_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
{
- return *(volatile uint8_t *)(h + o);
+ uint8_t val = *(volatile uint8_t *)(h + o);
+ __asm volatile ("fence i,ir" ::: "memory");
+ return val;
}
uint16_t
generic_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
{
- return *(volatile uint16_t *)(h + o);
+ uint16_t val = *(volatile uint16_t *)(h + o);
+ __asm volatile ("fence i,ir" ::: "memory");
+ return val;
}
uint32_t
generic_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
{
- return *(volatile uint32_t *)(h + o);
+ uint32_t val = *(volatile uint32_t *)(h + o);
+ __asm volatile ("fence i,ir" ::: "memory");
+ return val;
}
uint64_t
generic_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
{
- return *(volatile uint64_t *)(h + o);
+ uint64_t val = *(volatile uint64_t *)(h + o);
+ __asm volatile ("fence i,ir" ::: "memory");
+ return val;
}
void
generic_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
uint8_t v)
{
+ __asm volatile ("fence w,o" ::: "memory");
*(volatile uint8_t *)(h + o) = v;
+ __asm volatile ("fence o,w" ::: "memory");
}
void
generic_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
uint16_t v)
{
+ __asm volatile ("fence w,o" ::: "memory");
*(volatile uint16_t *)(h + o) = v;
+ __asm volatile ("fence o,w" ::: "memory");
}
void
generic_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
uint32_t v)
{
+ __asm volatile ("fence w,o" ::: "memory");
*(volatile uint32_t *)(h + o) = v;
+ __asm volatile ("fence o,w" ::: "memory");
}
void
generic_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
uint64_t v)
{
+ __asm volatile ("fence w,o" ::: "memory");
*(volatile uint64_t *)(h + o) = v;
+ __asm volatile ("fence o,w" ::: "memory");
}
void
*(uint16_t *)buf = *addr;
buf += 2;
}
+ __asm volatile ("fence i,ir" ::: "memory");
}
void
const uint8_t *buf, bus_size_t len)
{
volatile uint16_t *addr = (volatile uint16_t *)(h + o);
+ __asm volatile ("fence w,o" ::: "memory");
len >>= 1;
while (len-- != 0) {
*addr = *(uint16_t *)buf;
buf += 2;
}
+ __asm volatile ("fence o,w" ::: "memory");
}
void
*(uint32_t *)buf = *addr;
buf += 4;
}
+ __asm volatile ("fence i,ir" ::: "memory");
}
void
const uint8_t *buf, bus_size_t len)
{
volatile uint32_t *addr = (volatile uint32_t *)(h + o);
+ __asm volatile ("fence w,o" ::: "memory");
len >>= 2;
while (len-- != 0) {
*addr = *(uint32_t *)buf;
buf += 4;
}
+ __asm volatile ("fence o,w" ::: "memory");
}
void
*(uint64_t *)buf = *addr;
buf += 8;
}
+ __asm volatile ("fence i,ir" ::: "memory");
}
void
const uint8_t *buf, bus_size_t len)
{
volatile uint64_t *addr = (volatile uint64_t *)(h + o);
+ __asm volatile ("fence w,o" ::: "memory");
len >>= 3;
while (len-- != 0) {
*addr = *(uint64_t *)buf;
buf += 8;
}
+ __asm volatile ("fence o,w" ::: "memory");
}
int