1*a570f712Smacallan /* $NetBSD: sxvar.h,v 1.5 2023/06/13 10:09:31 macallan Exp $ */
23b60920aSmacallan
33b60920aSmacallan /*-
43b60920aSmacallan * Copyright (c) 2013 The NetBSD Foundation, Inc.
53b60920aSmacallan * All rights reserved.
63b60920aSmacallan *
73b60920aSmacallan * This code is derived from software contributed to The NetBSD Foundation
83b60920aSmacallan * by Michael Lorenz.
93b60920aSmacallan *
103b60920aSmacallan * Redistribution and use in source and binary forms, with or without
113b60920aSmacallan * modification, are permitted provided that the following conditions
123b60920aSmacallan * are met:
133b60920aSmacallan * 1. Redistributions of source code must retain the above copyright
143b60920aSmacallan * notice, this list of conditions and the following disclaimer.
153b60920aSmacallan * 2. Redistributions in binary form must reproduce the above copyright
163b60920aSmacallan * notice, this list of conditions and the following disclaimer in the
173b60920aSmacallan * documentation and/or other materials provided with the distribution.
183b60920aSmacallan *
193b60920aSmacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203b60920aSmacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213b60920aSmacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223b60920aSmacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233b60920aSmacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243b60920aSmacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253b60920aSmacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263b60920aSmacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273b60920aSmacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283b60920aSmacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293b60920aSmacallan * POSSIBILITY OF SUCH DAMAGE.
303b60920aSmacallan */
313b60920aSmacallan
323b60920aSmacallan #ifndef SXVAR_H
333b60920aSmacallan #define SXVAR_H
343b60920aSmacallan
35*a570f712Smacallan #include <sparc/dev/sxreg.h>
36*a570f712Smacallan
373b60920aSmacallan struct sx_softc {
383b60920aSmacallan device_t sc_dev;
393b60920aSmacallan bus_addr_t sc_uregs;
403b60920aSmacallan bus_space_tag_t sc_tag;
413b60920aSmacallan bus_space_handle_t sc_regh;
42*a570f712Smacallan int sc_cnt;
433b60920aSmacallan };
443b60920aSmacallan
453b60920aSmacallan static inline void
sx_write(struct sx_softc * sc,int addr,uint32_t val)463b60920aSmacallan sx_write(struct sx_softc *sc, int addr, uint32_t val)
473b60920aSmacallan {
483b60920aSmacallan bus_space_write_4(sc->sc_tag, sc->sc_regh, addr, val);
493b60920aSmacallan }
503b60920aSmacallan
51a825263fSmacallan static inline uint32_t
sx_read(struct sx_softc * sc,int addr)52a825263fSmacallan sx_read(struct sx_softc *sc, int addr)
53a825263fSmacallan {
54a825263fSmacallan return bus_space_read_4(sc->sc_tag, sc->sc_regh, addr);
55a825263fSmacallan }
56a825263fSmacallan
57*a570f712Smacallan /*
58*a570f712Smacallan * to be used before issuing SX instructions
59*a570f712Smacallan * this will periodically allow the instruction queue to drain in order
60*a570f712Smacallan * to avoid excessive MBus relinquish & retry cycles during long SX ops
61*a570f712Smacallan * which may cause us to lose interrupts
62*a570f712Smacallan */
63*a570f712Smacallan static inline void
sx_wait(struct sx_softc * sc)64*a570f712Smacallan sx_wait(struct sx_softc *sc)
65*a570f712Smacallan {
66*a570f712Smacallan uint32_t reg;
67*a570f712Smacallan if (sc->sc_cnt > 6) {
68*a570f712Smacallan do {
69*a570f712Smacallan reg = bus_space_read_4(sc->sc_tag, sc->sc_regh,
70*a570f712Smacallan SX_CONTROL_STATUS);
71*a570f712Smacallan } while ((reg & SX_MT) == 0);
72*a570f712Smacallan sc->sc_cnt = 0;
73*a570f712Smacallan } else
74*a570f712Smacallan sc->sc_cnt++;
75*a570f712Smacallan }
76*a570f712Smacallan
7704a1595bSmacallan void sx_dump(void);
7804a1595bSmacallan
793b60920aSmacallan #endif
80