cpufunc.h revision 1.4
11.4Sjruoho/*	$NetBSD: cpufunc.h,v 1.4 2010/07/24 09:35:36 jruoho Exp $	*/
21.1Scherry
31.1Scherry/*-
41.1Scherry * Copyright (c) 1998 Doug Rabson
51.1Scherry * All rights reserved.
61.1Scherry *
71.1Scherry * Redistribution and use in source and binary forms, with or without
81.1Scherry * modification, are permitted provided that the following conditions
91.1Scherry * are met:
101.1Scherry * 1. Redistributions of source code must retain the above copyright
111.1Scherry *    notice, this list of conditions and the following disclaimer.
121.1Scherry * 2. Redistributions in binary form must reproduce the above copyright
131.1Scherry *    notice, this list of conditions and the following disclaimer in the
141.1Scherry *    documentation and/or other materials provided with the distribution.
151.1Scherry *
161.1Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171.1Scherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181.1Scherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191.1Scherry * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201.1Scherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211.1Scherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221.1Scherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231.1Scherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241.1Scherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251.1Scherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261.1Scherry * SUCH DAMAGE.
271.1Scherry *
281.1Scherry * $FreeBSD$
291.1Scherry */
301.1Scherry
311.1Scherry#ifndef _MACHINE_CPUFUNC_H_
321.1Scherry#define _MACHINE_CPUFUNC_H_
331.1Scherry
341.1Scherry#ifdef _KERNEL
351.1Scherry
361.1Scherry#include <sys/types.h>
371.1Scherry#include <machine/ia64_cpu.h>
381.1Scherry#include <machine/vmparam.h>
391.1Scherry
401.1Scherrystruct thread;
411.1Scherry
421.1Scherry#define	IA64_FIXED_BREAK	0x84B5D
431.1Scherry
441.1Scherry#ifdef __GNUC__
451.1Scherry
461.1Scherrystatic __inline void
471.1Scherrybreakpoint(void)
481.1Scherry{
491.3Skiyohara
501.1Scherry	__asm __volatile("break.m %0" :: "i"(IA64_FIXED_BREAK));
511.1Scherry}
521.1Scherry
531.1Scherry#define	HAVE_INLINE_FFS
541.1Scherry#define	ffs(x)	__builtin_ffs(x)
551.1Scherry
561.1Scherry#endif
571.1Scherry
581.1Scherryextern uint64_t ia64_port_base;
591.1Scherry#define	__MEMIO_ADDR(x)		(__volatile void*)(IA64_PHYS_TO_RR6(x))
601.1Scherry#define	__PIO_ADDR(x)		(__volatile void*)(ia64_port_base |	\
611.1Scherry	(((x) & 0xFFFC) << 10) | ((x) & 0xFFF))
621.1Scherry
631.1Scherry/*
641.1Scherry * I/O port reads with ia32 semantics.
651.1Scherry */
661.1Scherrystatic __inline uint8_t
671.1Scherryinb(unsigned int port)
681.1Scherry{
691.1Scherry	__volatile uint8_t *p;
701.1Scherry	uint8_t v;
711.1Scherry	p = __PIO_ADDR(port);
721.1Scherry	ia64_mf();
731.1Scherry	v = *p;
741.1Scherry	ia64_mf_a();
751.1Scherry	ia64_mf();
761.3Skiyohara	return v;
771.1Scherry}
781.1Scherry
791.1Scherrystatic __inline uint16_t
801.1Scherryinw(unsigned int port)
811.1Scherry{
821.1Scherry	__volatile uint16_t *p;
831.1Scherry	uint16_t v;
841.3Skiyohara
851.1Scherry	p = __PIO_ADDR(port);
861.1Scherry	ia64_mf();
871.1Scherry	v = *p;
881.1Scherry	ia64_mf_a();
891.1Scherry	ia64_mf();
901.3Skiyohara	return v;
911.1Scherry}
921.1Scherry
931.1Scherrystatic __inline uint32_t
941.1Scherryinl(unsigned int port)
951.1Scherry{
961.1Scherry	volatile uint32_t *p;
971.1Scherry	uint32_t v;
981.3Skiyohara
991.1Scherry	p = __PIO_ADDR(port);
1001.1Scherry	ia64_mf();
1011.1Scherry	v = *p;
1021.1Scherry	ia64_mf_a();
1031.1Scherry	ia64_mf();
1041.3Skiyohara	return v;
1051.1Scherry}
1061.1Scherry
1071.1Scherrystatic __inline void
1081.1Scherryinsb(unsigned int port, void *addr, size_t count)
1091.1Scherry{
1101.1Scherry	uint8_t *buf = addr;
1111.3Skiyohara
1121.1Scherry	while (count--)
1131.1Scherry		*buf++ = inb(port);
1141.1Scherry}
1151.1Scherry
1161.1Scherrystatic __inline void
1171.1Scherryinsw(unsigned int port, void *addr, size_t count)
1181.1Scherry{
1191.1Scherry	uint16_t *buf = addr;
1201.3Skiyohara
1211.1Scherry	while (count--)
1221.1Scherry		*buf++ = inw(port);
1231.1Scherry}
1241.1Scherry
1251.1Scherrystatic __inline void
1261.1Scherryinsl(unsigned int port, void *addr, size_t count)
1271.1Scherry{
1281.1Scherry	uint32_t *buf = addr;
1291.3Skiyohara
1301.1Scherry	while (count--)
1311.1Scherry		*buf++ = inl(port);
1321.1Scherry}
1331.1Scherry
1341.1Scherrystatic __inline void
1351.1Scherryoutb(unsigned int port, uint8_t data)
1361.1Scherry{
1371.1Scherry	volatile uint8_t *p;
1381.3Skiyohara
1391.1Scherry	p = __PIO_ADDR(port);
1401.1Scherry	ia64_mf();
1411.1Scherry	*p = data;
1421.1Scherry	ia64_mf_a();
1431.1Scherry	ia64_mf();
1441.1Scherry}
1451.1Scherry
1461.1Scherrystatic __inline void
1471.1Scherryoutw(unsigned int port, uint16_t data)
1481.1Scherry{
1491.1Scherry	volatile uint16_t *p;
1501.3Skiyohara
1511.1Scherry	p = __PIO_ADDR(port);
1521.1Scherry	ia64_mf();
1531.1Scherry	*p = data;
1541.1Scherry	ia64_mf_a();
1551.1Scherry	ia64_mf();
1561.1Scherry}
1571.1Scherry
1581.1Scherrystatic __inline void
1591.1Scherryoutl(unsigned int port, uint32_t data)
1601.1Scherry{
1611.1Scherry	volatile uint32_t *p;
1621.3Skiyohara
1631.1Scherry	p = __PIO_ADDR(port);
1641.1Scherry	ia64_mf();
1651.1Scherry	*p = data;
1661.1Scherry	ia64_mf_a();
1671.1Scherry	ia64_mf();
1681.1Scherry}
1691.1Scherry
1701.1Scherrystatic __inline void
1711.1Scherryoutsb(unsigned int port, const void *addr, size_t count)
1721.1Scherry{
1731.1Scherry	const uint8_t *buf = addr;
1741.3Skiyohara
1751.1Scherry	while (count--)
1761.1Scherry		outb(port, *buf++);
1771.1Scherry}
1781.1Scherry
1791.1Scherrystatic __inline void
1801.1Scherryoutsw(unsigned int port, const void *addr, size_t count)
1811.1Scherry{
1821.1Scherry	const uint16_t *buf = addr;
1831.3Skiyohara
1841.1Scherry	while (count--)
1851.1Scherry		outw(port, *buf++);
1861.1Scherry}
1871.1Scherry
1881.1Scherrystatic __inline void
1891.1Scherryoutsl(unsigned int port, const void *addr, size_t count)
1901.1Scherry{
1911.1Scherry	const uint32_t *buf = addr;
1921.3Skiyohara
1931.1Scherry	while (count--)
1941.1Scherry		outl(port, *buf++);
1951.1Scherry}
1961.1Scherry
1971.1Scherrystatic __inline void
1981.1Scherrydisable_intr(void)
1991.1Scherry{
2001.3Skiyohara
2011.1Scherry	__asm __volatile ("rsm psr.i");
2021.1Scherry}
2031.1Scherry
2041.1Scherrystatic __inline void
2051.1Scherryenable_intr(void)
2061.1Scherry{
2071.3Skiyohara
2081.1Scherry	__asm __volatile ("ssm psr.i;; srlz.d");
2091.1Scherry}
2101.1Scherry
2111.1Scherrystatic __inline register_t
2121.1Scherryintr_disable(void)
2131.1Scherry{
2141.1Scherry	register_t psr;
2151.3Skiyohara
2161.1Scherry	__asm __volatile ("mov %0=psr;;" : "=r"(psr));
2171.1Scherry	disable_intr();
2181.3Skiyohara	return (psr & IA64_PSR_I) ? 1 : 0;
2191.1Scherry}
2201.1Scherry
2211.1Scherrystatic __inline void
2221.1Scherryintr_restore(register_t ie)
2231.1Scherry{
2241.3Skiyohara
2251.1Scherry	if (ie)
2261.1Scherry		enable_intr();
2271.1Scherry}
2281.1Scherry
2291.1Scherry#endif /* _KERNEL */
2301.1Scherry
2311.1Scherry#endif /* !_MACHINE_CPUFUNC_H_ */
232