From owner-acpi-jp@jp.FreeBSD.org Sat Jul 13 01:58:44 2002
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) id g6CGwij17702;
	Sat, 13 Jul 2002 01:58:44 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (root@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) with ESMTP/inet id g6CGwfn17697
	for <acpi-jp@jp.FreeBSD.org>; Sat, 13 Jul 2002 01:58:41 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwa@tasogare.imasy.or.jp [202.227.24.5])
	by tasogare.imasy.or.jp (8.11.6+3.4W/8.11.6/tasogare) with ESMTP/inet id g6CGwQh08152;
	Sat, 13 Jul 2002 01:58:27 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Date: Sat, 13 Jul 2002 01:58:03 +0900 (JST)
Message-Id: <20020713.015803.35656372.iwasaki@jp.FreeBSD.org>
To: acpi-jp@jp.FreeBSD.org, andrew.grover@intel.com
From: Mitsuru IWASAKI <iwasaki@jp.FreeBSD.org>
In-Reply-To: <59885C5E3098D511AD690002A5072D3C02AB7F7F@orsmsx111.jf.intel.com>
References: <59885C5E3098D511AD690002A5072D3C02AB7F7F@orsmsx111.jf.intel.com>
X-Mailer: Mew version 2.1 on Emacs 20.7 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: acpi-jp@jp.FreeBSD.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+020713
X-Sequence: acpi-jp 1673
Subject: [acpi-jp 1673] Re: Intel's acpi 
Errors-To: owner-acpi-jp@jp.FreeBSD.org
Sender: owner-acpi-jp@jp.FreeBSD.org
X-Originator: iwasaki@jp.FreeBSD.org

Hi,

> > From: Mitsuru IWASAKI [mailto:iwasaki@jp.FreeBSD.org] 
> > I thought the same thing.  Could you integrate attached diffs and
> > files into your next snapshot?
> 
> No, because I don't think arch-specific headers should be included from
> acenv.h, but rather from the OS-specific header (e.g. freebsd.h).
> 
> Yes it's true, we currently do have both WIN32 and WIN64-specific headers
> included directly, but I'd like to see us consolidate those, I think.

Ah, I thought ACPI CA is going that way like having WIN32 and
WIN64-specific headers.
*BSD systems have the framework for this purpose.  In arch-specific
header directory, we can have arch-specific headers and arch-independent
source files can include them, like;

#include <machine/acpica_machdep.h>

i.e. in acfreebsd.h includes sys/i386/include/acpica_machdep.h or
sys/ia64/include/acpica_machdep.h depending on its machine architecture.

Sample code attached.  Could you review them?

Thanks

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	sys/contrib/dev/acpica/acfreebsd.h
#	sys/i386/include/acpica_machdep.h
#	sys/ia64/include/acpica_machdep.h
#
echo x - sys/contrib/dev/acpica/acfreebsd.h
sed 's/^X//' >sys/contrib/dev/acpica/acfreebsd.h << 'END-of-sys/contrib/dev/acpica/acfreebsd.h'
X/******************************************************************************
X *
X * Name: acfreebsd.h - OS specific defines, etc.
X *       $Revision: 7 $
X *
X *****************************************************************************/
X
X/******************************************************************************
X *
X * 1. Copyright Notice
X *
X * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
X * All rights reserved.
X *
X * 2. License
X *
X * 2.1. This is your license from Intel Corp. under its intellectual property
X * rights.  You may have additional license terms from the party that provided
X * you this software, covering your right to use that party's intellectual
X * property rights.
X *
X * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
X * copy of the source code appearing in this file ("Covered Code") an
X * irrevocable, perpetual, worldwide license under Intel's copyrights in the
X * base code distributed originally by Intel ("Original Intel Code") to copy,
X * make derivatives, distribute, use and display any portion of the Covered
X * Code in any form, with the right to sublicense such rights; and
X *
X * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
X * license (with the right to sublicense), under only those claims of Intel
X * patents that are infringed by the Original Intel Code, to make, use, sell,
X * offer to sell, and import the Covered Code and derivative works thereof
X * solely to the minimum extent necessary to exercise the above copyright
X * license, and in no event shall the patent license extend to any additions
X * to or modifications of the Original Intel Code.  No other license or right
X * is granted directly or by implication, estoppel or otherwise;
X *
X * The above copyright and patent license is granted only if the following
X * conditions are met:
X *
X * 3. Conditions
X *
X * 3.1. Redistribution of Source with Rights to Further Distribute Source.
X * Redistribution of source code of any substantial portion of the Covered
X * Code or modification with rights to further distribute source must include
X * the above Copyright Notice, the above License, this list of Conditions,
X * and the following Disclaimer and Export Compliance provision.  In addition,
X * Licensee must cause all Covered Code to which Licensee contributes to
X * contain a file documenting the changes Licensee made to create that Covered
X * Code and the date of any change.  Licensee must include in that file the
X * documentation of any changes made by any predecessor Licensee.  Licensee
X * must include a prominent statement that the modification is derived,
X * directly or indirectly, from Original Intel Code.
X *
X * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
X * Redistribution of source code of any substantial portion of the Covered
X * Code or modification without rights to further distribute source must
X * include the following Disclaimer and Export Compliance provision in the
X * documentation and/or other materials provided with distribution.  In
X * addition, Licensee may not authorize further sublicense of source of any
X * portion of the Covered Code, and must include terms to the effect that the
X * license from Licensee to its licensee is limited to the intellectual
X * property embodied in the software Licensee provides to its licensee, and
X * not to intellectual property embodied in modifications its licensee may
X * make.
X *
X * 3.3. Redistribution of Executable. Redistribution in executable form of any
X * substantial portion of the Covered Code or modification must reproduce the
X * above Copyright Notice, and the following Disclaimer and Export Compliance
X * provision in the documentation and/or other materials provided with the
X * distribution.
X *
X * 3.4. Intel retains all right, title, and interest in and to the Original
X * Intel Code.
X *
X * 3.5. Neither the name Intel nor any other trademark owned or controlled by
X * Intel shall be used in advertising or otherwise to promote the sale, use or
X * other dealings in products derived from or relating to the Covered Code
X * without prior written authorization from Intel.
X *
X * 4. Disclaimer and Export Compliance
X *
X * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
X * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
X * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
X * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
X * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
X * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
X * PARTICULAR PURPOSE.
X *
X * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
X * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
X * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
X * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
X * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
X * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
X * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
X * LIMITED REMEDY.
X *
X * 4.3. Licensee shall not export, either directly or indirectly, any of this
X * software or system incorporating such software without first obtaining any
X * required license or other approval from the U. S. Department of Commerce or
X * any other agency or department of the United States Government.  In the
X * event Licensee exports any such software from the United States or
X * re-exports any such software from a foreign destination, Licensee shall
X * ensure that the distribution and export/re-export of the software is in
X * compliance with all laws, regulations, orders, or other restrictions of the
X * U.S. Export Administration Regulations. Licensee agrees that neither it nor
X * any of its subsidiaries will export/re-export any technical data, process,
X * software, or service, directly or indirectly, to any country for which the
X * United States government or any agency thereof requires an export license,
X * other governmental approval, or letter of assurance, without first obtaining
X * such license, approval or letter.
X *
X *****************************************************************************/
X
X#ifndef __ACFREEBSD_H__
X#define __ACFREEBSD_H__
X
X/*
X * XXX this is technically correct, but will cause problems with some ASL
X *     which only works if the string names a Microsoft operating system.
X */
X#define ACPI_OS_NAME                "FreeBSD"
X
X/* FreeBSD uses GCC */
X
X#include "acgcc.h"
X
X#ifdef _KERNEL
X#include "opt_acpi.h"
X
X#include <sys/ctype.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <sys/libkern.h>
X#include <machine/stdarg.h>
X#include <machine/acpica_machdep.h>
X
X#ifdef DEBUGGER_THREADING
X#undef DEBUGGER_THREADING
X#endif /* DEBUGGER_THREADING */
X#define DEBUGGER_THREADING 0    /* integrated with DDB */
X#ifdef ACPI_DEBUG
X#include "opt_ddb.h"
X#ifdef DDB
X#define ENABLE_DEBUGGER
X#endif /* DDB */
X#endif /* ACPI_DEBUG */
X
X#else /* _KERNEL */
X
X/* Not building kernel code, so use libc */
X#define ACPI_USE_STANDARD_HEADERS
X
X#define __cli()
X#define __sti()
X#define ACPI_FLUSH_CPU_CACHE()
X
X#endif /* _KERNEL */
X
X/* Always use FreeBSD code over our local versions */
X#define ACPI_USE_SYSTEM_CLIBRARY
X
X/* FreeBSD doesn't have strupr, should be fixed. (move to libkern) */
Xstatic __inline char *
Xstrupr(char *str)
X{
X    char *c = str;
X    while(*c) {
X    *c = toupper(*c);
X    c++;
X    }
X    return(str);
X}
X
X#ifdef _KERNEL
X/* Or strstr (used in debugging mode, also move to libkern) */
Xstatic __inline char *
Xstrstr(char *s, char *find)
X{
X    char c, sc;
X    size_t len;
X
X    if ((c = *find++) != 0) {
X    len = strlen(find);
X    do {
X        do {
X        if ((sc = *s++) == 0)
X            return (NULL);
X        } while (sc != c);
X    } while (strncmp(s, find, len) != 0);
X    s--;
X    }
X    return ((char *)s);
X}
X#endif /* _KERNEL */
X
X#endif /* __ACFREEBSD_H__ */
END-of-sys/contrib/dev/acpica/acfreebsd.h
echo x - sys/i386/include/acpica_machdep.h
sed 's/^X//' >sys/i386/include/acpica_machdep.h << 'END-of-sys/i386/include/acpica_machdep.h'
X/*-
X * Copyright (c) 2002 Mitsuru IWASAKI
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X * $FreeBSD$
X */
X
X/******************************************************************************
X *
X * Name: acpica_machdep.h - arch-specific defines, etc.
X *       $Revision$
X *
X *****************************************************************************/
X
X#ifndef __ACPICA_MACHDEP_H__
X#define __ACPICA_MACHDEP_H__
X
X#ifdef _KERNEL
X/*
X * Calling conventions:
X *
X * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
X * ACPI_EXTERNAL_XFACE      - External ACPI interfaces 
X * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
X * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
X */
X#define ACPI_SYSTEM_XFACE
X#define ACPI_EXTERNAL_XFACE
X#define ACPI_INTERNAL_XFACE
X#define ACPI_INTERNAL_VAR_XFACE
X
X/* Asm macros */
X
X#define ACPI_ASM_MACROS
X#define BREAKPOINT3
X#define ACPI_DISABLE_IRQS() disable_intr()
X#define ACPI_ENABLE_IRQS()  enable_intr()
X
X#define ACPI_FLUSH_CPU_CACHE()	wbinvd()
X
X#define asm         __asm
X/*! [Begin] no source code translation
X *
X * A brief explanation as GNU inline assembly is a bit hairy
X *  %0 is the output parameter in EAX ("=a")
X *  %1 and %2 are the input parameters in ECX ("c")
X *  and an immediate value ("i") respectively
X *  All actual register references are preceded with "%%" as in "%%edx"
X *  Immediate values in the assembly are preceded by "$" as in "$0x1"
X *  The final asm parameter are the operation altered non-output registers.
X */
X#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
X    do { \
X        int dummy; \
X        asm("1:     movl (%1),%%eax;" \
X            "movl   %%eax,%%edx;" \
X            "andl   %2,%%edx;" \
X            "btsl   $0x1,%%edx;" \
X            "adcl   $0x0,%%edx;" \
X            "lock;  cmpxchgl %%edx,(%1);" \
X            "jnz    1b;" \
X            "cmpb   $0x3,%%dl;" \
X            "sbbl   %%eax,%%eax" \
X            :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~1L):"dx"); \
X    } while(0)
X
X#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
X    do { \
X        int dummy; \
X        asm("1:     movl (%1),%%eax;" \
X            "movl   %%eax,%%edx;" \
X            "andl   %2,%%edx;" \
X            "lock;  cmpxchgl %%edx,(%1);" \
X            "jnz    1b;" \
X            "andl   $0x1,%%eax" \
X            :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~3L):"dx"); \
X    } while(0)
X
X
X/*
X * Math helper asm macros
X */
X#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
X        asm("divl %2;"        \
X        :"=a"(q32), "=d"(r32) \
X        :"r"(d32),            \
X        "0"(n_lo), "1"(n_hi))
X
X
X#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
X    asm("shrl   $1,%2;"             \
X        "rcrl   $1,%3;"             \
X        :"=r"(n_hi), "=r"(n_lo)     \
X        :"0"(n_hi), "1"(n_lo))
X
X/*! [End] no source code translation !*/
X#endif /* _KERNEL */
X
X#define ACPI_MACHINE_WIDTH             32
X#define COMPILER_DEPENDENT_INT64       long long
X#define COMPILER_DEPENDENT_UINT64      unsigned long long
X#define ACPI_USE_NATIVE_DIVIDE
X
X#endif /* __ACPICA_MACHDEP_H__ */
END-of-sys/i386/include/acpica_machdep.h
echo x - sys/ia64/include/acpica_machdep.h
sed 's/^X//' >sys/ia64/include/acpica_machdep.h << 'END-of-sys/ia64/include/acpica_machdep.h'
X/*-
X * Copyright (c) 2002 Mitsuru IWASAKI
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X * $FreeBSD$
X */
X
X/******************************************************************************
X *
X * Name: acpica_machdep.h - arch-specific defines, etc.
X *       $Revision$
X *
X *****************************************************************************/
X
X#ifndef __ACPICA_MACHDEP_H__
X#define __ACPICA_MACHDEP_H__
X
X#ifdef _KERNEL
X#define _IA64
X
X/*
X * Calling conventions:
X *
X * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
X * ACPI_EXTERNAL_XFACE      - External ACPI interfaces 
X * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
X * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
X */
X#define ACPI_SYSTEM_XFACE
X#define ACPI_EXTERNAL_XFACE
X#define ACPI_INTERNAL_XFACE
X#define ACPI_INTERNAL_VAR_XFACE
X
X/* Asm macros */
X
X#define ACPI_ASM_MACROS
X#define BREAKPOINT3
X#define ACPI_DISABLE_IRQS() disable_intr()
X#define ACPI_ENABLE_IRQS()  enable_intr()
X
X#define ACPI_FLUSH_CPU_CACHE()	/* XXX ia64_fc()? */
X
X/*! [Begin] no source code translation */
X
X#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
X    do { \
X    __asm__ volatile ("1:  ld4      r29=%1\n"  \
X        ";;\n"                  \
X        "mov    ar.ccv=r29\n"   \
X        "mov    r2=r29\n"       \
X        "shr.u  r30=r29,1\n"    \
X        "and    r29=-4,r29\n"   \
X        ";;\n"                  \
X        "add    r29=2,r29\n"    \
X        "and    r30=1,r30\n"    \
X        ";;\n"                  \
X        "add    r29=r29,r30\n"  \
X        ";;\n"                  \
X        "cmpxchg4.acq   r30=%1,r29,ar.ccv\n" \
X        ";;\n"                  \
X        "cmp.eq p6,p7=r2,r30\n" \
X        "(p7) br.dpnt.few 1b\n" \
X        "cmp.gt p8,p9=3,r29\n"  \
X        ";;\n"                  \
X        "(p8) mov %0=-1\n"      \
X        "(p9) mov %0=r0\n"      \
X        :"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
X    } while (0)
X
X#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
X    do { \
X    __asm__ volatile ("1:  ld4      r29=%1\n" \
X        ";;\n"                  \
X        "mov    ar.ccv=r29\n"   \
X        "mov    r2=r29\n"       \
X        "and    r29=-4,r29\n"   \
X        ";;\n"                  \
X        "cmpxchg4.acq   r30=%1,r29,ar.ccv\n" \
X        ";;\n"                  \
X        "cmp.eq p6,p7=r2,r30\n" \
X        "(p7) br.dpnt.few 1b\n" \
X        "and    %0=1,r2\n"      \
X        ";;\n"                  \
X        :"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
X    } while (0)
X/*! [End] no source code translation !*/
X
X#endif /* _KERNEL */
X
X#define ACPI_MACHINE_WIDTH             64
X#define COMPILER_DEPENDENT_INT64       long
X#define COMPILER_DEPENDENT_UINT64      unsigned long
X
X#endif /* __ACPICA_MACHDEP_H__ */
END-of-sys/ia64/include/acpica_machdep.h
exit

