⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bus.h

📁 国产CPU-龙芯(loongson)BIOS源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
/*	$OpenBSD: bus.h,v 1.33 2002/03/14 01:26:33 millert Exp $	*//*	$NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $	*//*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * 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. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the NetBSD *	Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its *    contributors may be used to endorse or promote products derived *    from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. *//* * Copyright (c) 1996 Charles M. Hannum.  All rights reserved. * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved. * Copyright (c) 1996 Christopher G. Demetriou.  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. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Christopher G. Demetriou *	for the NetBSD Project. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. */#ifndef _I386_BUS_H_#define _I386_BUS_H_#include <machine/pio.h>/* * Values for the i386 bus space tag, not to be used directly by MI code. */#define	I386_BUS_SPACE_IO	0	/* space is i/o space */#define I386_BUS_SPACE_MEM	1	/* space is mem space *//* * Bus address and size types */typedef u_long bus_addr_t;typedef u_long bus_size_t;/* * Access methods for bus resources and address space. *//* * Access methods for bus resources */#define bus_space_map(t, addr, size, cacheable, bshp) \						      ((*(bshp) = (t)->bus_base + (addr)), 0)#define bus_space_unmap(t, bsh, size)typedef u_int32_t bus_space_handle_t;typedef struct tgt_bus_space *bus_space_tag_t;/* *  Describe a bus with properties. */struct tgt_bus_space {	u_int32_t	bus_base;	u_int8_t	bus_reverse;	/* Reverse bytes */};extern struct tgt_bus_space tgt_isa_io, tgt_isa_mem;#ifndef PMONint	bus_space_map(bus_space_tag_t t, bus_addr_t addr,	    bus_size_t size, int cacheable, bus_space_handle_t *bshp);/* like bus_space_map(), but without extent map checking/allocation */int	_bus_space_map(bus_space_tag_t t, bus_addr_t addr,	    bus_size_t size, int cacheable, bus_space_handle_t *bshp);void	bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,	    bus_size_t size);int	bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);int	bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,	    bus_addr_t rend, bus_size_t size, bus_size_t align,	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,	    bus_space_handle_t *bshp);void	bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,	    bus_size_t size);#endif /* !PMON *//* *	u_intN_t bus_space_read_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset); * * Read a 1, 2, 4, or 8 byte quantity from bus space * described by tag/handle/offset. */#define	bus_space_read_1(t, h, o)					\	((t) == I386_BUS_SPACE_IO ? (inb((h) + (o))) :			\	    (*(volatile u_int8_t *)((h) + (o))))#define	bus_space_read_2(t, h, o)					\	((t) == I386_BUS_SPACE_IO ? (inw((h) + (o))) :			\	    (*(volatile u_int16_t *)((h) + (o))))#define	bus_space_read_4(t, h, o)					\	((t) == I386_BUS_SPACE_IO ? (inl((h) + (o))) :			\	    (*(volatile u_int32_t *)((h) + (o))))#if 0	/* Cause a link error for bus_space_read_8 */#define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!#endif/* *	void bus_space_read_multi_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset, *	    u_intN_t *addr, size_t count); * * Read `count' 1, 2, 4, or 8 byte quantities from bus space * described by tag/handle/offset and copy into buffer provided. */#define	bus_space_read_multi_1(t, h, o, a, cnt) do {			\	if ((t) == I386_BUS_SPACE_IO) {					\		insb((h) + (o), (a), (cnt));				\	} else {void *_addr=(a); int _cnt=(cnt);			\		__asm __volatile("					\			cld					;	\		1:	movb (%2),%%al				;	\			stosb					;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt) : "r" ((h) + (o))	:	\		    "%eax", "memory", "cc");				\	}								\} while (0)#define	bus_space_read_multi_2(t, h, o, a, cnt) do {			\	if ((t) == I386_BUS_SPACE_IO) {					\		insw((h) + (o), (a), (cnt));				\	} else {void *_addr=(a); int _cnt=(cnt);			\		__asm __volatile("					\			cld					;	\		1:	movw (%2),%%ax				;	\			stosw					;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt) : "r" ((h) + (o))	:	\		    "%eax", "memory", "cc");				\	}								\} while (0)#define	bus_space_read_multi_4(t, h, o, a, cnt) do {			\	if ((t) == I386_BUS_SPACE_IO) {					\		insl((h) + (o), (a), (cnt));				\	} else {void *_addr=(a); int _cnt=(cnt);			\		__asm __volatile("					\			cld					;	\		1:	movl (%2),%%eax				;	\			stosl					;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt) : "r" ((h) + (o))	:	\		    "%eax", "memory", "cc");				\	}								\} while (0)#if 0	/* Cause a link error for bus_space_read_multi_8 */#define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!#endif/* *	void bus_space_read_raw_multi_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset, *	    u_int8_t *addr, size_t count); * * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space * described by tag/handle/offset and copy into buffer provided.  The buffer * must have proper alignment for the N byte wide entities.  Furthermore * possible byte-swapping should be done by these functions. */#define	bus_space_read_raw_multi_2(t, h, o, a, c) \    bus_space_read_multi_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1)#define	bus_space_read_raw_multi_4(t, h, o, a, c) \    bus_space_read_multi_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2)#if 0	/* Cause a link error for bus_space_read_raw_multi_8 */#define	bus_space_read_raw_multi_8 \    !!! bus_space_read_raw_multi_8 unimplemented !!!#endif/* *	void bus_space_read_region_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset, *	    u_intN_t *addr, size_t count); * * Read `count' 1, 2, 4, or 8 byte quantities from bus space * described by tag/handle and starting at `offset' and copy into * buffer provided. */#define	bus_space_read_region_1(t, h, o, a, cnt) do {			\	int _cnt = (cnt);	void *_addr = (a); int _port = (h)+(o);	\	if ((t) == I386_BUS_SPACE_IO) {					\		__asm __volatile("					\			cld					;	\		1:	inb %w2,%%al				;	\			stosb					;	\			incl %2					;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt), "+d" (_port)	::	\		    "%eax", "memory", "cc");				\	} else								\		i386_space_copy(_port, _addr, 1, _cnt);			\} while (0)#define	bus_space_read_region_2(t, h, o, a, cnt) do {			\	int _cnt = (cnt);	void *_addr = (a); int _port = (h)+(o);	\	if ((t) == I386_BUS_SPACE_IO) {					\		__asm __volatile("					\			cld					;	\		1:	inw %w2,%%ax				;	\			stosw					;	\			addl $2,%2				;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt), "+d" (_port)	::	\		    "%eax", "memory", "cc");				\	} else								\		i386_space_copy(_port, _addr, 2, _cnt);			\} while (0)#define	bus_space_read_region_4(t, h, o, a, cnt) do {			\	int _cnt = (cnt);	void *_addr = (a); int _port = (h)+(o);	\	if ((t) == I386_BUS_SPACE_IO) {					\		__asm __volatile("					\			cld					;	\		1:	inl %w2,%%eax				;	\			stosl					;	\			addl $4,%2				;	\			loop 1b"				:	\		    "+D" (_addr), "+c" (_cnt), "+d" (_port)	::	\		    "%eax", "memory", "cc");				\	} else								\		i386_space_copy(_port, _addr, 4, _cnt);			\} while (0)#if 0	/* Cause a link error for bus_space_read_region_8 */#define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!#endif/* *	void bus_space_read_raw_region_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset, *	    u_int8_t *addr, size_t count); * * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space * described by tag/handle and starting at `offset' and copy into * buffer provided.  The buffer must have proper alignment for the N byte * wide entities.  Furthermore possible byte-swapping should be done by * these functions. */#define	bus_space_read_raw_region_2(t, h, o, a, c) \    bus_space_read_region_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1)#define	bus_space_read_raw_region_4(t, h, o, a, c) \    bus_space_read_region_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2)#if 0	/* Cause a link error for bus_space_read_raw_region_8 */#define	bus_space_read_raw_region_8 \    !!! bus_space_read_raw_region_8 unimplemented !!!#endif/* *	void bus_space_write_N(bus_space_tag_t tag, *	    bus_space_handle_t bsh, bus_size_t offset, *	    u_intN_t value); * * Write the 1, 2, 4, or 8 byte value `value' to bus space

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -