cpufunc.h revision 1.1
11.1Scherry/*	$NetBSD: cpufunc.h,v 1.1 2006/04/07 14:21:18 cherry 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.1Scherry	__asm __volatile("break.m %0" :: "i"(IA64_FIXED_BREAK));
501.1Scherry}
511.1Scherry
521.1Scherry#define	HAVE_INLINE_FFS
531.1Scherry#define	ffs(x)	__builtin_ffs(x)
541.1Scherry
551.1Scherry#endif
561.1Scherry
571.1Scherryextern uint64_t ia64_port_base;
581.1Scherry#define	__MEMIO_ADDR(x)		(__volatile void*)(IA64_PHYS_TO_RR6(x))
591.1Scherry#define	__PIO_ADDR(x)		(__volatile void*)(ia64_port_base |	\
601.1Scherry	(((x) & 0xFFFC) << 10) | ((x) & 0xFFF))
611.1Scherry
621.1Scherry/*
631.1Scherry * I/O port reads with ia32 semantics.
641.1Scherry */
651.1Scherrystatic __inline uint8_t
661.1Scherryinb(unsigned int port)
671.1Scherry{
681.1Scherry	__volatile uint8_t *p;
691.1Scherry	uint8_t v;
701.1Scherry	p = __PIO_ADDR(port);
711.1Scherry	ia64_mf();
721.1Scherry	v = *p;
731.1Scherry	ia64_mf_a();
741.1Scherry	ia64_mf();
751.1Scherry	return (v);
761.1Scherry}
771.1Scherry
781.1Scherrystatic __inline uint16_t
791.1Scherryinw(unsigned int port)
801.1Scherry{
811.1Scherry	__volatile uint16_t *p;
821.1Scherry	uint16_t v;
831.1Scherry	p = __PIO_ADDR(port);
841.1Scherry	ia64_mf();
851.1Scherry	v = *p;
861.1Scherry	ia64_mf_a();
871.1Scherry	ia64_mf();
881.1Scherry	return (v);
891.1Scherry}
901.1Scherry
911.1Scherrystatic __inline uint32_t
921.1Scherryinl(unsigned int port)
931.1Scherry{
941.1Scherry	volatile uint32_t *p;
951.1Scherry	uint32_t v;
961.1Scherry	p = __PIO_ADDR(port);
971.1Scherry	ia64_mf();
981.1Scherry	v = *p;
991.1Scherry	ia64_mf_a();
1001.1Scherry	ia64_mf();
1011.1Scherry	return (v);
1021.1Scherry}
1031.1Scherry
1041.1Scherrystatic __inline void
1051.1Scherryinsb(unsigned int port, void *addr, size_t count)
1061.1Scherry{
1071.1Scherry	uint8_t *buf = addr;
1081.1Scherry	while (count--)
1091.1Scherry		*buf++ = inb(port);
1101.1Scherry}
1111.1Scherry
1121.1Scherrystatic __inline void
1131.1Scherryinsw(unsigned int port, void *addr, size_t count)
1141.1Scherry{
1151.1Scherry	uint16_t *buf = addr;
1161.1Scherry	while (count--)
1171.1Scherry		*buf++ = inw(port);
1181.1Scherry}
1191.1Scherry
1201.1Scherrystatic __inline void
1211.1Scherryinsl(unsigned int port, void *addr, size_t count)
1221.1Scherry{
1231.1Scherry	uint32_t *buf = addr;
1241.1Scherry	while (count--)
1251.1Scherry		*buf++ = inl(port);
1261.1Scherry}
1271.1Scherry
1281.1Scherrystatic __inline void
1291.1Scherryoutb(unsigned int port, uint8_t data)
1301.1Scherry{
1311.1Scherry	volatile uint8_t *p;
1321.1Scherry	p = __PIO_ADDR(port);
1331.1Scherry	ia64_mf();
1341.1Scherry	*p = data;
1351.1Scherry	ia64_mf_a();
1361.1Scherry	ia64_mf();
1371.1Scherry}
1381.1Scherry
1391.1Scherrystatic __inline void
1401.1Scherryoutw(unsigned int port, uint16_t data)
1411.1Scherry{
1421.1Scherry	volatile uint16_t *p;
1431.1Scherry	p = __PIO_ADDR(port);
1441.1Scherry	ia64_mf();
1451.1Scherry	*p = data;
1461.1Scherry	ia64_mf_a();
1471.1Scherry	ia64_mf();
1481.1Scherry}
1491.1Scherry
1501.1Scherrystatic __inline void
1511.1Scherryoutl(unsigned int port, uint32_t data)
1521.1Scherry{
1531.1Scherry	volatile uint32_t *p;
1541.1Scherry	p = __PIO_ADDR(port);
1551.1Scherry	ia64_mf();
1561.1Scherry	*p = data;
1571.1Scherry	ia64_mf_a();
1581.1Scherry	ia64_mf();
1591.1Scherry}
1601.1Scherry
1611.1Scherrystatic __inline void
1621.1Scherryoutsb(unsigned int port, const void *addr, size_t count)
1631.1Scherry{
1641.1Scherry	const uint8_t *buf = addr;
1651.1Scherry	while (count--)
1661.1Scherry		outb(port, *buf++);
1671.1Scherry}
1681.1Scherry
1691.1Scherrystatic __inline void
1701.1Scherryoutsw(unsigned int port, const void *addr, size_t count)
1711.1Scherry{
1721.1Scherry	const uint16_t *buf = addr;
1731.1Scherry	while (count--)
1741.1Scherry		outw(port, *buf++);
1751.1Scherry}
1761.1Scherry
1771.1Scherrystatic __inline void
1781.1Scherryoutsl(unsigned int port, const void *addr, size_t count)
1791.1Scherry{
1801.1Scherry	const uint32_t *buf = addr;
1811.1Scherry	while (count--)
1821.1Scherry		outl(port, *buf++);
1831.1Scherry}
1841.1Scherry
1851.1Scherrystatic __inline void
1861.1Scherrydisable_intr(void)
1871.1Scherry{
1881.1Scherry	__asm __volatile ("rsm psr.i");
1891.1Scherry}
1901.1Scherry
1911.1Scherrystatic __inline void
1921.1Scherryenable_intr(void)
1931.1Scherry{
1941.1Scherry	__asm __volatile ("ssm psr.i;; srlz.d");
1951.1Scherry}
1961.1Scherry
1971.1Scherrystatic __inline register_t
1981.1Scherryintr_disable(void)
1991.1Scherry{
2001.1Scherry	register_t psr;
2011.1Scherry	__asm __volatile ("mov %0=psr;;" : "=r"(psr));
2021.1Scherry	disable_intr();
2031.1Scherry	return ((psr & IA64_PSR_I) ? 1 : 0);
2041.1Scherry}
2051.1Scherry
2061.1Scherrystatic __inline void
2071.1Scherryintr_restore(register_t ie)
2081.1Scherry{
2091.1Scherry	if (ie)
2101.1Scherry		enable_intr();
2111.1Scherry}
2121.1Scherry
2131.1Scherry#endif /* _KERNEL */
2141.1Scherry
2151.1Scherry#endif /* !_MACHINE_CPUFUNC_H_ */
216