All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] ARM: BCM2835: Add a function for doing an rmb() between device reads.
@ 2015-03-13  2:32 Eric Anholt
       [not found] ` <1426213936-4139-1-git-send-email-eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
  0 siblings, 1 reply; 42+ messages in thread
From: Eric Anholt @ 2015-03-13  2:32 UTC (permalink / raw)
  To: linux-arm-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Stephen Warren, Lee Jones, devicetree-u79uwXL29TY76Z2rM5mHXA,
	Jassi Brar, Craig McGeachie, Lubomir Rintel, Eric Anholt

Stephen Warren was concerned that the rmb() present in the new mailbox
driver was unnecessary, and after seeing the docs, that it was just so
surprising that somebody would come along and remove it later.  The
explanation for the need for the rmb() is long enough that we won't
want to place it at every callsite.  Make a wrapper with the whole
explanation in it, so that anyone wondering what's going on sees the
docs right there.

Signed-off-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
---
 include/soc/bcm2835/peripheral-workaround.h | 75 +++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 include/soc/bcm2835/peripheral-workaround.h

diff --git a/include/soc/bcm2835/peripheral-workaround.h b/include/soc/bcm2835/peripheral-workaround.h
new file mode 100644
index 0000000..4541a13
--- /dev/null
+++ b/include/soc/bcm2835/peripheral-workaround.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2015 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+static inline void bcm2835_peripheral_read_workaround(void)
+{
+#ifdef CONFIG_ARCH_BCM2835
+	/*
+	 * The BCM2835 bus is unusual in that it doesn't guarantee
+	 * ordering between reads from different peripherals (where
+	 * peripherals roughly correspond to Linux devices).  From
+	 * BCM2835 ARM Peripherals.pdf, page 7:
+	 *
+	 *     "In order to keep the system complexity low and data
+	 *      throughput high, the BCM2835 AXI system does not
+	 *      always return read data in-order. The GPU has special
+	 *      logic to cope with data arriving out-of-order; however
+	 *      the ARM core does not contain such logic. Therefore
+	 *      some precautions must be taken when using the ARM to
+	 *      access peripherals.
+	 *
+	 *      Accesses to the same peripheral will always arrive and
+	 *      return in-order. It is only when switching from one
+	 *      peripheral to another that data can arrive
+	 *      out-of-order. The simplest way to make sure that data
+	 *      is processed in-order is to place a memory barrier
+	 *      instruction at critical positions in the code. You
+	 *      should place:
+	 *
+	 *      • A memory write barrier before the first write to a
+	 *        peripheral.
+	 *      • A memory read barrier after the last read of a
+	 *        peripheral."
+	 *
+	 * The footnote explicitly says that:
+	 *
+	 *      "For example:
+	 *
+	 *         a_status = *pointer_to_peripheral_a;
+	 *         b_status = *pointer_to_peripheral_b;
+	 *
+	 *       Without precuations the values ending up in the
+	 *       variables a_status and b_status can be swapped
+	 *       around."
+	 *
+	 * However, it also notes that, somewhat contrary to the first
+	 * bullet point:
+	 *
+	 *     "It is theoretical possible for writes to go ‘wrong’
+	 *      but that is far more difficult to achieve. The AXI
+	 *      system makes sure the data always arrives in-order at
+	 *      its intended destination. So:
+	 *
+	 *        *pointer_to_peripheral_a = value_a;
+	 *        *pointer_to_peripheral_b = value_b;
+	 *
+	 *      will always give the expected result. The only time
+	 *      write data can arrive out-of-order is if two different
+	 *      peripherals are connected to the same external
+	 *      equipment"
+	 *
+	 * Since we aren't interacting with multiple peripherals
+	 * connected to the same external equipment as far as we know,
+	 * that means that we only need to handle the read workaround
+	 * case.  We do so by placing an rmb() at the first device
+	 * read acceess in a given driver path, including the
+	 * interrupt handlers.
+	 */
+	rmb();
+#endif
+}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2015-03-20 19:29 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13  2:32 [PATCH 1/4] ARM: BCM2835: Add a function for doing an rmb() between device reads Eric Anholt
     [not found] ` <1426213936-4139-1-git-send-email-eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2015-03-13  2:32   ` [PATCH 2/4 v3] dt/bindings: Add binding for BCM2835 mailbox driver Eric Anholt
     [not found]     ` <1426213936-4139-2-git-send-email-eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2015-03-17 17:27       ` Lee Jones
2015-03-17 22:14         ` Scott Branden
     [not found]           ` <5508A75A.4070203-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2015-03-18  1:34             ` Eric Anholt
2015-03-18  8:23             ` Lee Jones
2015-03-18  8:40               ` Jassi Brar
     [not found]                 ` <CABb+yY0Gc+vJHksKc7ahYfRdh2vzj_VR_bFvjr+K+hiqiah5bg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-18  9:15                   ` Lee Jones
2015-03-13  2:32   ` [PATCH 3/4 v4] mailbox: Enable BCM2835 mailbox support Eric Anholt
     [not found]     ` <1426213936-4139-3-git-send-email-eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2015-03-17  3:33       ` Stephen Warren
2015-03-17  3:33         ` Stephen Warren
     [not found]         ` <5507A095.5090805-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-03-17 18:05           ` Lee Jones
2015-03-17 18:05             ` Lee Jones
2015-03-17 19:04             ` Eric Anholt
2015-03-17 19:04               ` Eric Anholt
2015-03-18 23:28           ` Eric Anholt
2015-03-18 23:28             ` Eric Anholt
     [not found]             ` <87619xq414.fsf-omZaPlIz5HhaEpDpdNBo/KxOck334EZe@public.gmane.org>
2015-03-20  4:48               ` Stephen Warren
2015-03-20  4:48                 ` Stephen Warren
     [not found]                 ` <550BA6B4.3030604-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-03-20  5:12                   ` Jassi Brar
2015-03-20  5:12                     ` Jassi Brar
     [not found]                     ` <CABb+yY0qN4KcZ9kc6eurSUWPn38f2keKe4FB2efKBAVjREcZbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-20 17:38                       ` Eric Anholt
2015-03-20 17:38                         ` Eric Anholt
2015-03-20 17:24                   ` Eric Anholt
2015-03-20 17:24                     ` Eric Anholt
     [not found]                     ` <87wq2bk2ez.fsf-omZaPlIz5HhaEpDpdNBo/KxOck334EZe@public.gmane.org>
2015-03-20 19:29                       ` Stephen Warren
2015-03-20 19:29                         ` Stephen Warren
2015-03-18  8:42       ` Lee Jones
2015-03-18 22:39         ` Eric Anholt
     [not found]           ` <87bnjqorpe.fsf-omZaPlIz5HhaEpDpdNBo/KxOck334EZe@public.gmane.org>
2015-03-19  7:58             ` Lee Jones
2015-03-20  4:46               ` Stephen Warren
2015-03-20  4:46                 ` Stephen Warren
2015-03-20  4:44             ` Stephen Warren
2015-03-20  4:44               ` Stephen Warren
2015-03-13  2:32   ` [PATCH 4/4] ARM: bcm2835: Add the mailbox to the device tree Eric Anholt
     [not found]     ` <1426213936-4139-4-git-send-email-eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2015-03-17  3:34       ` Stephen Warren
2015-03-17  3:34         ` Stephen Warren
2015-03-17  3:24   ` [PATCH 1/4] ARM: BCM2835: Add a function for doing an rmb() between device reads Stephen Warren
2015-03-17  3:24     ` Stephen Warren
     [not found]     ` <55079E79.6030303-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-03-17 19:06       ` Eric Anholt
2015-03-17 19:06         ` Eric Anholt
2015-03-18  8:26   ` Lee Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.