2000-09-29 13:46:07 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MACHINE_CPUFUNC_H_
|
|
|
|
#define _MACHINE_CPUFUNC_H_
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2001-09-15 12:30:56 +00:00
|
|
|
#include <machine/ia64_cpu.h>
|
2002-05-19 04:42:19 +00:00
|
|
|
#include <machine/vmparam.h>
|
2000-09-29 13:46:07 +00:00
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
struct thread;
|
2001-12-18 00:27:18 +00:00
|
|
|
|
2000-09-29 13:46:07 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
breakpoint(void)
|
|
|
|
{
|
|
|
|
__asm __volatile("break 0x80100"); /* XXX use linux value */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-04-29 09:50:03 +00:00
|
|
|
extern uint64_t ia64_port_base;
|
|
|
|
#define __MEMIO_ADDR(x) (__volatile void*)(IA64_PHYS_TO_RR6(x))
|
|
|
|
#define __PIO_ADDR(x) (__volatile void*)(ia64_port_base | \
|
|
|
|
(((x) & 0xFFFC) << 10) | ((x) & 0xFFF))
|
2001-09-15 12:30:56 +00:00
|
|
|
|
2003-04-29 09:50:03 +00:00
|
|
|
/*
|
|
|
|
* I/O port reads with ia32 semantics.
|
|
|
|
*/
|
|
|
|
static __inline uint8_t
|
|
|
|
inb(unsigned int port)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
__volatile uint8_t *p;
|
|
|
|
uint8_t v;
|
|
|
|
p = __PIO_ADDR(port);
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
v = *p;
|
|
|
|
ia64_mf_a();
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
return (v);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
2003-04-29 09:50:03 +00:00
|
|
|
static __inline uint16_t
|
|
|
|
inw(unsigned int port)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
__volatile uint16_t *p;
|
|
|
|
uint16_t v;
|
|
|
|
p = __PIO_ADDR(port);
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
v = *p;
|
|
|
|
ia64_mf_a();
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
return (v);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
2003-04-29 09:50:03 +00:00
|
|
|
static __inline uint32_t
|
|
|
|
inl(unsigned int port)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
volatile uint32_t *p;
|
|
|
|
uint32_t v;
|
|
|
|
p = __PIO_ADDR(port);
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
v = *p;
|
|
|
|
ia64_mf_a();
|
2001-09-15 12:30:56 +00:00
|
|
|
ia64_mf();
|
2003-04-29 09:50:03 +00:00
|
|
|
return (v);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
insb(unsigned int port, void *addr, size_t count)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
uint8_t *buf = addr;
|
2000-09-29 13:46:07 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
*buf++ = inb(port);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
insw(unsigned int port, void *addr, size_t count)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
uint16_t *buf = addr;
|
2000-09-29 13:46:07 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
*buf++ = inw(port);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
insl(unsigned int port, void *addr, size_t count)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
uint32_t *buf = addr;
|
2000-09-29 13:46:07 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
*buf++ = inl(port);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outb(unsigned int port, uint8_t data)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
volatile uint8_t *p;
|
|
|
|
p = __PIO_ADDR(port);
|
|
|
|
ia64_mf();
|
2001-09-22 19:51:18 +00:00
|
|
|
*p = data;
|
2003-04-29 09:50:03 +00:00
|
|
|
ia64_mf_a();
|
2001-09-22 19:51:18 +00:00
|
|
|
ia64_mf();
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outw(unsigned int port, uint16_t data)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
volatile uint16_t *p;
|
|
|
|
p = __PIO_ADDR(port);
|
|
|
|
ia64_mf();
|
2001-09-22 19:51:18 +00:00
|
|
|
*p = data;
|
2003-04-29 09:50:03 +00:00
|
|
|
ia64_mf_a();
|
2001-09-22 19:51:18 +00:00
|
|
|
ia64_mf();
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outl(unsigned int port, uint32_t data)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
volatile uint32_t *p;
|
|
|
|
p = __PIO_ADDR(port);
|
|
|
|
ia64_mf();
|
2001-09-22 19:51:18 +00:00
|
|
|
*p = data;
|
2003-04-29 09:50:03 +00:00
|
|
|
ia64_mf_a();
|
2001-09-22 19:51:18 +00:00
|
|
|
ia64_mf();
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
2001-10-06 09:31:43 +00:00
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outsb(unsigned int port, const void *addr, size_t count)
|
2001-10-06 09:31:43 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
const uint8_t *buf = addr;
|
2001-10-06 09:31:43 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
outb(port, *buf++);
|
2001-10-06 09:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outsw(unsigned int port, const void *addr, size_t count)
|
2001-10-06 09:31:43 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
const uint16_t *buf = addr;
|
2001-10-06 09:31:43 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
outw(port, *buf++);
|
2001-10-06 09:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2003-04-29 09:50:03 +00:00
|
|
|
outsl(unsigned int port, const void *addr, size_t count)
|
2001-10-06 09:31:43 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
const uint32_t *buf = addr;
|
2001-10-06 09:31:43 +00:00
|
|
|
while (count--)
|
2003-04-29 09:50:03 +00:00
|
|
|
outl(port, *buf++);
|
2001-10-06 09:31:43 +00:00
|
|
|
}
|
|
|
|
|
2000-09-29 13:46:07 +00:00
|
|
|
static __inline void
|
|
|
|
disable_intr(void)
|
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
__asm __volatile ("rsm psr.i");
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
enable_intr(void)
|
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
__asm __volatile ("ssm psr.i;; srlz.d");
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 09:50:11 +00:00
|
|
|
static __inline register_t
|
2002-03-20 10:00:05 +00:00
|
|
|
intr_disable(void)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2002-03-21 09:50:11 +00:00
|
|
|
register_t psr;
|
2003-04-29 09:50:03 +00:00
|
|
|
__asm __volatile ("mov %0=psr;;" : "=r"(psr));
|
2001-03-28 02:31:54 +00:00
|
|
|
disable_intr();
|
|
|
|
return (psr);
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2002-03-20 17:28:40 +00:00
|
|
|
intr_restore(critical_t psr)
|
2000-09-29 13:46:07 +00:00
|
|
|
{
|
2003-04-29 09:50:03 +00:00
|
|
|
__asm __volatile ("mov psr.l=%0;; srlz.d" :: "r"(psr));
|
2000-09-29 13:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
#endif /* !_MACHINE_CPUFUNC_H_ */
|