sys_machdep.c revision 1.13
11.13Sdsl/*	$NetBSD: sys_machdep.c,v 1.13 2007/12/20 23:02:40 dsl Exp $	*/
21.1Schs
31.1Schs/*
41.1Schs * Copyright (c) 1982, 1986, 1993
51.1Schs *	The Regents of the University of California.  All rights reserved.
61.1Schs *
71.1Schs * Redistribution and use in source and binary forms, with or without
81.1Schs * modification, are permitted provided that the following conditions
91.1Schs * are met:
101.1Schs * 1. Redistributions of source code must retain the above copyright
111.1Schs *    notice, this list of conditions and the following disclaimer.
121.1Schs * 2. Redistributions in binary form must reproduce the above copyright
131.1Schs *    notice, this list of conditions and the following disclaimer in the
141.1Schs *    documentation and/or other materials provided with the distribution.
151.4Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Schs *    may be used to endorse or promote products derived from this software
171.1Schs *    without specific prior written permission.
181.1Schs *
191.1Schs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Schs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Schs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Schs * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Schs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Schs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Schs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Schs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Schs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Schs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Schs * SUCH DAMAGE.
301.1Schs *
311.1Schs *	@(#)sys_machdep.c	8.2 (Berkeley) 1/13/94
321.1Schs */
331.1Schs
341.1Schs#include <sys/cdefs.h>
351.1Schs__KERNEL_RCSID(0, "$NetBSD");
361.1Schs
371.1Schs#include "opt_compat_hpux.h"
381.1Schs
391.1Schs#include <sys/param.h>
401.1Schs#include <sys/proc.h>
411.1Schs#include <sys/mount.h>
421.1Schs
431.1Schs#include <uvm/uvm_extern.h>
441.1Schs
451.1Schs#include <sys/syscallargs.h>
461.1Schs
471.1Schs#include <machine/cpu.h>
481.1Schs#include <m68k/cacheops.h>
491.1Schs
501.1Schs/* XXX should be in an include file somewhere */
511.1Schs#define CC_PURGE	1
521.1Schs#define CC_FLUSH	2
531.1Schs#define CC_IPURGE	4
541.1Schs#define CC_EXTPURGE	0x80000000
551.1Schs/* XXX end should be */
561.1Schs
571.1Schs/*
581.1Schs * Note that what we do here on 040/060 for BSD is different than for HP-UX.
591.1Schs *
601.3Sthorpej * In 'pux they either act on a line (len == 16), a page (len == PAGE_SIZE)
611.1Schs * or the whole cache (len == anything else).
621.1Schs *
631.1Schs * In BSD we attempt to be more optimal when acting on "odd" sizes.
641.3Sthorpej * For lengths up to 1024 we do all affected lines, up to 2*PAGE_SIZE we
651.1Schs * do pages, above that we do the entire cache.
661.1Schs */
671.1Schs/*ARGSUSED1*/
681.1Schsint
691.5Sthorpejcachectl1(u_long req, vaddr_t addr, size_t len, struct proc *p)
701.1Schs{
711.1Schs	int error = 0;
721.1Schs
731.1Schs#if defined(M68040) || defined(M68060)
741.1Schs	if (mmutype == MMU_68040) {
751.1Schs		int inc = 0;
761.10Sthorpej		bool doall = false;
771.1Schs		paddr_t pa = 0;
781.1Schs		vaddr_t end = 0;
791.1Schs#ifdef COMPAT_HPUX
801.1Schs		extern struct emul emul_hpux;
811.1Schs
821.1Schs		if ((p->p_emul == &emul_hpux) &&
831.3Sthorpej		    len != 16 && len != PAGE_SIZE)
841.1Schs			doall = 1;
851.1Schs#endif
861.1Schs
871.1Schs		if (addr == 0 ||
881.1Schs#if defined(M68060)
891.1Schs		    (cputype == CPU_68040 && req & CC_IPURGE) ||
901.1Schs#else
911.1Schs		    (req & CC_IPURGE) ||
921.1Schs#endif
931.3Sthorpej		    ((req & ~CC_EXTPURGE) != CC_PURGE && len > 2 * PAGE_SIZE))
941.1Schs			doall = 1;
951.1Schs
961.1Schs		if (!doall) {
971.1Schs			end = addr + len;
981.1Schs			if (len <= 1024) {
991.1Schs				addr = addr & ~0xf;
1001.1Schs				inc = 16;
1011.1Schs			} else {
1021.1Schs				addr = addr & ~PGOFSET;
1031.3Sthorpej				inc = PAGE_SIZE;
1041.1Schs			}
1051.1Schs		}
1061.1Schs		do {
1071.1Schs			/*
1081.1Schs			 * Convert to physical address if needed.
1091.1Schs			 * If translation fails, we perform operation on
1101.1Schs			 * entire cache.
1111.1Schs			 */
1121.1Schs			if (!doall &&
1131.1Schs			    (pa == 0 || m68k_page_offset(addr) == 0)) {
1141.1Schs				if (pmap_extract(p->p_vmspace->vm_map.pmap,
1151.10Sthorpej				    addr, &pa) == false)
1161.1Schs					doall = 1;
1171.1Schs			}
1181.1Schs			switch (req) {
1191.1Schs			case CC_EXTPURGE|CC_IPURGE:
1201.1Schs			case CC_IPURGE:
1211.1Schs				if (doall) {
1221.1Schs					DCFA();
1231.1Schs					ICPA();
1241.1Schs				} else if (inc == 16) {
1251.1Schs					DCFL(pa);
1261.1Schs					ICPL(pa);
1271.3Sthorpej				} else if (inc == PAGE_SIZE) {
1281.1Schs					DCFP(pa);
1291.1Schs					ICPP(pa);
1301.1Schs				}
1311.1Schs				break;
1321.1Schs
1331.1Schs			case CC_EXTPURGE|CC_PURGE:
1341.1Schs			case CC_PURGE:
1351.1Schs				if (doall)
1361.1Schs					DCFA();	/* note: flush not purge */
1371.1Schs				else if (inc == 16)
1381.1Schs					DCPL(pa);
1391.3Sthorpej				else if (inc == PAGE_SIZE)
1401.1Schs					DCPP(pa);
1411.1Schs				break;
1421.1Schs
1431.1Schs			case CC_EXTPURGE|CC_FLUSH:
1441.1Schs			case CC_FLUSH:
1451.1Schs				if (doall)
1461.1Schs					DCFA();
1471.1Schs				else if (inc == 16)
1481.1Schs					DCFL(pa);
1491.3Sthorpej				else if (inc == PAGE_SIZE)
1501.1Schs					DCFP(pa);
1511.1Schs				break;
1521.1Schs
1531.1Schs			default:
1541.1Schs				error = EINVAL;
1551.1Schs				break;
1561.1Schs			}
1571.1Schs			if (doall)
1581.1Schs				break;
1591.1Schs			pa += inc;
1601.1Schs			addr += inc;
1611.1Schs		} while (addr < end);
1621.1Schs		return (error);
1631.1Schs	}
1641.1Schs#endif
1651.1Schs	switch (req) {
1661.1Schs	case CC_EXTPURGE|CC_PURGE:
1671.1Schs	case CC_EXTPURGE|CC_FLUSH:
1681.1Schs#if defined(CACHE_HAVE_PAC)
1691.1Schs		if (ectype == EC_PHYS)
1701.1Schs			PCIA();
1711.1Schs		/* fall into... */
1721.1Schs#endif
1731.1Schs	case CC_PURGE:
1741.1Schs	case CC_FLUSH:
1751.1Schs		DCIU();
1761.1Schs		break;
1771.1Schs	case CC_EXTPURGE|CC_IPURGE:
1781.1Schs#if defined(CACHE_HAVE_PAC)
1791.1Schs		if (ectype == EC_PHYS)
1801.1Schs			PCIA();
1811.1Schs		else
1821.1Schs#endif
1831.1Schs		DCIU();
1841.1Schs		/* fall into... */
1851.1Schs	case CC_IPURGE:
1861.1Schs		ICIA();
1871.1Schs		break;
1881.1Schs	default:
1891.1Schs		error = EINVAL;
1901.1Schs		break;
1911.1Schs	}
1921.7Stsutsui	return error;
1931.1Schs}
1941.1Schs
1951.1Schsint
1961.13Sdslsys_sysarch(struct lwp *l, const struct sys_sysarch_args *uap, register_t *retval)
1971.1Schs{
1981.1Schs
1991.7Stsutsui	return ENOSYS;
2001.1Schs}
2011.1Schs
2021.1Schs#if defined(amiga) || defined(x68k)
2031.1Schs
2041.1Schs/*
2051.1Schs * DMA cache control
2061.1Schs */
2071.1Schs
2081.1Schs/*ARGSUSED1*/
2091.1Schsint
2101.11Schristosdma_cachectl(void *addr, int len)
2111.1Schs{
2121.1Schs#if defined(M68040) || defined(M68060)
2131.1Schs	int inc = 0;
2141.1Schs	int pa = 0;
2151.11Schristos	void *end;
2161.1Schs
2171.1Schs	if (mmutype != MMU_68040) {
2181.7Stsutsui		return 0;
2191.1Schs	}
2201.1Schs
2211.12She	end = (char*)addr + len;
2221.1Schs	if (len <= 1024) {
2231.11Schristos		addr = (void *)((vaddr_t)addr & ~0xf);
2241.1Schs		inc = 16;
2251.1Schs	} else {
2261.11Schristos		addr = (void *)((vaddr_t)addr & ~PGOFSET);
2271.3Sthorpej		inc = PAGE_SIZE;
2281.1Schs	}
2291.1Schs	do {
2301.1Schs		/*
2311.1Schs		 * Convert to physical address.
2321.1Schs		 */
2331.1Schs		if (pa == 0 || ((vaddr_t)addr & PGOFSET) == 0) {
2341.1Schs			pa = kvtop(addr);
2351.1Schs		}
2361.1Schs		if (inc == 16) {
2371.1Schs			DCFL(pa);
2381.1Schs			ICPL(pa);
2391.1Schs		} else {
2401.1Schs			DCFP(pa);
2411.1Schs			ICPP(pa);
2421.1Schs		}
2431.1Schs		pa += inc;
2441.12She		addr = (char*)addr + inc;
2451.1Schs	} while (addr < end);
2461.1Schs#endif	/* defined(M68040) || defined(M68060) */
2471.7Stsutsui	return 0;
2481.1Schs}
2491.1Schs#endif	/* defined(amiga) || defined(x68k) */
250