xref: /netbsd-src/sys/arch/hpcmips/include/bus_machdep.h (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: bus_machdep.h,v 1.3 2008/04/28 20:23:21 martin Exp $	*/
21d1d5c87Stakemura 
31d1d5c87Stakemura /*-
41d1d5c87Stakemura  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
51d1d5c87Stakemura  * All rights reserved.
61d1d5c87Stakemura  *
71d1d5c87Stakemura  * This code is derived from software contributed to The NetBSD Foundation
81d1d5c87Stakemura  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
91d1d5c87Stakemura  * NASA Ames Research Center.
101d1d5c87Stakemura  *
111d1d5c87Stakemura  * Redistribution and use in source and binary forms, with or without
121d1d5c87Stakemura  * modification, are permitted provided that the following conditions
131d1d5c87Stakemura  * are met:
141d1d5c87Stakemura  * 1. Redistributions of source code must retain the above copyright
151d1d5c87Stakemura  *    notice, this list of conditions and the following disclaimer.
161d1d5c87Stakemura  * 2. Redistributions in binary form must reproduce the above copyright
171d1d5c87Stakemura  *    notice, this list of conditions and the following disclaimer in the
181d1d5c87Stakemura  *    documentation and/or other materials provided with the distribution.
191d1d5c87Stakemura  *
201d1d5c87Stakemura  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
211d1d5c87Stakemura  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
221d1d5c87Stakemura  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
231d1d5c87Stakemura  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
241d1d5c87Stakemura  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
251d1d5c87Stakemura  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
261d1d5c87Stakemura  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271d1d5c87Stakemura  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
281d1d5c87Stakemura  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
291d1d5c87Stakemura  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
301d1d5c87Stakemura  * POSSIBILITY OF SUCH DAMAGE.
311d1d5c87Stakemura  */
321d1d5c87Stakemura 
33c71c45f6She #ifndef _HPCMIPS_BUS_MACHDEP_H_
34c71c45f6She #define _HPCMIPS_BUS_MACHDEP_H_
351d1d5c87Stakemura 
361d1d5c87Stakemura #ifdef BUS_SPACE_DEBUG
371d1d5c87Stakemura #include <sys/systm.h> /* for printf() prototype */
381d1d5c87Stakemura /*
391d1d5c87Stakemura  * Macros for checking the aligned-ness of pointers passed to bus
401d1d5c87Stakemura  * space ops.  Strict alignment is required by the MIPS architecture,
411d1d5c87Stakemura  * and a trap will occur if unaligned access is performed.  These
421d1d5c87Stakemura  * may aid in the debugging of a broken device driver by displaying
431d1d5c87Stakemura  * useful information about the problem.
441d1d5c87Stakemura  */
451d1d5c87Stakemura #define	__BUS_SPACE_ALIGNED_ADDRESS(p, t)				\
461d1d5c87Stakemura 	((((u_long)(p)) & (sizeof(t)-1)) == 0)
471d1d5c87Stakemura 
481d1d5c87Stakemura #define	__BUS_SPACE_ADDRESS_SANITY(p, t, d)				\
491d1d5c87Stakemura ({									\
501d1d5c87Stakemura 	if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) {			\
511d1d5c87Stakemura 		printf("%s 0x%lx not aligned to %d bytes %s:%d\n",	\
521d1d5c87Stakemura 		    d, (u_long)(p), sizeof(t), __FILE__, __LINE__);	\
531d1d5c87Stakemura 	}								\
541d1d5c87Stakemura 	(void) 0;							\
551d1d5c87Stakemura })
561d1d5c87Stakemura 
571d1d5c87Stakemura #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
581d1d5c87Stakemura #else
591d1d5c87Stakemura #define	__BUS_SPACE_ADDRESS_SANITY(p,t,d)	(void) 0
601d1d5c87Stakemura #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
611d1d5c87Stakemura #endif /* BUS_SPACE_DEBUG */
621d1d5c87Stakemura 
63c71c45f6She #endif /* _HPCMIPS_BUS_MACHDEP_H_ */
64