1*4a6459a8Sriastradh/* $NetBSD: membar_ops.S,v 1.13 2022/04/21 12:06:31 riastradh Exp $ */ 2234aa623Sad 3234aa623Sad/*- 4234aa623Sad * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. 5234aa623Sad * All rights reserved. 6234aa623Sad * 7234aa623Sad * This code is derived from software contributed to The NetBSD Foundation 8234aa623Sad * by Jason R. Thorpe, and by Andrew Doran. 9234aa623Sad * 10234aa623Sad * Redistribution and use in source and binary forms, with or without 11234aa623Sad * modification, are permitted provided that the following conditions 12234aa623Sad * are met: 13234aa623Sad * 1. Redistributions of source code must retain the above copyright 14234aa623Sad * notice, this list of conditions and the following disclaimer. 15234aa623Sad * 2. Redistributions in binary form must reproduce the above copyright 16234aa623Sad * notice, this list of conditions and the following disclaimer in the 17234aa623Sad * documentation and/or other materials provided with the distribution. 18234aa623Sad * 19234aa623Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20234aa623Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21234aa623Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22234aa623Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23234aa623Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24234aa623Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25234aa623Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26234aa623Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27234aa623Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28234aa623Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29234aa623Sad * POSSIBILITY OF SUCH DAMAGE. 30234aa623Sad */ 31234aa623Sad 32234aa623Sad#include "atomic_op_asm.h" 33234aa623Sad 34234aa623Sad .text 35e8a22c65Smatt .set noreorder 36234aa623Sad 376740bb54SchsLEAF(_membar_sync) 38234aa623Sad j ra 3976b37851Sskrll BDSYNC 40234aa623SadEND(_membar_sync) 41*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_sync,_membar_sync) 42*4a6459a8Sriastradh 43*4a6459a8SriastradhSTRONG_ALIAS(_membar_enter,_membar_sync) 44*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_enter,_membar_sync) 45234aa623Sad 46ac748598Smatt#ifdef __OCTEON__ 47*4a6459a8Sriastradh 484f8ce3b3Sriastradh/* 49*4a6459a8Sriastradh * cnMIPS guarantees load-before-load/store ordering without any 50*4a6459a8Sriastradh * barriers. So the only barriers we need are store-before-load (sync) 51*4a6459a8Sriastradh * and store-before-store (syncw, i.e., sync 4). See Table 2-32 52*4a6459a8Sriastradh * `Execution Ordering Rules' on p. 104 of Cavium OCTEON III CN78XX 53*4a6459a8Sriastradh * Hardware Reference Manual, CN78XX-HM-0.99E, September 2014: 544f8ce3b3Sriastradh * 55*4a6459a8Sriastradh * First Operation DLD [load instruction to a physical 56*4a6459a8Sriastradh * address that is L2/DRAM] 57*4a6459a8Sriastradh * Second Operation Any 58*4a6459a8Sriastradh * Execution Ordering Comments 594f8ce3b3Sriastradh * 60*4a6459a8Sriastradh * The second operation cannot appear to execute before 61*4a6459a8Sriastradh * the first (DLD) operation, regardless of the presence 62*4a6459a8Sriastradh * or absence of SYNC* instructions. 63*4a6459a8Sriastradh * 64*4a6459a8Sriastradh * Note: I'm not sure if this applies to earlier cnMIPS -- can't find 65*4a6459a8Sriastradh * it in the Cavium Networks OCTEON Plus CN50XX Hardware Reference 66*4a6459a8Sriastradh * Manual CN50XX-HM-0.99E, July 2008. Experimentally, on an erlite3 67*4a6459a8Sriastradh * (Cavium Octeon CN5020-500), I can easily detect reordering of 68*4a6459a8Sriastradh * store-before-store and store-before-load, but I haven't been able to 69*4a6459a8Sriastradh * detect any reordering of load-before-load or load-before-store. 70*4a6459a8Sriastradh * 71*4a6459a8Sriastradh * Note: On early cnMIPS (CN3xxx), there is an erratum which sometimes 72*4a6459a8Sriastradh * requires issuing two syncw's in a row. I don't know the details -- 73*4a6459a8Sriastradh * don't have documentation -- and in Linux it is only used for I/O 74*4a6459a8Sriastradh * purposes. 75*4a6459a8Sriastradh * 76*4a6459a8Sriastradh * Currently we don't build kernels that work on both Octeon and 77*4a6459a8Sriastradh * non-Octeon MIPS CPUs, so none of this is done with binary patching. 78*4a6459a8Sriastradh * For userlands we could use a separate shared library on Octeon with 79*4a6459a8Sriastradh * ld.so.conf to override the symbols with cheaper definitions, but we 80*4a6459a8Sriastradh * don't do that now. 814f8ce3b3Sriastradh */ 82*4a6459a8Sriastradh 83*4a6459a8SriastradhLEAF(_membar_acquire) 84*4a6459a8Sriastradh j ra 85*4a6459a8Sriastradh nop 86*4a6459a8SriastradhEND(_membar_acquire) 87*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_acquire,_membar_acquire) 88*4a6459a8Sriastradh 89*4a6459a8SriastradhSTRONG_ALIAS(_membar_consumer,_membar_acquire) 90*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_consumer,_membar_acquire) 91*4a6459a8Sriastradh 92*4a6459a8SriastradhLEAF(_membar_release) 93ac748598Smatt j ra 94ac748598Smatt syncw 954f8ce3b3SriastradhEND(_membar_release) 964f8ce3b3SriastradhATOMIC_OP_ALIAS(membar_release,_membar_release) 97*4a6459a8Sriastradh 98*4a6459a8SriastradhSTRONG_ALIAS(_membar_exit,_membar_release) 99*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_exit,_membar_release) 100*4a6459a8Sriastradh 1014f8ce3b3SriastradhSTRONG_ALIAS(_membar_producer,_membar_release) 102*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_producer,_membar_release) 103*4a6459a8Sriastradh 104*4a6459a8Sriastradh#else /* !__OCTEON__ */ 105*4a6459a8Sriastradh 106*4a6459a8SriastradhSTRONG_ALIAS(_membar_acquire,_membar_sync) 107*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_acquire,_membar_sync) 1084f8ce3b3SriastradhSTRONG_ALIAS(_membar_release,_membar_sync) 109*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_release,_membar_sync) 110*4a6459a8SriastradhSTRONG_ALIAS(_membar_exit,_membar_sync) 111*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_exit,_membar_sync) 112234aa623SadSTRONG_ALIAS(_membar_consumer,_membar_sync) 113*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_consumer,_membar_sync) 114*4a6459a8SriastradhSTRONG_ALIAS(_membar_producer,_membar_sync) 115*4a6459a8SriastradhATOMIC_OP_ALIAS(membar_producer,_membar_sync) 116*4a6459a8Sriastradh 117*4a6459a8Sriastradh#endif 118