Initial pass a ARC BIOS code that can be shared between the sgimips
and arc ports.
This commit is contained in:
parent
b86053cc53
commit
e379ce3db0
105
sys/dev/arcbios/arcbios.c
Normal file
105
sys/dev/arcbios/arcbios.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* $NetBSD: arcbios.c,v 1.1 2001/07/08 19:58:02 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dev/cons.h>
|
||||
|
||||
#include <dev/arcbios/arcbios.h>
|
||||
#include <dev/arcbios/arcbiosvar.h>
|
||||
|
||||
const struct arcbios_spb *ARCBIOS_SPB;
|
||||
const struct arcbios_fv *ARCBIOS;
|
||||
|
||||
int arcbios_cngetc(dev_t);
|
||||
void arcbios_cnputc(dev_t, int);
|
||||
|
||||
struct consdev arcbios_cn = {
|
||||
NULL, NULL, arcbios_cngetc, arcbios_cnputc, nullcnpollc, NULL,
|
||||
NODEV, CN_NORMAL,
|
||||
};
|
||||
|
||||
/*
|
||||
* arcbios_init:
|
||||
*
|
||||
* Initialize the ARC BIOS.
|
||||
*/
|
||||
int
|
||||
arcbios_init(vaddr_t pblkva)
|
||||
{
|
||||
|
||||
ARCBIOS_SPB = (struct arcbios_spb *) pblkva;
|
||||
|
||||
switch (ARCBIOS_SPB->SPBSignature) {
|
||||
case ARCBIOS_SPB_SIGNATURE:
|
||||
case ARCBIOS_SPB_SIGNATURE_1:
|
||||
/* Okay. */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Don't know what this is. */
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Initialize our pointer to the firmware vector. */
|
||||
ARCBIOS = ARCBIOS_SPB->FirmwareVector;
|
||||
|
||||
/* Initialize the bootstrap console. */
|
||||
cn_tab = &arcbios_cn;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_cngetc(dev_t dev)
|
||||
{
|
||||
uint32_t count;
|
||||
char c;
|
||||
|
||||
(*ARCBIOS->Read)(ARCBIOS_STDIN, &c, 1, &count);
|
||||
return (c);
|
||||
}
|
||||
|
||||
void
|
||||
arcbios_cnputc(dev_t dev, int c)
|
||||
{
|
||||
uint32_t count;
|
||||
char ch = c;
|
||||
|
||||
(*ARCBIOS->Write)(ARCBIOS_STDOUT, &ch, 1, &count);
|
||||
}
|
398
sys/dev/arcbios/arcbios.h
Normal file
398
sys/dev/arcbios/arcbios.h
Normal file
@ -0,0 +1,398 @@
|
||||
/* $NetBSD: arcbios.h,v 1.1 2001/07/08 19:58:02 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The ARC BIOS (which is similar, but not 100% compatible with SGI ARCS)
|
||||
* specification can be found at:
|
||||
*
|
||||
* http://www.microsoft.com/hwdev/download/respec/riscspec.zip
|
||||
*/
|
||||
|
||||
#define ARCBIOS_STDIN 0
|
||||
#define ARCBIOS_STDOUT 1
|
||||
|
||||
#define ARCBIOS_PAGESIZE 4096
|
||||
|
||||
/* ARC BIOS status codes. */
|
||||
#define ARCBIOS_ESUCCESS 0 /* Success */
|
||||
#define ARCBIOS_E2BIG 1 /* argument list too long */
|
||||
#define ARCBIOS_EACCES 2 /* permission denied */
|
||||
#define ARCBIOS_EAGAIN 3 /* resource temporarily unavailable */
|
||||
#define ARCBIOS_EBADF 4 /* bad file number */
|
||||
#define ARCBIOS_EBUSY 5 /* device or resource busy */
|
||||
#define ARCBIOS_EFAULT 6 /* bad address */
|
||||
#define ARCBIOS_EINVAL 7 /* invalid argument */
|
||||
#define ARCBIOS_EIO 8 /* I/O error */
|
||||
#define ARCBIOS_EISDIR 9 /* is a directory */
|
||||
#define ARCBIOS_EMFILE 10 /* too many open files */
|
||||
#define ARCBIOS_EMLINK 11 /* too many links */
|
||||
#define ARCBIOS_ENAMETOOLONG 12 /* file name too long */
|
||||
#define ARCBIOS_ENODEV 13 /* no such device */
|
||||
#define ARCBIOS_ENOENT 14 /* no such file or directory */
|
||||
#define ARCBIOS_ENOEXEC 15 /* exec format error */
|
||||
#define ARCBIOS_ENOMEM 16 /* out of memory */
|
||||
#define ARCBIOS_ENOSPC 17 /* no space left on device */
|
||||
#define ARCBIOS_ENOTDIR 18 /* not a directory */
|
||||
#define ARCBIOS_ENOTTY 19 /* not a typewriter */
|
||||
#define ARCBIOS_ENXIO 20 /* media not loaded */
|
||||
#define ARCBIOS_EROFS 21 /* read-only file system */
|
||||
#if defined(sgimips)
|
||||
#define ARCBIOS_EADDRNOTAVAIL 31 /* address not available */
|
||||
#define ARCBIOS_ETIMEDOUT 32 /* operation timed out */
|
||||
#define ARCBIOS_ECONNABORTED 33 /* connection aborted */
|
||||
#define ARCBIOS_ENOCONNECT 34 /* not connected */
|
||||
#endif /* sgimips */
|
||||
|
||||
/*
|
||||
* 4.2.2: System Parameter Block
|
||||
*/
|
||||
struct arcbios_spb {
|
||||
uint32_t SPBSignature;
|
||||
uint32_t SPBLength;
|
||||
uint16_t Version;
|
||||
uint16_t Revision;
|
||||
void *RestartBlock;
|
||||
void *DebugBlock;
|
||||
void *GEVector;
|
||||
void *UTLBMissVector;
|
||||
uint32_t FirmwareVectorLength;
|
||||
void *FirmwareVector;
|
||||
uint32_t PrivateVectorLength;
|
||||
void *PrivateVector;
|
||||
uint32_t AdapterCount;
|
||||
uint32_t AdapterType;
|
||||
uint32_t AdapterVectorLength;
|
||||
void *AdapterVector;
|
||||
};
|
||||
|
||||
#define ARCBIOS_SPB_SIGNATURE 0x53435241 /* A R C S */
|
||||
#define ARCBIOS_SPB_SIGNATURE_1 0x41524353 /* S C R A */
|
||||
|
||||
/*
|
||||
* 4.2.5: System Configuration Data
|
||||
*/
|
||||
struct arcbios_component {
|
||||
uint32_t Class;
|
||||
uint32_t Type;
|
||||
uint32_t Flags;
|
||||
uint16_t Version;
|
||||
uint16_t Revision;
|
||||
uint32_t Key;
|
||||
uint32_t AffinityMask;
|
||||
uint32_t ConfigurationDataSize;
|
||||
uint32_t IdentifierLength;
|
||||
char *Identifier;
|
||||
};
|
||||
|
||||
/* Component Class */
|
||||
#define COMPONENT_CLASS_SystemClass 0
|
||||
#define COMPONENT_CLASS_ProcessorClass 1
|
||||
#define COMPONENT_CLASS_CacheClass 2
|
||||
#define COMPONENT_CLASS_AdapterClass 3
|
||||
#define COMPONENT_CLASS_ControllerClass 4
|
||||
#define COMPONENT_CLASS_PeripheralClass 5
|
||||
#define COMPONENT_CLASS_MemoryClass 6
|
||||
|
||||
/* System Class */
|
||||
#define COMPONENT_TYPE_ARC 0
|
||||
|
||||
/* Processor Class */
|
||||
#define COMPONENT_TYPE_CPU 1
|
||||
#define COMPONENT_TYPE_FPU 2
|
||||
|
||||
/* Cache Class */
|
||||
#define COMPONENT_TYPE_PrimaryICache 3
|
||||
#define COMPONENT_TYPE_PrimaryDCache 4
|
||||
#define COMPONENT_TYPE_SecondaryICache 5
|
||||
#define COMPONENT_TYPE_SecondaryDCache 6
|
||||
#define COMPONENT_TYPE_SecondaryCache 7
|
||||
|
||||
/* Adapter Class */
|
||||
#define COMPONENT_TYPE_EISAAdapter 8
|
||||
#define COMPONENT_TYPE_TCAdapter 9
|
||||
#define COMPONENT_TYPE_SCSIAdapter 10
|
||||
#define COMPONENT_TYPE_DTIAdapter 11
|
||||
#define COMPONENT_TYPE_MultiFunctionAdapter 12
|
||||
|
||||
/* Controller Class */
|
||||
#define COMPONENT_TYPE_DiskController 13
|
||||
#define COMPONENT_TYPE_TapeController 14
|
||||
#define COMPONENT_TYPE_CDROMController 15
|
||||
#define COMPONENT_TYPE_WORMController 16
|
||||
#define COMPONENT_TYPE_SerialController 17
|
||||
#define COMPONENT_TYPE_NetworkController 18
|
||||
#define COMPONENT_TYPE_DisplayController 19
|
||||
#define COMPONENT_TYPE_ParallelController 20
|
||||
#define COMPONENT_TYPE_PointerController 21
|
||||
#define COMPONENT_TYPE_KeyboardController 22
|
||||
#define COMPONENT_TYPE_AudioController 23
|
||||
#define COMPONENT_TYPE_OtherController 24
|
||||
|
||||
/* Peripheral Class */
|
||||
#define COMPONENT_TYPE_DiskPeripheral 25
|
||||
#define COMPONENT_TYPE_FloppyDiskPeripheral 26
|
||||
#define COMPONENT_TYPE_TapePeripheral 27
|
||||
#define COMPONENT_TYPE_ModemPeripheral 28
|
||||
#define COMPONENT_TYPE_MonitorPeripheral 29
|
||||
#define COMPONENT_TYPE_PrinterPeripheral 30
|
||||
#define COMPONENT_TYPE_PointerPeripheral 31
|
||||
#define COMPONENT_TYPE_KeyboardPeripheral 32
|
||||
#define COMPONENT_TYPE_TerminalPeripheral 33
|
||||
#define COMPONENT_TYPE_OtherPeripheral 34
|
||||
#define COMPONENT_TYPE_LinePeripheral 35
|
||||
#define COMPONENT_TYPE_NetworkPeripheral 36
|
||||
|
||||
/* Memory Class */
|
||||
#define COMPONENT_TYPE_MemoryUnit 37
|
||||
|
||||
/* Component flags */
|
||||
#define COMPONENT_FLAG_Failed 1
|
||||
#define COMPONENT_FLAG_ReadOnly 2
|
||||
#define COMPONENT_FLAG_Removable 4
|
||||
#define COMPONENT_FLAG_ConsoleIn 8
|
||||
#define COMPONENT_FLAG_ConsoleOut 16
|
||||
#define COMPONENT_FLAG_Input 32
|
||||
#define COMPONENT_FLAG_Output 64
|
||||
|
||||
/* Key for Cache: */
|
||||
#define COMPONENT_KEY_Cache_CacheSize(x) \
|
||||
(ARCBIOS_PAGESIZE << ((x) & 0xffff))
|
||||
#define COMPONENT_KEY_Cache_LineSize(x) \
|
||||
(1U << (((x) >> 16) & 0xff))
|
||||
#define COMPONENT_KEY_Cache_RefillSize(x) \
|
||||
(((x) >> 24) & 0xff)
|
||||
|
||||
/*
|
||||
* ARC system ID
|
||||
*/
|
||||
struct arcbios_sysid {
|
||||
char Vendor[8];
|
||||
char Serial[8];
|
||||
};
|
||||
|
||||
/*
|
||||
* ARC memory descriptor
|
||||
*/
|
||||
struct arcbios_mem {
|
||||
uint32_t Type;
|
||||
uint32_t BasePage;
|
||||
uint32_t PageCount;
|
||||
};
|
||||
|
||||
#if defined(sgimips)
|
||||
#define ARCBIOS_MEM_ExecptionBlock 0
|
||||
#define ARCBIOS_MEM_SystemParameterBlock 1
|
||||
#define ARCBIOS_MEM_FreeContiguous 2
|
||||
#define ARCBIOS_MEM_FreeMemory 3
|
||||
#define ARCBIOS_MEM_BadMemory 4
|
||||
#define ARCBIOS_MEM_LoadedProgram 5
|
||||
#define ARCBIOS_MEM_FirmwareTemporary 6
|
||||
#define ARCBIOS_MEM_FirmwarePermanent 7
|
||||
#elif defined(arc)
|
||||
#define ARCBIOS_MEM_ExceptionBlock 0
|
||||
#define ARCBIOS_MEM_SystemParameterBlock 1
|
||||
#define ARCBIOS_MEM_FreeMemory 2
|
||||
#define ARCBIOS_MEM_BadMemory 3
|
||||
#define ARCBIOS_MEM_LoadedProgram 4
|
||||
#define ARCBIOS_MEM_FirmwareTemporary 5
|
||||
#define ARCBIOS_MEM_FirmwarePermanent 6
|
||||
#define ARCBIOS_MEM_FreeContiguous 7
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ARC display status
|
||||
*/
|
||||
struct arcbios_dsp_stat {
|
||||
uint16_t CursorXPosition;
|
||||
uint16_t CursorYPosition;
|
||||
uint16_t CursorMaxXPosition;
|
||||
uint16_t CursorMaxYPosition;
|
||||
uint8_t ForegroundColor;
|
||||
uint8_t BackgroundColor;
|
||||
uint8_t HighIntensity;
|
||||
uint8_t Underscored;
|
||||
uint8_t ReverseVideo;
|
||||
};
|
||||
|
||||
/*
|
||||
* ARC firmware vector
|
||||
*/
|
||||
struct arcbios_fv {
|
||||
uint32_t (*Load)(
|
||||
char *, /* image to load */
|
||||
uint32_t, /* top address */
|
||||
uint32_t, /* entry address */
|
||||
uint32_t *); /* low address */
|
||||
|
||||
uint32_t (*Invoke)(
|
||||
uint32_t, /* entry address */
|
||||
uint32_t, /* stack address */
|
||||
uint32_t, /* argc */
|
||||
char **, /* argv */
|
||||
char **); /* envp */
|
||||
|
||||
uint32_t (*Execute)(
|
||||
char *, /* image path */
|
||||
uint32_t, /* argc */
|
||||
char **, /* argv */
|
||||
char **); /* envp */
|
||||
|
||||
void (*Halt)(void)
|
||||
__attribute__((__noreturn__));
|
||||
|
||||
void (*PowerDown)(void)
|
||||
__attribute__((__noreturn__));
|
||||
|
||||
void (*Restart)(void)
|
||||
__attribute__((__noreturn__));
|
||||
|
||||
void (*Reboot)(void)
|
||||
__attribute__((__noreturn__));
|
||||
|
||||
void (*EnterInteractiveMode)(void)
|
||||
__attribute__((__noreturn__));
|
||||
#if defined(sgimips)
|
||||
void *reserved0;
|
||||
#else
|
||||
void (*ReturnFromMain)(void)
|
||||
__attribute__((__noreturn__));
|
||||
#endif
|
||||
void *(*GetPeer)(
|
||||
void *); /* component */
|
||||
|
||||
void *(*GetChild)(
|
||||
void *); /* component */
|
||||
|
||||
void *(*GetParent)(
|
||||
void *); /* component */
|
||||
|
||||
uint32_t (*GetConfigurationData)(
|
||||
void *, /* configuration data */
|
||||
void *); /* component */
|
||||
|
||||
void *(*AddChild)(
|
||||
void *, /* component */
|
||||
void *); /* new component */
|
||||
|
||||
uint32_t (*DeleteComponent)(
|
||||
void *); /* component */
|
||||
|
||||
uint32_t (*GetComponent)(
|
||||
char *); /* path */
|
||||
|
||||
uint32_t (*SaveConfiguration)(void);
|
||||
|
||||
void *(*GetSystemId)(void);
|
||||
|
||||
void *(*GetMemoryDescriptor)(
|
||||
void *); /* memory descriptor */
|
||||
#if defined(sgimips)
|
||||
void *reserved1;
|
||||
#else
|
||||
void (*Signal)(
|
||||
uint32_t, /* signal number */
|
||||
void *); /* handler */
|
||||
#endif
|
||||
void *(*GetTime)(void);
|
||||
|
||||
uint32_t (*GetRelativeTime)(void);
|
||||
|
||||
uint32_t (*GetDirectoryEntry)(
|
||||
uint32_t, /* file ID */
|
||||
void *, /* directory entry */
|
||||
uint32_t, /* length */
|
||||
uint32_t *); /* count */
|
||||
|
||||
uint32_t (*Open)(
|
||||
char *, /* path */
|
||||
uint32_t, /* open mode */
|
||||
uint32_t *); /* file ID */
|
||||
|
||||
uint32_t (*Close)(
|
||||
uint32_t); /* file ID */
|
||||
|
||||
uint32_t (*Read)(
|
||||
uint32_t, /* file ID */
|
||||
void *, /* buffer */
|
||||
uint32_t, /* length */
|
||||
uint32_t *); /* count */
|
||||
|
||||
uint32_t (*GetReadStatus)(
|
||||
uint32_t); /* file ID */
|
||||
|
||||
uint32_t (*Write)(
|
||||
uint32_t, /* file ID */
|
||||
void *, /* buffer */
|
||||
uint32_t, /* length */
|
||||
uint32_t *); /* count */
|
||||
|
||||
uint32_t (*Seek)(
|
||||
uint32_t, /* file ID */
|
||||
int64_t *, /* offset */
|
||||
uint32_t); /* whence */
|
||||
|
||||
uint32_t (*Mount)(
|
||||
char *, /* path */
|
||||
uint32_t); /* operation */
|
||||
|
||||
char *(*GetEnvironmentVariable)(
|
||||
char *); /* variable */
|
||||
|
||||
uint32_t (*SetEnvironmentVariable)(
|
||||
char *, /* variable */
|
||||
char *); /* contents */
|
||||
|
||||
uint32_t (*GetFileInformation)(
|
||||
uint32_t, /* file ID */
|
||||
void *); /* XXX */
|
||||
|
||||
uint32_t (*SetFileInformation)(
|
||||
uint32_t, /* file ID */
|
||||
uint32_t, /* XXX */
|
||||
uint32_t); /* XXX */
|
||||
|
||||
void (*FlushAllCaches)(void);
|
||||
#if !defined(sgimips)
|
||||
uint32_t (*TestUnicode)(
|
||||
uint32_t, /* file ID */
|
||||
uint16_t); /* unicode character */
|
||||
|
||||
void *(*GetDisplayStatus)(
|
||||
uint32_t); /* file ID */
|
||||
#endif
|
||||
};
|
251
sys/dev/arcbios/arcbios_tty.c
Normal file
251
sys/dev/arcbios/arcbios_tty.c
Normal file
@ -0,0 +1,251 @@
|
||||
/* $NetBSD: arcbios_tty.c,v 1.1 2001/07/08 19:58:03 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Chris G. Demetriou
|
||||
*
|
||||
* Permission to use, copy, modify and distribute this software and
|
||||
* its documentation is hereby granted, provided that both the copyright
|
||||
* notice and this permission notice appear in all copies of the
|
||||
* software, derivative works or modified versions, and any portions
|
||||
* thereof, and that both notices appear in supporting documentation.
|
||||
*
|
||||
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
||||
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
||||
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
||||
*
|
||||
* Carnegie Mellon requests users of this software to return to
|
||||
*
|
||||
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
||||
* School of Computer Science
|
||||
* Carnegie Mellon University
|
||||
* Pittsburgh PA 15213-3890
|
||||
*
|
||||
* any improvements or extensions that they make and grant Carnegie the
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/callout.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/termios.h>
|
||||
|
||||
#include <dev/cons.h>
|
||||
|
||||
#include <dev/arcbios/arcbios.h>
|
||||
#include <dev/arcbios/arcbiosvar.h>
|
||||
|
||||
struct callout arcbios_tty_ch = CALLOUT_INITIALIZER;
|
||||
|
||||
static struct tty *arcbios_tty[1];
|
||||
|
||||
extern struct consdev arcbios_cn;
|
||||
|
||||
void arcbios_tty_start(struct tty *);
|
||||
void arcbios_tty_poll(void *);
|
||||
int arcbios_tty_param(struct tty *, struct termios *);
|
||||
|
||||
cdev_decl(arcbios_tty);
|
||||
|
||||
int
|
||||
arcbios_ttyopen(dev_t dev, int flag, int mode, struct proc *p)
|
||||
{
|
||||
int unit = minor(dev);
|
||||
struct tty *tp;
|
||||
int s, maj, error = 0, setuptimeout = 0;
|
||||
|
||||
if (unit != 0)
|
||||
return (ENODEV);
|
||||
|
||||
s = spltty();
|
||||
|
||||
if (arcbios_tty[unit] == NULL) {
|
||||
tp = arcbios_tty[unit] = ttymalloc();
|
||||
tty_attach(tp);
|
||||
} else
|
||||
tp = arcbios_tty[unit];
|
||||
|
||||
tp->t_oproc = arcbios_tty_start;
|
||||
tp->t_param = arcbios_tty_param;
|
||||
tp->t_dev = dev;
|
||||
if ((tp->t_state & TS_ISOPEN) == 0) {
|
||||
tp->t_state |= TS_CARR_ON;
|
||||
ttychars(tp);
|
||||
tp->t_iflag = TTYDEF_IFLAG;
|
||||
tp->t_oflag = TTYDEF_OFLAG;
|
||||
tp->t_cflag = TTYDEF_CFLAG | CLOCAL;
|
||||
tp->t_lflag = TTYDEF_LFLAG;
|
||||
tp->t_ispeed = tp->t_ospeed = 9600;
|
||||
ttsetwater(tp);
|
||||
|
||||
setuptimeout = 1;
|
||||
|
||||
/*
|
||||
* Initialize the ARC BIOS console device major.
|
||||
*/
|
||||
for (maj = 0; maj < nchrdev; maj++)
|
||||
if (cdevsw[maj].d_open == arcbios_ttyopen)
|
||||
break;
|
||||
arcbios_cn.cn_dev = makedev(maj, 0);
|
||||
} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
|
||||
splx(s);
|
||||
return (EBUSY);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
|
||||
error = (*tp->t_linesw->l_open)(dev, tp);
|
||||
if (error == 0 && setuptimeout)
|
||||
callout_reset(&arcbios_tty_ch, 1, arcbios_tty_poll, tp);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_ttyclose(dev_t dev, int flag, int mode, struct proc *p)
|
||||
{
|
||||
int unit = minor(dev);
|
||||
struct tty *tp = arcbios_tty[unit];
|
||||
|
||||
callout_stop(&arcbios_tty_ch);
|
||||
(*tp->t_linesw->l_close)(tp, flag);
|
||||
ttyclose(tp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_ttyread(dev_t dev, struct uio *uio, int flag)
|
||||
{
|
||||
struct tty *tp = arcbios_tty[minor(dev)];
|
||||
|
||||
return ((*tp->t_linesw->l_read)(tp, uio, flag));
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_ttywrite(dev_t dev, struct uio *uio, int flag)
|
||||
{
|
||||
struct tty *tp = arcbios_tty[minor(dev)];
|
||||
|
||||
return ((*tp->t_linesw->l_write)(tp, uio, flag));
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_ttypoll(dev_t dev, int events, struct proc *p)
|
||||
{
|
||||
struct tty *tp = arcbios_tty[minor(dev)];
|
||||
|
||||
return ((*tp->t_linesw->l_poll)(tp, events, p));
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_ttyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
||||
{
|
||||
int unit = minor(dev);
|
||||
struct tty *tp = arcbios_tty[unit];
|
||||
int error;
|
||||
|
||||
error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
|
||||
if (error >= 0)
|
||||
return (error);
|
||||
error = ttioctl(tp, cmd, data, flag, p);
|
||||
if (error >= 0)
|
||||
return (error);
|
||||
|
||||
return (ENOTTY);
|
||||
}
|
||||
|
||||
int
|
||||
arcbios_tty_param(struct tty *tp, struct termios *t)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
arcbios_tty_start(struct tty *tp)
|
||||
{
|
||||
uint32_t count;
|
||||
int s;
|
||||
|
||||
s = spltty();
|
||||
if (tp->t_state & (TS_TTSTOP | TS_BUSY))
|
||||
goto out;
|
||||
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
||||
if (tp->t_state & TS_ASLEEP) {
|
||||
tp->t_state &= ~TS_ASLEEP;
|
||||
wakeup((caddr_t)&tp->t_outq);
|
||||
}
|
||||
selwakeup(&tp->t_wsel);
|
||||
}
|
||||
tp->t_state |= TS_BUSY;
|
||||
while (tp->t_outq.c_cc != 0) {
|
||||
(*ARCBIOS->Write)(ARCBIOS_STDOUT, tp->t_outq.c_cf,
|
||||
ndqb(&tp->t_outq, 0), &count);
|
||||
ndflush(&tp->t_outq, count);
|
||||
}
|
||||
tp->t_state &= ~TS_BUSY;
|
||||
out:
|
||||
splx(s);
|
||||
}
|
||||
|
||||
void
|
||||
arcbios_ttystop(struct tty *tp, int flag)
|
||||
{
|
||||
int s;
|
||||
|
||||
s = spltty();
|
||||
if (tp->t_state & TS_BUSY)
|
||||
if ((tp->t_state & TS_TTSTOP) == 0)
|
||||
tp->t_state |= TS_FLUSH;
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static int
|
||||
arcbios_tty_getchar(int *cp)
|
||||
{
|
||||
char c;
|
||||
int32_t q;
|
||||
u_int32_t count;
|
||||
|
||||
q = ARCBIOS->GetReadStatus(ARCBIOS_STDIN);
|
||||
|
||||
if (q == 0) {
|
||||
ARCBIOS->Read(ARCBIOS_STDIN, &c, 1, &count);
|
||||
*cp = c;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
arcbios_tty_poll(void *v)
|
||||
{
|
||||
struct tty *tp = v;
|
||||
int c, l_r;
|
||||
|
||||
while (arcbios_tty_getchar(&c)) {
|
||||
if (tp->t_state & TS_ISOPEN)
|
||||
l_r = (*tp->t_linesw->l_rint)(c, tp);
|
||||
}
|
||||
callout_reset(&arcbios_tty_ch, 1, arcbios_tty_poll, tp);
|
||||
}
|
||||
|
||||
struct tty *
|
||||
arcbios_ttytty(dev_t dev)
|
||||
{
|
||||
|
||||
if (minor(dev) != 0)
|
||||
panic("arcbios_ttytty: bogus");
|
||||
|
||||
return (arcbios_tty[0]);
|
||||
}
|
46
sys/dev/arcbios/arcbiosvar.h
Normal file
46
sys/dev/arcbios/arcbiosvar.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* $NetBSD: arcbiosvar.h,v 1.1 2001/07/08 19:58:03 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
extern const struct arcbios_spb *ARCBIOS_SPB;
|
||||
extern const struct arcbios_fv *ARCBIOS;
|
||||
|
||||
int arcbios_init(vaddr_t);
|
||||
|
||||
#endif /* _KERNEL */
|
Loading…
x
Reference in New Issue
Block a user