Commit 726978f5 authored by Ralf Bächle's avatar Ralf Bächle Committed by Linus Torvalds

[PATCH] drivers/sgi update

This updates drivers/sgi by removing it :-)  With all the conceptually
wrong code which has was rewritten or should be rewritten or better
live elsewhere there just was no point in keeping this directory around
any longer.
parent 98ebe7d3
#
# Character device configuration
#
menu "SGI devices"
depends on SGI_IP22
config SGI_SERIAL
bool "SGI Zilog85C30 serial support"
help
If you want to use your SGI's built-in serial ports under Linux,
answer Y.
config SERIAL_CONSOLE
bool "Support for console on serial port"
depends on SGI_SERIAL
---help---
If you say Y here, it will be possible to use a serial port as the
system console (the system console is the device which receives all
kernel messages and warnings and which allows logins in single user
mode). This could be useful if some terminal or printer is connected
to that serial port.
Even if you say Y here, the currently visible virtual console
(/dev/tty0) will still be used as the system console by default, but
you can alter that using a kernel command line option such as
"console=ttyS1". (Try "man bootparam" or see the documentation of
your boot loader (lilo or loadlin) about how to pass options to the
kernel at boot time.)
If you don't have a VGA card installed and you say Y here, the
kernel will automatically use the first serial line, /dev/ttyS0, as
system console.
If unsure, say N.
config SGI_DS1286
bool "SGI DS1286 RTC support"
help
If you say Y here and create a character special file /dev/rtc with
major number 10 and minor number 135 using mknod ("man mknod"), you
will get access to the real time clock built into your computer.
Every SGI has such a clock built in. It reports status information
via the file /proc/rtc and its behaviour is set by various ioctls on
/dev/rtc.
config SGI_NEWPORT_GFX
tristate "SGI Newport Graphics support (EXPERIMENTAL)"
depends on EXPERIMENTAL
help
If you have an SGI machine and you want to compile the graphics
drivers, say Y here. This will include the code for the
/dev/graphics and /dev/gfx drivers into the kernel for supporting
virtualized access to your graphics hardware.
endmenu
#
# Makefile for the linux kernel.
#
#
# Character and Audio devices for SGI machines.
#
subdir-m += char
obj-y += char/
#
# Makefile for the linux kernel.
#
obj-y := newport.o shmiq.o sgicons.o usema.o streamable.o
obj-$(CONFIG_SGI_SERIAL) += sgiserial.o
obj-$(CONFIG_SGI_DS1286) += ds1286.o
obj-$(CONFIG_SGI_NEWPORT_GFX) += graphics.o rrm.o
/*
* DS1286 Real Time Clock interface for Linux
*
* Copyright (C) 1998, 1999, 2000 Ralf Baechle
*
* Based on code written by Paul Gortmaker.
*
* This driver allows use of the real time clock (built into nearly all
* computers) from user space. It exports the /dev/rtc interface supporting
* various ioctl() and also the /proc/rtc pseudo-file for status
* information.
*
* The ioctls can be used to set the interrupt behaviour and generation rate
* from the RTC via IRQ 8. Then the /dev/rtc interface can be used to make
* use of these timer interrupts, be they interval or alarm based.
*
* The /dev/rtc interface will block on reads until an interrupt has been
* received. If a RTC interrupt has already happened, it will output an
* unsigned long and then block. The output value contains the interrupt
* status in the low byte and the number of interrupts since the last read
* in the remaining high bytes. The /dev/rtc interface can also be used with
* the select(2) call.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/rtc.h>
#include <linux/spinlock.h>
#include <linux/bcd.h>
#include <asm/ds1286.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#define DS1286_VERSION "1.0"
/*
* We sponge a minor off of the misc major. No need slurping
* up another valuable major dev number for this. If you add
* an ioctl, make sure you don't conflict with SPARC's RTC
* ioctls.
*/
static DECLARE_WAIT_QUEUE_HEAD(ds1286_wait);
static ssize_t ds1286_read(struct file *file, char *buf,
size_t count, loff_t *ppos);
static int ds1286_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
static unsigned int ds1286_poll(struct file *file, poll_table *wait);
void get_rtc_time (struct rtc_time *rtc_tm);
void get_rtc_alm_time (struct rtc_time *alm_tm);
void set_rtc_irq_bit(unsigned char bit);
void clear_rtc_irq_bit(unsigned char bit);
static inline unsigned char ds1286_is_updating(void);
static spinlock_t ds1286_lock = SPIN_LOCK_UNLOCKED;
/*
* Bits in rtc_status. (7 bits of room for future expansion)
*/
#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */
#define RTC_TIMER_ON 0x02 /* missed irq timer active */
unsigned char ds1286_status; /* bitmapped status byte. */
unsigned long ds1286_freq; /* Current periodic IRQ rate */
unsigned char days_in_mo[] =
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*
* Now all the various file operations that we export.
*/
static ssize_t ds1286_read(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
return -EIO;
}
static int ds1286_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct rtc_time wtime;
switch (cmd) {
case RTC_AIE_OFF: /* Mask alarm int. enab. bit */
{
unsigned int flags;
unsigned char val;
if (!capable(CAP_SYS_TIME))
return -EACCES;
spin_lock_irqsave(&ds1286_lock, flags);
val = CMOS_READ(RTC_CMD);
val |= RTC_TDM;
CMOS_WRITE(val, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
return 0;
}
case RTC_AIE_ON: /* Allow alarm interrupts. */
{
unsigned int flags;
unsigned char val;
if (!capable(CAP_SYS_TIME))
return -EACCES;
spin_lock_irqsave(&ds1286_lock, flags);
val = CMOS_READ(RTC_CMD);
val &= ~RTC_TDM;
CMOS_WRITE(val, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
return 0;
}
case RTC_WIE_OFF: /* Mask watchdog int. enab. bit */
{
unsigned int flags;
unsigned char val;
if (!capable(CAP_SYS_TIME))
return -EACCES;
spin_lock_irqsave(&ds1286_lock, flags);
val = CMOS_READ(RTC_CMD);
val |= RTC_WAM;
CMOS_WRITE(val, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
return 0;
}
case RTC_WIE_ON: /* Allow watchdog interrupts. */
{
unsigned int flags;
unsigned char val;
if (!capable(CAP_SYS_TIME))
return -EACCES;
spin_lock_irqsave(&ds1286_lock, flags);
val = CMOS_READ(RTC_CMD);
val &= ~RTC_WAM;
CMOS_WRITE(val, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
return 0;
}
case RTC_ALM_READ: /* Read the present alarm time */
{
/*
* This returns a struct rtc_time. Reading >= 0xc0
* means "don't care" or "match all". Only the tm_hour,
* tm_min, and tm_sec values are filled in.
*/
get_rtc_alm_time(&wtime);
break;
}
case RTC_ALM_SET: /* Store a time into the alarm */
{
/*
* This expects a struct rtc_time. Writing 0xff means
* "don't care" or "match all". Only the tm_hour,
* tm_min and tm_sec are used.
*/
unsigned char hrs, min, sec;
struct rtc_time alm_tm;
if (!capable(CAP_SYS_TIME))
return -EACCES;
if (copy_from_user(&alm_tm, (struct rtc_time*)arg,
sizeof(struct rtc_time)))
return -EFAULT;
hrs = alm_tm.tm_hour;
min = alm_tm.tm_min;
if (hrs >= 24)
hrs = 0xff;
if (min >= 60)
min = 0xff;
BIN_TO_BCD(sec);
BIN_TO_BCD(min);
BIN_TO_BCD(hrs);
spin_lock(&ds1286_lock);
CMOS_WRITE(hrs, RTC_HOURS_ALARM);
CMOS_WRITE(min, RTC_MINUTES_ALARM);
spin_unlock(&ds1286_lock);
return 0;
}
case RTC_RD_TIME: /* Read the time/date from RTC */
{
get_rtc_time(&wtime);
break;
}
case RTC_SET_TIME: /* Set the RTC */
{
struct rtc_time rtc_tm;
unsigned char mon, day, hrs, min, sec, leap_yr;
unsigned char save_control;
unsigned int yrs, flags;
if (!capable(CAP_SYS_TIME))
return -EACCES;
if (copy_from_user(&rtc_tm, (struct rtc_time*)arg,
sizeof(struct rtc_time)))
return -EFAULT;
yrs = rtc_tm.tm_year + 1900;
mon = rtc_tm.tm_mon + 1; /* tm_mon starts at zero */
day = rtc_tm.tm_mday;
hrs = rtc_tm.tm_hour;
min = rtc_tm.tm_min;
sec = rtc_tm.tm_sec;
if (yrs < 1970)
return -EINVAL;
leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400));
if ((mon > 12) || (day == 0))
return -EINVAL;
if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr)))
return -EINVAL;
if ((hrs >= 24) || (min >= 60) || (sec >= 60))
return -EINVAL;
if ((yrs -= 1940) > 255) /* They are unsigned */
return -EINVAL;
if (yrs >= 100)
yrs -= 100;
BIN_TO_BCD(sec);
BIN_TO_BCD(min);
BIN_TO_BCD(hrs);
BIN_TO_BCD(day);
BIN_TO_BCD(mon);
BIN_TO_BCD(yrs);
spin_lock_irqsave(&ds1286_lock, flags);
save_control = CMOS_READ(RTC_CMD);
CMOS_WRITE((save_control|RTC_TE), RTC_CMD);
CMOS_WRITE(yrs, RTC_YEAR);
CMOS_WRITE(mon, RTC_MONTH);
CMOS_WRITE(day, RTC_DATE);
CMOS_WRITE(hrs, RTC_HOURS);
CMOS_WRITE(min, RTC_MINUTES);
CMOS_WRITE(sec, RTC_SECONDS);
CMOS_WRITE(0, RTC_HUNDREDTH_SECOND);
CMOS_WRITE(save_control, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
return 0;
}
default:
return -EINVAL;
}
return copy_to_user((void *)arg, &wtime, sizeof wtime) ? -EFAULT : 0;
}
/*
* We enforce only one user at a time here with the open/close.
* Also clear the previous interrupt data on an open, and clean
* up things on a close.
*/
static int ds1286_open(struct inode *inode, struct file *file)
{
spin_lock_irq(&ds1286_lock);
if (ds1286_status & RTC_IS_OPEN)
goto out_busy;
ds1286_status |= RTC_IS_OPEN;
spin_lock_irq(&ds1286_lock);
return 0;
out_busy:
spin_lock_irq(&ds1286_lock);
return -EBUSY;
}
static int ds1286_release(struct inode *inode, struct file *file)
{
ds1286_status &= ~RTC_IS_OPEN;
return 0;
}
static unsigned int ds1286_poll(struct file *file, poll_table *wait)
{
poll_wait(file, &ds1286_wait, wait);
return 0;
}
/*
* The various file operations we support.
*/
static struct file_operations ds1286_fops = {
.llseek = no_llseek,
.read = ds1286_read,
.poll = ds1286_poll,
.ioctl = ds1286_ioctl,
.open = ds1286_open,
.release = ds1286_release,
};
static struct miscdevice ds1286_dev=
{
RTC_MINOR,
"rtc",
&ds1286_fops
};
int __init ds1286_init(void)
{
printk(KERN_INFO "DS1286 Real Time Clock Driver v%s\n", DS1286_VERSION);
return misc_register(&ds1286_dev);
}
static char *days[] = {
"***", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/*
* Info exported via "/proc/rtc".
*/
int get_ds1286_status(char *buf)
{
char *p, *s;
struct rtc_time tm;
unsigned char hundredth, month, cmd, amode;
p = buf;
get_rtc_time(&tm);
hundredth = CMOS_READ(RTC_HUNDREDTH_SECOND);
BCD_TO_BIN(hundredth);
p += sprintf(p,
"rtc_time\t: %02d:%02d:%02d.%02d\n"
"rtc_date\t: %04d-%02d-%02d\n",
tm.tm_hour, tm.tm_min, tm.tm_sec, hundredth,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
/*
* We implicitly assume 24hr mode here. Alarm values >= 0xc0 will
* match any value for that particular field. Values that are
* greater than a valid time, but less than 0xc0 shouldn't appear.
*/
get_rtc_alm_time(&tm);
p += sprintf(p, "alarm\t\t: %s ", days[tm.tm_wday]);
if (tm.tm_hour <= 24)
p += sprintf(p, "%02d:", tm.tm_hour);
else
p += sprintf(p, "**:");
if (tm.tm_min <= 59)
p += sprintf(p, "%02d\n", tm.tm_min);
else
p += sprintf(p, "**\n");
month = CMOS_READ(RTC_MONTH);
p += sprintf(p,
"oscillator\t: %s\n"
"square_wave\t: %s\n",
(month & RTC_EOSC) ? "disabled" : "enabled",
(month & RTC_ESQW) ? "disabled" : "enabled");
amode = ((CMOS_READ(RTC_MINUTES_ALARM) & 0x80) >> 5) |
((CMOS_READ(RTC_HOURS_ALARM) & 0x80) >> 6) |
((CMOS_READ(RTC_DAY_ALARM) & 0x80) >> 7);
if (amode == 7) s = "each minute";
else if (amode == 3) s = "minutes match";
else if (amode == 1) s = "hours and minutes match";
else if (amode == 0) s = "days, hours and minutes match";
else s = "invalid";
p += sprintf(p, "alarm_mode\t: %s\n", s);
cmd = CMOS_READ(RTC_CMD);
p += sprintf(p,
"alarm_enable\t: %s\n"
"wdog_alarm\t: %s\n"
"alarm_mask\t: %s\n"
"wdog_alarm_mask\t: %s\n"
"interrupt_mode\t: %s\n"
"INTB_mode\t: %s_active\n"
"interrupt_pins\t: %s\n",
(cmd & RTC_TDF) ? "yes" : "no",
(cmd & RTC_WAF) ? "yes" : "no",
(cmd & RTC_TDM) ? "disabled" : "enabled",
(cmd & RTC_WAM) ? "disabled" : "enabled",
(cmd & RTC_PU_LVL) ? "pulse" : "level",
(cmd & RTC_IBH_LO) ? "low" : "high",
(cmd & RTC_IPSW) ? "unswapped" : "swapped");
return p - buf;
}
/*
* Returns true if a clock update is in progress
*/
static inline unsigned char ds1286_is_updating(void)
{
return CMOS_READ(RTC_CMD) & RTC_TE;
}
void get_rtc_time(struct rtc_time *rtc_tm)
{
unsigned long uip_watchdog = jiffies;
unsigned char save_control;
unsigned int flags;
/*
* read RTC once any update in progress is done. The update
* can take just over 2ms. We wait 10 to 20ms. There is no need to
* to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
* If you need to know *exactly* when a second has started, enable
* periodic update complete interrupts, (via ioctl) and then
* immediately read /dev/rtc which will block until you get the IRQ.
* Once the read clears, read the RTC time (again via ioctl). Easy.
*/
if (ds1286_is_updating() != 0)
while (jiffies - uip_watchdog < 2*HZ/100)
barrier();
/*
* Only the values that we read from the RTC are set. We leave
* tm_wday, tm_yday and tm_isdst untouched. Even though the
* RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
* by the RTC when initially set to a non-zero value.
*/
spin_lock_irqsave(&ds1286_lock, flags);
save_control = CMOS_READ(RTC_CMD);
CMOS_WRITE((save_control|RTC_TE), RTC_CMD);
rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
rtc_tm->tm_hour = CMOS_READ(RTC_HOURS) & 0x1f;
rtc_tm->tm_mday = CMOS_READ(RTC_DATE);
rtc_tm->tm_mon = CMOS_READ(RTC_MONTH) & 0x1f;
rtc_tm->tm_year = CMOS_READ(RTC_YEAR);
CMOS_WRITE(save_control, RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
BCD_TO_BIN(rtc_tm->tm_sec);
BCD_TO_BIN(rtc_tm->tm_min);
BCD_TO_BIN(rtc_tm->tm_hour);
BCD_TO_BIN(rtc_tm->tm_mday);
BCD_TO_BIN(rtc_tm->tm_mon);
BCD_TO_BIN(rtc_tm->tm_year);
/*
* Account for differences between how the RTC uses the values
* and how they are defined in a struct rtc_time;
*/
if (rtc_tm->tm_year < 45)
rtc_tm->tm_year += 30;
if ((rtc_tm->tm_year += 40) < 70)
rtc_tm->tm_year += 100;
rtc_tm->tm_mon--;
}
void get_rtc_alm_time(struct rtc_time *alm_tm)
{
unsigned char cmd;
unsigned int flags;
/*
* Only the values that we read from the RTC are set. That
* means only tm_wday, tm_hour, tm_min.
*/
spin_lock_irqsave(&ds1286_lock, flags);
alm_tm->tm_min = CMOS_READ(RTC_MINUTES_ALARM) & 0x7f;
alm_tm->tm_hour = CMOS_READ(RTC_HOURS_ALARM) & 0x1f;
alm_tm->tm_wday = CMOS_READ(RTC_DAY_ALARM) & 0x07;
cmd = CMOS_READ(RTC_CMD);
spin_unlock_irqrestore(&ds1286_lock, flags);
BCD_TO_BIN(alm_tm->tm_min);
BCD_TO_BIN(alm_tm->tm_hour);
alm_tm->tm_sec = 0;
}
/*
* This is a temporary measure, we should eventually migrate to
* Gert's generic graphic console code.
*/
#define cmapsz 8192
#define CHAR_HEIGHT 16
struct console_ops {
void (*set_origin)(unsigned short offset);
void (*hide_cursor)(void);
void (*set_cursor)(int currcons);
void (*get_scrmem)(int currcons);
void (*set_scrmem)(int currcons, long offset);
int (*set_get_cmap)(unsigned char *arg, int set);
void (*blitc)(unsigned short charattr, unsigned long addr);
void (*memsetw)(void *s, unsigned short c, unsigned int count);
void (*memcpyw)(unsigned short *to, unsigned short *from, unsigned int count);
};
void register_gconsole (struct console_ops *);
/* This points to the system console */
extern struct console_ops *gconsole;
extern void gfx_init (const char **name);
extern void __set_origin (unsigned short offset);
extern void hide_cursor (void);
extern unsigned char vga_font[];
extern void disable_gconsole (void);
extern void enable_gconsole (void);
/*
* gfx.c: support for SGI's /dev/graphics, /dev/opengl
*
* Author: Miguel de Icaza (miguel@nuclecu.unam.mx)
* Ralf Baechle (ralf@gnu.org)
* Ulf Carlsson (ulfc@bun.falkenberg.se)
*
* On IRIX, /dev/graphics is [10, 146]
* /dev/opengl is [10, 147]
*
* From a mail with Mark J. Kilgard, /dev/opengl and /dev/graphics are
* the same thing, the use of /dev/graphics seems deprecated though.
*
* The reason that the original SGI programmer had to use only one
* device for all the graphic cards on the system will remain a
* mistery for the rest of our lives. Why some ioctls take a board
* number and some others not? Mistery. Why do they map the hardware
* registers into the user address space with an ioctl instead of
* mmap? Mistery too. Why they did not use the standard way of
* making ioctl constants and instead sticked a random constant?
* Mistery too.
*
* We implement those misterious things, and tried not to think about
* the reasons behind them.
*/
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include "gconsole.h"
#include "graphics.h"
#include "usema.h"
#include <asm/gfx.h>
#include <asm/rrm.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <video/newport.h>
#define DEBUG
/* The boards */
extern struct graphics_ops *newport_probe (int, const char **);
static struct graphics_ops cards [MAXCARDS];
static int boards;
#define GRAPHICS_CARD(inode) 0
/*
void enable_gconsole(void) {};
void disable_gconsole(void) {};
*/
int
sgi_graphics_open (struct inode *inode, struct file *file)
{
struct newport_regs *nregs =
(struct newport_regs *) KSEG1ADDR(cards[0].g_regs);
newport_wait();
nregs->set.wrmask = 0xffffffff;
nregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX |
NPORT_DMODE0_STOPY);
nregs->set.colori = 1;
nregs->set.xystarti = (0 << 16) | 0;
nregs->go.xyendi = (1280 << 16) | 1024;
return 0;
}
int
sgi_graphics_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
unsigned int board;
unsigned int devnum = GRAPHICS_CARD (inode->i_rdev);
int i;
if ((cmd >= RRM_BASE) && (cmd <= RRM_CMD_LIMIT))
return rrm_command (cmd-RRM_BASE, (void *) arg);
switch (cmd){
case GFX_GETNUM_BOARDS:
return boards;
case GFX_GETBOARD_INFO: {
struct gfx_getboardinfo_args *bia = (void *) arg;
void *dest_buf;
int max_len;
i = verify_area (VERIFY_READ, (void *) arg, sizeof (struct gfx_getboardinfo_args));
if (i) return i;
if (__get_user (board, &bia->board) ||
__get_user (dest_buf, &bia->buf) ||
__get_user (max_len, &bia->len))
return -EFAULT;
if (board >= boards)
return -EINVAL;
if (max_len < sizeof (struct gfx_getboardinfo_args))
return -EINVAL;
if (max_len > cards [board].g_board_info_len)
max_len = cards [boards].g_board_info_len;
i = verify_area (VERIFY_WRITE, dest_buf, max_len);
if (i) return i;
if (copy_to_user (dest_buf, cards [board].g_board_info, max_len))
return -EFAULT;
return max_len;
}
case GFX_ATTACH_BOARD: {
struct gfx_attach_board_args *att = (void *) arg;
void *vaddr;
int r;
i = verify_area (VERIFY_READ, (void *)arg, sizeof (struct gfx_attach_board_args));
if (i) return i;
if (__get_user (board, &att->board) ||
__get_user (vaddr, &att->vaddr))
return -EFAULT;
/* Ok for now we are assuming /dev/graphicsN -> head N even
* if the ioctl api suggests that this is not quite the case.
*
* Otherwise we fail, we use this assumption in the mmap code
* below to find our board information.
*/
if (board != devnum){
printk ("Parameter board does not match the current board\n");
return -EINVAL;
}
if (board >= boards)
return -EINVAL;
/* If it is the first opening it, then make it the board owner */
if (!cards [board].g_owner)
cards [board].g_owner = current;
/*
* Ok, we now call mmap on this file, which will end up calling
* sgi_graphics_mmap
*/
disable_gconsole ();
down_write(&current->mm->mmap_sem);
r = do_mmap (file, (unsigned long)vaddr,
cards[board].g_regs_size, PROT_READ|PROT_WRITE,
MAP_FIXED|MAP_PRIVATE, 0);
up_write(&current->mm->mmap_sem);
if (r)
return r;
}
/* Strange, the real mapping seems to be done at GFX_ATTACH_BOARD,
* GFX_MAPALL is not even used by IRIX X server
*/
case GFX_MAPALL:
return 0;
case GFX_LABEL:
return 0;
/* Version check
* for my IRIX 6.2 X server, this is what the kernel returns
*/
case 1:
return 3;
/* Xsgi does not use this one, I assume minor is the board being queried */
case GFX_IS_MANAGED:
if (devnum > boards)
return -EINVAL;
return (cards [devnum].g_owner != 0);
default:
if (cards [devnum].g_ioctl)
return (*cards [devnum].g_ioctl)(devnum, cmd, arg);
}
return -EINVAL;
}
int
sgi_graphics_close (struct inode *inode, struct file *file)
{
int board = GRAPHICS_CARD (inode->i_rdev);
/* Tell the rendering manager that one client is going away */
rrm_close (inode, file);
/* Was this file handle from the board owner?, clear it */
if (current == cards [board].g_owner){
cards [board].g_owner = 0;
if (cards [board].g_reset_console)
(*cards [board].g_reset_console)();
enable_gconsole ();
}
return 0;
}
/*
* This is the core of the direct rendering engine.
*/
struct page *
sgi_graphics_nopage (struct vm_area_struct *vma, unsigned long address, int
no_share)
{
pgd_t *pgd; pmd_t *pmd; pte_t *pte;
int board = GRAPHICS_CARD (vma->vm_dentry->d_inode->i_rdev);
unsigned long virt_add, phys_add;
struct page * page;
#ifdef DEBUG
printk ("Got a page fault for board %d address=%lx guser=%lx\n", board,
address, (unsigned long) cards[board].g_user);
#endif
/* Figure out if another process has this mapped, and revoke the mapping
* in that case. */
if (cards[board].g_user && cards[board].g_user != current) {
/* FIXME: save graphics context here, dump it to rendering
* node? */
remove_mapping(vma, cards[board].g_user, vma->vm_start, vma->vm_end);
}
cards [board].g_user = current;
/* Map the physical address of the newport registers into the address
* space of this process */
virt_add = address & PAGE_MASK;
phys_add = cards[board].g_regs + virt_add - vma->vm_start;
remap_page_range(vma, virt_add, phys_add, PAGE_SIZE, vma->vm_page_prot);
pgd = pgd_offset(current->mm, address);
pmd = pmd_offset(pgd, address);
pte = pte_kmap_offset(pmd, address);
page = pte_page(*pte);
pte_kunmap(pte);
return page;
}
/*
* We convert a GFX ioctl for mapping hardware registers, in a nice sys_mmap
* call, which takes care of everything that must be taken care of.
*
*/
static struct vm_operations_struct graphics_mmap = {
.nopage = sgi_graphics_nopage, /* our magic no-page fault handler */
};
int
sgi_graphics_mmap (struct file *file, struct vm_area_struct *vma)
{
uint size;
size = vma->vm_end - vma->vm_start;
/* 1. Set our special graphic virtualizer */
vma->vm_ops = &graphics_mmap;
/* 2. Set the special tlb permission bits */
vma->vm_page_prot = PAGE_USERIO;
/* final setup */
vma->vm_file = file;
return 0;
}
#if 0
/* Do any post card-detection setup on graphics_ops */
static void
graphics_ops_post_init (int slot)
{
/* There is no owner for the card initially */
cards [slot].g_owner = (struct task_struct *) 0;
cards [slot].g_user = (struct task_struct *) 0;
}
#endif
struct file_operations sgi_graphics_fops = {
.ioctl = sgi_graphics_ioctl,
.mmap = sgi_graphics_mmap,
.open = sgi_graphics_open,
.release = sgi_graphics_close,
};
/* /dev/graphics */
static struct miscdevice dev_graphics = {
SGI_GRAPHICS_MINOR, "sgi-graphics", &sgi_graphics_fops
};
/* /dev/opengl */
static struct miscdevice dev_opengl = {
SGI_OPENGL_MINOR, "sgi-opengl", &sgi_graphics_fops
};
/* This is called later from the misc-init routine */
void __init gfx_register (void)
{
misc_register (&dev_graphics);
misc_register (&dev_opengl);
}
void __init gfx_init (const char **name)
{
#if 0
struct console_ops *console;
struct graphics_ops *g;
#endif
printk ("GFX INIT: ");
shmiq_init ();
usema_init ();
boards++;
#if 0
if ((g = newport_probe (boards, name)) != 0) {
cards [boards] = *g;
graphics_ops_post_init (boards);
boards++;
console = 0;
}
/* Add more graphic drivers here */
/* Keep passing console around */
#endif
if (boards > MAXCARDS)
printk (KERN_WARNING "Too many cards found on the system\n");
}
#ifdef MODULE
MODULE_LICENSE("GPL");
int init_module(void) {
static int initiated = 0;
printk("SGI Newport Graphics version %i.%i.%i\n",42,54,69);
if (!initiated++) {
shmiq_init();
usema_init();
printk("Adding first board\n");
boards++;
cards[0].g_regs = 0x1f0f0000;
cards[0].g_regs_size = sizeof (struct newport_regs);
}
printk("Boards: %d\n", boards);
misc_register (&dev_graphics);
misc_register (&dev_opengl);
return 0;
}
void cleanup_module(void) {
printk("Shutting down SGI Newport Graphics\n");
misc_deregister (&dev_graphics);
misc_deregister (&dev_opengl);
}
#endif
#define MAXCARDS 4
struct graphics_ops {
/* SGIism: Board owner, gets the shmiq requests from the kernel */
struct task_struct *g_owner;
/* Last process that got the graphics registers mapped */
struct task_struct *g_user;
/* Board info */
void *g_board_info;
int g_board_info_len;
/* These point to hardware registers that should be mapped with
* GFX_ATTACH_BOARD and the size of the information pointed to
*/
unsigned long g_regs;
int g_regs_size;
void (*g_save_context)(void *);
void (*g_restore_context)(void *);
void (*g_reset_console)(void);
int (*g_ioctl)(int device, int cmd, unsigned long arg);
};
void shmiq_init (void);
void streamable_init (void);
/*
* newport.c: context switching the newport graphics card and
* newport graphics support.
*
* Author: Miguel de Icaza
*/
#include <linux/errno.h>
#include <linux/sched.h>
#include <asm/types.h>
#include <asm/gfx.h>
#include <asm/ng1.h>
#include <asm/uaccess.h>
#include <video/newport.h>
#include <linux/module.h>
struct newport_regs *npregs;
EXPORT_SYMBOL(npregs);
/* Kernel routines for supporting graphics context switching */
void newport_save (void *y)
{
newport_ctx *x = y;
newport_wait ();
#define LOAD(val) x->val = npregs->set.val;
#define LOADI(val) x->val = npregs->set.val.word;
#define LOADC(val) x->val = npregs->cset.val;
LOAD(drawmode1);
LOAD(drawmode0);
LOAD(lsmode);
LOAD(lspattern);
LOAD(lspatsave);
LOAD(zpattern);
LOAD(colorback);
LOAD(colorvram);
LOAD(alpharef);
LOAD(smask0x);
LOAD(smask0y);
LOADI(_xstart);
LOADI(_ystart);
LOADI(_xend);
LOADI(_yend);
LOAD(xsave);
LOAD(xymove);
LOADI(bresd);
LOADI(bress1);
LOAD(bresoctinc1);
LOAD(bresrndinc2);
LOAD(brese1);
LOAD(bress2);
LOAD(aweight0);
LOAD(aweight1);
LOADI(colorred);
LOADI(coloralpha);
LOADI(colorgrn);
LOADI(colorblue);
LOADI(slopered);
LOADI(slopealpha);
LOADI(slopegrn);
LOADI(slopeblue);
LOAD(wrmask);
LOAD(hostrw0);
LOAD(hostrw1);
/* configregs */
LOADC(smask1x);
LOADC(smask1y);
LOADC(smask2x);
LOADC(smask2y);
LOADC(smask3x);
LOADC(smask3y);
LOADC(smask4x);
LOADC(smask4y);
LOADC(topscan);
LOADC(xywin);
LOADC(clipmode);
LOADC(config);
/* Mhm, maybe I am missing something, but it seems that
* saving/restoring the DCB is only a matter of saving these
* registers
*/
newport_bfwait ();
LOAD (dcbmode);
newport_bfwait ();
x->dcbdata0 = npregs->set.dcbdata0.byword;
newport_bfwait ();
LOAD(dcbdata1);
}
/*
* Importat things to keep in mind when restoring the newport context:
*
* 1. slopered register is stored as a 2's complete (s12.11);
* needs to be converted to a signed magnitude (s(8)12.11).
*
* 2. xsave should be stored after xstart.
*
* 3. None of the registers should be written with the GO address.
* (read the docs for more details on this).
*/
void newport_restore (void *y)
{
newport_ctx *x = y;
#define STORE(val) npregs->set.val = x->val
#define STOREI(val) npregs->set.val.word = x->val
#define STOREC(val) npregs->cset.val = x->val
newport_wait ();
STORE(drawmode1);
STORE(drawmode0);
STORE(lsmode);
STORE(lspattern);
STORE(lspatsave);
STORE(zpattern);
STORE(colorback);
STORE(colorvram);
STORE(alpharef);
STORE(smask0x);
STORE(smask0y);
STOREI(_xstart);
STOREI(_ystart);
STOREI(_xend);
STOREI(_yend);
STORE(xsave);
STORE(xymove);
STOREI(bresd);
STOREI(bress1);
STORE(bresoctinc1);
STORE(bresrndinc2);
STORE(brese1);
STORE(bress2);
STORE(aweight0);
STORE(aweight1);
STOREI(colorred);
STOREI(coloralpha);
STOREI(colorgrn);
STOREI(colorblue);
STOREI(slopered);
STOREI(slopealpha);
STOREI(slopegrn);
STOREI(slopeblue);
STORE(wrmask);
STORE(hostrw0);
STORE(hostrw1);
/* configregs */
STOREC(smask1x);
STOREC(smask1y);
STOREC(smask2x);
STOREC(smask2y);
STOREC(smask3x);
STOREC(smask3y);
STOREC(smask4x);
STOREC(smask4y);
STOREC(topscan);
STOREC(xywin);
STOREC(clipmode);
STOREC(config);
/* FIXME: restore dcb thingies */
}
int
newport_ioctl (int card, int cmd, unsigned long arg)
{
switch (cmd){
case NG1_SETDISPLAYMODE: {
struct ng1_setdisplaymode_args request;
if (copy_from_user (&request, (void *) arg, sizeof (request)))
return -EFAULT;
newport_wait ();
newport_bfwait ();
npregs->set.dcbmode = DCB_XMAP0 | XM9_CRS_FIFO_AVAIL |
DCB_DATAWIDTH_1 | R_DCB_XMAP9_PROTOCOL;
xmap9FIFOWait (npregs);
/* FIXME: timing is wrong, just be extracted from
* the per-board timing table. I still have to figure
* out where this comes from
*
* This is used to select the protocol used to talk to
* the xmap9. For now I am using 60, selecting the
* WSLOW_DCB_XMAP9_PROTOCOL.
*
* Robert Tray comments on this issue:
*
* cfreq refers to the frequency of the monitor
* (ie. the refresh rate). Our monitors run typically
* between 60 Hz and 76 Hz. But it will be as low as
* 50 Hz if you're displaying NTSC/PAL and as high as
* 120 Hz if you are runining in stereo mode. You
* might want to try the WSLOW values.
*/
xmap9SetModeReg (npregs, request.wid, request.mode, 60);
return 0;
}
case NG1_SET_CURSOR_HOTSPOT: {
struct ng1_set_cursor_hotspot request;
if (copy_from_user (&request, (void *) arg, sizeof (request)))
return -EFAULT;
/* FIXME: make request.xhot, request.yhot the hot spot */
return 0;
}
case NG1_SETGAMMARAMP0:
/* FIXME: load the gamma ramps :-) */
return 0;
}
return -EINVAL;
}
/*
* Linux Rendering Resource Manager
*
* Implements the SGI-compatible rendering resource manager.
* This takes care of implementing the virtualized video hardware
* access required for OpenGL direct rendering.
*
* Author: Miguel de Icaza (miguel@nuclecu.unam.mx)
*
* Fixes:
*/
#include <linux/module.h>
#include <asm/uaccess.h>
#include <asm/rrm.h>
int
rrm_open_rn (int rnid, void *arg)
{
return 0;
}
int
rrm_close_rn (int rnid, void *arg)
{
return 0;
}
int
rrm_bind_proc_to_rn (int rnid, void *arg)
{
return 0;
}
typedef int (*rrm_function )(void *arg);
struct {
int (*r_fn)(int rnid, void *arg);
int arg_size;
} rrm_functions [] = {
{ rrm_open_rn, sizeof (struct RRM_OpenRN) },
{ rrm_close_rn, sizeof (struct RRM_CloseRN) },
{ rrm_bind_proc_to_rn, sizeof (struct RRM_BindProcToRN) }
};
#define RRM_FUNCTIONS (sizeof (rrm_functions)/sizeof (rrm_functions [0]))
/* cmd is a number in the range [0..RRM_CMD_LIMIT-RRM_BASE] */
int
rrm_command (unsigned int cmd, void *arg)
{
int i, rnid;
if (cmd > RRM_FUNCTIONS){
printk ("Called unimplemented rrm ioctl: %d\n", cmd + RRM_BASE);
return -EINVAL;
}
i = verify_area (VERIFY_READ, arg, rrm_functions [cmd].arg_size);
if (i) return i;
if (__get_user (rnid, (int *) arg))
return -EFAULT;
return (*(rrm_functions [cmd].r_fn))(rnid, arg);
}
int
rrm_close (struct inode *inode, struct file *file)
{
/* This routine is invoked when the device is closed */
return 0;
}
EXPORT_SYMBOL(rrm_command);
EXPORT_SYMBOL(rrm_close);
/*
* sgicons.c: Setting up and registering console I/O on the SGI.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
* Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
*
* This implement a virtual console interface.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <asm/uaccess.h>
#include "gconsole.h"
/* This is the system graphics console (the first adapter found) */
struct console_ops *gconsole = 0;
struct console_ops *real_gconsole = 0;
void
enable_gconsole (void)
{
if (!gconsole)
gconsole = real_gconsole;
}
void
disable_gconsole (void)
{
if (gconsole){
real_gconsole = gconsole;
gconsole = 0;
}
}
EXPORT_SYMBOL(disable_gconsole);
EXPORT_SYMBOL(enable_gconsole);
void
register_gconsole (struct console_ops *gc)
{
if (gconsole)
return;
gconsole = gc;
}
/* sgiserial.c: Serial port driver for SGI machines.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
*/
/*
* Note: This driver seems to have been derived from some
* version of the sbus/char/zs.c driver. A lot of clean-up
* and bug fixes seem to have happened to the Sun driver in
* the intervening time. As of 21.09.1999, I have merged in
* ONLY the changes necessary to fix observed functional
* problems on the Indy. Someone really ought to do a
* thorough pass to merge in the rest of the updates.
* Better still, someone really ought to make it a common
* code module for both platforms. kevink@mips.com
*
* 20010616 - Klaus Naumann <spock@mgnet.de> : Make serial console work with
* any speed - not only 9600
*/
#include <linux/config.h> /* for CONFIG_REMOTE_DEBUG */
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/console.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/sgialib.h>
#include <asm/system.h>
#include <asm/bitops.h>
#include <asm/sgi/sgihpc.h>
#include <asm/sgi/sgint23.h>
#include <asm/uaccess.h>
#include "sgiserial.h"
#define NUM_SERIAL 1 /* One chip on board. */
#define NUM_CHANNELS (NUM_SERIAL * 2)
struct sgi_zslayout *zs_chips[NUM_SERIAL] = { 0, };
struct sgi_zschannel *zs_channels[NUM_CHANNELS] = { 0, 0, };
struct sgi_zschannel *zs_conschan;
struct sgi_zschannel *zs_kgdbchan;
struct sgi_serial zs_soft[NUM_CHANNELS];
struct sgi_serial *zs_chain; /* IRQ servicing chain */
static int zilog_irq = SGI_SERIAL_IRQ;
/* Console hooks... */
static int zs_cons_chanout;
static int zs_cons_chanin;
struct sgi_serial *zs_consinfo;
static unsigned char kgdb_regs[16] = {
0, 0, 0, /* write 0, 1, 2 */
(Rx8 | RxENABLE), /* write 3 */
(X16CLK | SB1 | PAR_EVEN), /* write 4 */
(Tx8 | TxENAB), /* write 5 */
0, 0, 0, /* write 6, 7, 8 */
(NV), /* write 9 */
(NRZ), /* write 10 */
(TCBR | RCBR), /* write 11 */
0, 0, /* BRG time constant, write 12 + 13 */
(BRENABL), /* write 14 */
(DCDIE) /* write 15 */
};
static unsigned char zscons_regs[16] = {
0, /* write 0 */
(EXT_INT_ENAB | INT_ALL_Rx), /* write 1 */
0, /* write 2 */
(Rx8 | RxENABLE), /* write 3 */
(X16CLK), /* write 4 */
(DTR | Tx8 | TxENAB), /* write 5 */
0, 0, 0, /* write 6, 7, 8 */
(NV | MIE), /* write 9 */
(NRZ), /* write 10 */
(TCBR | RCBR), /* write 11 */
0, 0, /* BRG time constant, write 12 + 13 */
(BRENABL), /* write 14 */
(DCDIE | CTSIE | TxUIE | BRKIE) /* write 15 */
};
#define ZS_CLOCK 3672000 /* Zilog input clock rate */
DECLARE_TASK_QUEUE(tq_serial);
static struct tty_driver *serial_driver;
struct console *sgisercon;
/* serial subtype definitions */
#define SERIAL_TYPE_NORMAL 1
/* number of characters left in xmit buffer before we ask for more */
#define WAKEUP_CHARS 256
/* Debugging... DEBUG_INTR is bad to use when one of the zs
* lines is your console ;(
*/
#undef SERIAL_DEBUG_INTR
#undef SERIAL_DEBUG_OPEN
#undef SERIAL_DEBUG_FLOW
#define RS_STROBE_TIME 10
#define RS_ISR_PASS_LIMIT 256
#define _INLINE_ inline
static void change_speed(struct sgi_serial *info);
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/*
* tmp_buf is used as a temporary buffer by serial_write. We need to
* lock it in case the memcpy_fromfs blocks while swapping in a page,
* and some other program tries to do a serial write at the same time.
* Since the lock will only come under contention when the system is
* swapping and available memory is low, it makes sense to share one
* buffer across all the serial ports, since it significantly saves
* memory if large numbers of serial ports are open.
*/
static unsigned char tmp_buf[4096]; /* This is cheating */
static DECLARE_MUTEX(tmp_buf_sem);
static inline int serial_paranoia_check(struct sgi_serial *info,
char *name, const char *routine)
{
#ifdef SERIAL_PARANOIA_CHECK
static const char *badmagic = KERN_WARNING
"Warning: bad magic number for serial struct %s in %s\n";
static const char *badinfo = KERN_WARNING
"Warning: null sgi_serial for %s in %s\n";
if (!info) {
printk(badinfo, name, routine);
return 1;
}
if (info->magic != SERIAL_MAGIC) {
printk(badmagic, name, routine);
return 1;
}
#endif
return 0;
}
/*
* This is used to figure out the divisor speeds and the timeouts
*/
static int baud_table[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200, 0 };
/*
* Reading and writing Zilog8530 registers. The delays are to make this
* driver work on the Sun4 which needs a settling delay after each chip
* register access, other machines handle this in hardware via auxiliary
* flip-flops which implement the settle time we do in software.
*
* read_zsreg() and write_zsreg() may get called from rs_kgdb_hook() before
* interrupts are enabled. Therefore we have to check ioc_iocontrol before we
* access it.
*/
static inline unsigned char read_zsreg(struct sgi_zschannel *channel,
unsigned char reg)
{
unsigned char retval;
volatile unsigned char junk;
udelay(2);
channel->control = reg;
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
udelay(1);
retval = channel->control;
return retval;
}
static inline void write_zsreg(struct sgi_zschannel *channel,
unsigned char reg, unsigned char value)
{
volatile unsigned char junk;
udelay(2);
channel->control = reg;
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
udelay(1);
channel->control = value;
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
return;
}
static inline void load_zsregs(struct sgi_zschannel *channel, unsigned char *regs)
{
ZS_CLEARERR(channel);
ZS_CLEARFIFO(channel);
/* Load 'em up */
write_zsreg(channel, R4, regs[R4]);
write_zsreg(channel, R10, regs[R10]);
write_zsreg(channel, R3, regs[R3] & ~RxENABLE);
write_zsreg(channel, R5, regs[R5] & ~TxENAB);
write_zsreg(channel, R1, regs[R1]);
write_zsreg(channel, R9, regs[R9]);
write_zsreg(channel, R11, regs[R11]);
write_zsreg(channel, R12, regs[R12]);
write_zsreg(channel, R13, regs[R13]);
write_zsreg(channel, R14, regs[R14]);
write_zsreg(channel, R15, regs[R15]);
write_zsreg(channel, R3, regs[R3]);
write_zsreg(channel, R5, regs[R5]);
return;
}
/* Sets or clears DTR/RTS on the requested line */
static inline void zs_rtsdtr(struct sgi_serial *ss, int set)
{
if(set) {
ss->curregs[5] |= (RTS | DTR);
ss->pendregs[5] = ss->curregs[5];
write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
} else {
ss->curregs[5] &= ~(RTS | DTR);
ss->pendregs[5] = ss->curregs[5];
write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
}
return;
}
static inline void kgdb_chaninit(struct sgi_serial *ss, int intson, int bps)
{
int brg;
if(intson) {
kgdb_regs[R1] = INT_ALL_Rx;
kgdb_regs[R9] |= MIE;
} else {
kgdb_regs[R1] = 0;
kgdb_regs[R9] &= ~MIE;
}
brg = BPS_TO_BRG(bps, ZS_CLOCK/ss->clk_divisor);
kgdb_regs[R12] = (brg & 255);
kgdb_regs[R13] = ((brg >> 8) & 255);
load_zsregs(ss->zs_channel, kgdb_regs);
}
/* Utility routines for the Zilog */
static inline int get_zsbaud(struct sgi_serial *ss)
{
struct sgi_zschannel *channel = ss->zs_channel;
int brg;
/* The baud rate is split up between two 8-bit registers in
* what is termed 'BRG time constant' format in my docs for
* the chip, it is a function of the clk rate the chip is
* receiving which happens to be constant.
*/
brg = ((read_zsreg(channel, 13)&0xff) << 8);
brg |= (read_zsreg(channel, 12)&0xff);
return BRG_TO_BPS(brg, (ZS_CLOCK/(ss->clk_divisor)));
}
/*
* ------------------------------------------------------------
* rs_stop() and rs_start()
*
* This routines are called before setting or resetting tty->stopped.
* They enable or disable transmitter interrupts, as necessary.
* ------------------------------------------------------------
*/
static void rs_stop(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "rs_stop"))
return;
save_flags(flags); cli();
if (info->curregs[5] & TxENAB) {
info->curregs[5] &= ~TxENAB;
info->pendregs[5] &= ~TxENAB;
write_zsreg(info->zs_channel, 5, info->curregs[5]);
}
restore_flags(flags);
}
static void rs_start(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "rs_start"))
return;
save_flags(flags); cli();
if (info->xmit_cnt && info->xmit_buf && !(info->curregs[5] & TxENAB)) {
info->curregs[5] |= TxENAB;
info->pendregs[5] = info->curregs[5];
write_zsreg(info->zs_channel, 5, info->curregs[5]);
}
restore_flags(flags);
}
/* Drop into either the boot monitor or kadb upon receiving a break
* from keyboard/console input.
*/
static void batten_down_hatches(void)
{
ArcEnterInteractiveMode();
#if 0
/* If we are doing kadb, we call the debugger
* else we just drop into the boot monitor.
* Note that we must flush the user windows
* first before giving up control.
*/
printk("\n");
if((((unsigned long)linux_dbvec)>=DEBUG_FIRSTVADDR) &&
(((unsigned long)linux_dbvec)<=DEBUG_LASTVADDR))
sp_enter_debugger();
else
prom_halt();
/* XXX We want to notify the keyboard driver that all
* XXX keys are in the up state or else weird things
* XXX happen...
*/
#endif
return;
}
/* On receive, this clears errors and the receiver interrupts */
static inline void rs_recv_clear(struct sgi_zschannel *zsc)
{
volatile unsigned char junk;
udelay(2);
zsc->control = ERR_RES;
junk = ioc_icontrol->istat0;
udelay(2);
zsc->control = RES_H_IUS;
junk = ioc_icontrol->istat0;
}
/*
* ----------------------------------------------------------------------
*
* Here starts the interrupt handling routines. All of the following
* subroutines are declared as inline and are folded into
* rs_interrupt(). They were separated out for readability's sake.
*
* Note: rs_interrupt() is a "fast" interrupt, which means that it
* runs with interrupts turned off. People who may want to modify
* rs_interrupt() should try to keep the interrupt handler as fast as
* possible. After you are done making modifications, it is not a bad
* idea to do:
*
* gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
*
* and look at the resulting assemble code in serial.s.
*
* - Ted Ts'o (tytso@mit.edu), 7-Mar-93
* -----------------------------------------------------------------------
*/
/*
* This routine is used by the interrupt handler to schedule
* processing in the software interrupt portion of the driver.
*/
static _INLINE_ void rs_sched_event(struct sgi_serial *info,
int event)
{
info->event |= 1 << event;
queue_task(&info->tqueue, &tq_serial);
mark_bh(SERIAL_BH);
}
#ifdef CONFIG_REMOTE_DEBUG
extern void set_async_breakpoint(unsigned int epc);
#endif
static _INLINE_ void receive_chars(struct sgi_serial *info, struct pt_regs *regs)
{
struct tty_struct *tty = info->tty;
volatile unsigned char junk;
unsigned char ch, stat;
udelay(2);
ch = info->zs_channel->data;
junk = ioc_icontrol->istat0;
udelay(2);
stat = read_zsreg(info->zs_channel, R1);
/* If this is the console keyboard, we need to handle
* L1-A's here.
*/
if(info->is_cons) {
if(ch==0) { /* whee, break received */
batten_down_hatches();
rs_recv_clear(info->zs_channel);
return;
} else if (ch == 1) {
show_state();
return;
}
}
/* Look for kgdb 'stop' character, consult the gdb documentation
* for remote target debugging and arch/sparc/kernel/sparc-stub.c
* to see how all this works.
*/
#ifdef CONFIG_REMOTE_DEBUG
if((info->kgdb_channel) && (ch =='\003')) {
set_async_breakpoint(read_32bit_cp0_register(CP0_EPC));
goto clear_and_exit;
}
#endif
if(!tty)
goto clear_and_exit;
if (tty->flip.count >= TTY_FLIPBUF_SIZE)
queue_task(&tty->flip.tqueue, &tq_timer);
tty->flip.count++;
if(stat & PAR_ERR)
*tty->flip.flag_buf_ptr++ = TTY_PARITY;
else if(stat & Rx_OVR)
*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
else if(stat & CRC_ERR)
*tty->flip.flag_buf_ptr++ = TTY_FRAME;
else
*tty->flip.flag_buf_ptr++ = 0; /* XXX */
*tty->flip.char_buf_ptr++ = ch;
queue_task(&tty->flip.tqueue, &tq_timer);
clear_and_exit:
rs_recv_clear(info->zs_channel);
return;
}
static _INLINE_ void transmit_chars(struct sgi_serial *info)
{
volatile unsigned char junk;
/* P3: In theory we have to test readiness here because a
* serial console can clog the chip through zs_cons_put_char().
* David did not do this. I think he relies on 3-chars FIFO in 8530.
* Let's watch for lost _output_ characters. XXX
*/
/* SGI ADDENDUM: On most SGI machines, the Zilog does possess
* a 16 or 17 byte fifo, so no worries. -dm
*/
if (info->x_char) {
/* Send next char */
udelay(2);
info->zs_channel->data = info->x_char;
junk = ioc_icontrol->istat0;
info->x_char = 0;
goto clear_and_return;
}
if((info->xmit_cnt <= 0) || info->tty->stopped) {
/* That's peculiar... */
udelay(2);
info->zs_channel->control = RES_Tx_P;
junk = ioc_icontrol->istat0;
goto clear_and_return;
}
/* Send char */
udelay(2);
info->zs_channel->data = info->xmit_buf[info->xmit_tail++];
junk = ioc_icontrol->istat0;
info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt--;
if (info->xmit_cnt < WAKEUP_CHARS)
rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
if(info->xmit_cnt <= 0) {
udelay(2);
info->zs_channel->control = RES_Tx_P;
junk = ioc_icontrol->istat0;
goto clear_and_return;
}
clear_and_return:
/* Clear interrupt */
udelay(2);
info->zs_channel->control = RES_H_IUS;
junk = ioc_icontrol->istat0;
return;
}
static _INLINE_ void status_handle(struct sgi_serial *info)
{
volatile unsigned char junk;
unsigned char status;
/* Get status from Read Register 0 */
udelay(2);
status = info->zs_channel->control;
junk = ioc_icontrol->istat0;
/* Clear status condition... */
udelay(2);
info->zs_channel->control = RES_EXT_INT;
junk = ioc_icontrol->istat0;
/* Clear the interrupt */
udelay(2);
info->zs_channel->control = RES_H_IUS;
junk = ioc_icontrol->istat0;
#if 0
if(status & DCD) {
if((info->tty->termios->c_cflag & CRTSCTS) &&
((info->curregs[3] & AUTO_ENAB)==0)) {
info->curregs[3] |= AUTO_ENAB;
info->pendregs[3] |= AUTO_ENAB;
write_zsreg(info->zs_channel, 3, info->curregs[3]);
}
} else {
if((info->curregs[3] & AUTO_ENAB)) {
info->curregs[3] &= ~AUTO_ENAB;
info->pendregs[3] &= ~AUTO_ENAB;
write_zsreg(info->zs_channel, 3, info->curregs[3]);
}
}
#endif
/* Whee, if this is console input and this is a
* 'break asserted' status change interrupt, call
* the boot prom.
*/
if((status & BRK_ABRT) && info->break_abort)
batten_down_hatches();
/* XXX Whee, put in a buffer somewhere, the status information
* XXX whee whee whee... Where does the information go...
*/
return;
}
/*
* This is the serial driver's generic interrupt routine
*/
void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
{
struct sgi_serial * info = (struct sgi_serial *) dev_id;
unsigned char zs_intreg;
zs_intreg = read_zsreg(info->zs_next->zs_channel, 3);
/* NOTE: The read register 3, which holds the irq status,
* does so for both channels on each chip. Although
* the status value itself must be read from the A
* channel and is only valid when read from channel A.
* Yes... broken hardware...
*/
#define CHAN_A_IRQMASK (CHARxIP | CHATxIP | CHAEXT)
#define CHAN_B_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
/* *** Chip 1 *** */
/* Channel B -- /dev/ttyb, could be the console */
if(zs_intreg & CHAN_B_IRQMASK) {
if (zs_intreg & CHBRxIP)
receive_chars(info, regs);
if (zs_intreg & CHBTxIP)
transmit_chars(info);
if (zs_intreg & CHBEXT)
status_handle(info);
}
info=info->zs_next;
/* Channel A -- /dev/ttya, could be the console */
if(zs_intreg & CHAN_A_IRQMASK) {
if (zs_intreg & CHARxIP)
receive_chars(info, regs);
if (zs_intreg & CHATxIP)
transmit_chars(info);
if (zs_intreg & CHAEXT)
status_handle(info);
}
}
/*
* -------------------------------------------------------------------
* Here ends the serial interrupt routines.
* -------------------------------------------------------------------
*/
/*
* This routine is used to handle the "bottom half" processing for the
* serial driver, known also the "software interrupt" processing.
* This processing is done at the kernel interrupt level, after the
* rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
* is where time-consuming activities which can not be done in the
* interrupt driver proper are done; the interrupt driver schedules
* them using rs_sched_event(), and they get done here.
*/
static void do_serial_bh(void)
{
run_task_queue(&tq_serial);
}
static void do_softint(void *private_)
{
struct sgi_serial *info = (struct sgi_serial *) private_;
struct tty_struct *tty;
tty = info->tty;
if (!tty)
return;
if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
tty->ldisc.write_wakeup)
(tty->ldisc.write_wakeup)(tty);
wake_up_interruptible(&tty->write_wait);
}
}
/*
* This routine is called from the scheduler tqueue when the interrupt
* routine has signalled that a hangup has occurred. The path of
* hangup processing is:
*
* serial interrupt routine -> (scheduler tqueue) ->
* do_serial_hangup() -> tty->hangup() -> rs_hangup()
*
*/
static void do_serial_hangup(void *private_)
{
struct sgi_serial *info = (struct sgi_serial *) private_;
struct tty_struct *tty;
tty = info->tty;
if (!tty)
return;
tty_hangup(tty);
}
static int startup(struct sgi_serial * info)
{
volatile unsigned char junk;
unsigned long flags;
if (info->flags & ZILOG_INITIALIZED)
return 0;
if (!info->xmit_buf) {
info->xmit_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
if (!info->xmit_buf)
return -ENOMEM;
}
save_flags(flags); cli();
#ifdef SERIAL_DEBUG_OPEN
printk("starting up ttys%d (irq %d)...\n", info->line, info->irq);
#endif
/*
* Clear the FIFO buffers and disable them
* (they will be reenabled in change_speed())
*/
ZS_CLEARFIFO(info->zs_channel);
info->xmit_fifo_size = 1;
/*
* Clear the interrupt registers.
*/
udelay(2);
info->zs_channel->control = ERR_RES;
junk = ioc_icontrol->istat0;
udelay(2);
info->zs_channel->control = RES_H_IUS;
junk = ioc_icontrol->istat0;
/*
* Now, initialize the Zilog
*/
zs_rtsdtr(info, 1);
/*
* Finally, enable sequencing and interrupts
*/
info->curregs[1] |= (info->curregs[1] & ~0x18) | (EXT_INT_ENAB|INT_ALL_Rx);
info->pendregs[1] = info->curregs[1];
info->curregs[3] |= (RxENABLE | Rx8);
info->pendregs[3] = info->curregs[3];
/* We enable Tx interrupts as needed. */
info->curregs[5] |= (TxENAB | Tx8);
info->pendregs[5] = info->curregs[5];
info->curregs[9] |= (NV | MIE);
info->pendregs[9] = info->curregs[9];
write_zsreg(info->zs_channel, 3, info->curregs[3]);
write_zsreg(info->zs_channel, 5, info->curregs[5]);
write_zsreg(info->zs_channel, 9, info->curregs[9]);
/*
* And clear the interrupt registers again for luck.
*/
udelay(2);
info->zs_channel->control = ERR_RES;
junk = ioc_icontrol->istat0;
udelay(2);
info->zs_channel->control = RES_H_IUS;
junk = ioc_icontrol->istat0;
if (info->tty)
clear_bit(TTY_IO_ERROR, &info->tty->flags);
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
/*
* and set the speed of the serial port
*/
change_speed(info);
info->flags |= ZILOG_INITIALIZED;
restore_flags(flags);
return 0;
}
/*
* This routine will shutdown a serial port; interrupts are disabled, and
* DTR is dropped if the hangup on close termio flag is on.
*/
static void shutdown(struct sgi_serial * info)
{
unsigned long flags;
if (!(info->flags & ZILOG_INITIALIZED))
return;
#ifdef SERIAL_DEBUG_OPEN
printk("Shutting down serial port %d (irq %d)....", info->line,
info->irq);
#endif
save_flags(flags); cli(); /* Disable interrupts */
if (info->xmit_buf) {
free_page((unsigned long) info->xmit_buf);
info->xmit_buf = 0;
}
if (info->tty)
set_bit(TTY_IO_ERROR, &info->tty->flags);
info->flags &= ~ZILOG_INITIALIZED;
restore_flags(flags);
}
/*
* This routine is called to set the UART divisor registers to match
* the specified baud rate for a serial port.
*/
static void change_speed(struct sgi_serial *info)
{
unsigned short port;
unsigned cflag;
int i;
int brg;
if (!info->tty || !info->tty->termios)
return;
cflag = info->tty->termios->c_cflag;
if (!(port = info->port))
return;
i = cflag & CBAUD;
if (i & CBAUDEX) {
/* XXX CBAUDEX is not obeyed.
* It is impossible at a 32bits SPARC.
* But we have to report this to user ... someday.
*/
i = B9600;
}
if (i == 0) {
/* XXX B0, hangup the line. */
do_serial_hangup(info);
} else if (baud_table[i]) {
info->zs_baud = baud_table[i];
info->clk_divisor = 16;
info->curregs[4] = X16CLK;
info->curregs[11] = TCBR | RCBR;
brg = BPS_TO_BRG(info->zs_baud, ZS_CLOCK/info->clk_divisor);
info->curregs[12] = (brg & 255);
info->curregs[13] = ((brg >> 8) & 255);
info->curregs[14] = BRENABL;
}
/* byte size and parity */
switch (cflag & CSIZE) {
case CS5:
info->curregs[3] &= ~(0xc0);
info->curregs[3] |= Rx5;
info->pendregs[3] = info->curregs[3];
info->curregs[5] &= ~(0xe0);
info->curregs[5] |= Tx5;
info->pendregs[5] = info->curregs[5];
break;
case CS6:
info->curregs[3] &= ~(0xc0);
info->curregs[3] |= Rx6;
info->pendregs[3] = info->curregs[3];
info->curregs[5] &= ~(0xe0);
info->curregs[5] |= Tx6;
info->pendregs[5] = info->curregs[5];
break;
case CS7:
info->curregs[3] &= ~(0xc0);
info->curregs[3] |= Rx7;
info->pendregs[3] = info->curregs[3];
info->curregs[5] &= ~(0xe0);
info->curregs[5] |= Tx7;
info->pendregs[5] = info->curregs[5];
break;
case CS8:
default: /* defaults to 8 bits */
info->curregs[3] &= ~(0xc0);
info->curregs[3] |= Rx8;
info->pendregs[3] = info->curregs[3];
info->curregs[5] &= ~(0xe0);
info->curregs[5] |= Tx8;
info->pendregs[5] = info->curregs[5];
break;
}
info->curregs[4] &= ~(0x0c);
if (cflag & CSTOPB) {
info->curregs[4] |= SB2;
} else {
info->curregs[4] |= SB1;
}
info->pendregs[4] = info->curregs[4];
if (cflag & PARENB) {
info->curregs[4] |= PAR_ENA;
info->pendregs[4] |= PAR_ENA;
} else {
info->curregs[4] &= ~PAR_ENA;
info->pendregs[4] &= ~PAR_ENA;
}
if (!(cflag & PARODD)) {
info->curregs[4] |= PAR_EVEN;
info->pendregs[4] |= PAR_EVEN;
} else {
info->curregs[4] &= ~PAR_EVEN;
info->pendregs[4] &= ~PAR_EVEN;
}
/* Load up the new values */
load_zsregs(info->zs_channel, info->curregs);
return;
}
/* This is for console output over ttya/ttyb */
static void zs_cons_put_char(char ch)
{
struct sgi_zschannel *chan = zs_conschan;
volatile unsigned char junk;
int flags, loops = 0;
save_flags(flags); cli();
while(((junk = chan->control) & Tx_BUF_EMP)==0 && loops < 10000) {
loops++;
udelay(2);
}
udelay(2);
chan->data = ch;
junk = ioc_icontrol->istat0;
restore_flags(flags);
}
/*
* This is the more generic put_char function for the driver.
* In earlier versions of this driver, "rs_put_char" was the
* name of the console-specific fucntion, now called zs_cons_put_char
*/
static void rs_put_char(struct tty_struct *tty, char ch)
{
struct sgi_zschannel *chan =
((struct sgi_serial *)tty->driver_data)->zs_channel;
volatile unsigned char junk;
int flags, loops = 0;
save_flags(flags); cli();
while(((junk = chan->control) & Tx_BUF_EMP)==0 && loops < 10000) {
loops++;
udelay(2);
}
udelay(2);
chan->data = ch;
junk = ioc_icontrol->istat0;
restore_flags(flags);
}
/* These are for receiving and sending characters under the kgdb
* source level kernel debugger.
*/
int putDebugChar(char kgdb_char)
{
struct sgi_zschannel *chan = zs_kgdbchan;
volatile unsigned char junk;
unsigned long flags;
save_flags(flags); cli();
udelay(2);
while((chan->control & Tx_BUF_EMP)==0)
udelay(2);
udelay(2);
chan->data = kgdb_char;
junk = ioc_icontrol->istat0;
restore_flags(flags);
return 1;
}
char getDebugChar(void)
{
struct sgi_zschannel *chan = zs_kgdbchan;
unsigned char junk;
while((chan->control & Rx_CH_AV)==0)
udelay(2);
junk = ioc_icontrol->istat0;
udelay(2);
return chan->data;
}
/*
* Fair output driver allows a process to speak.
*/
static void rs_fair_output(void)
{
int left; /* Output no more than that */
unsigned long flags;
struct sgi_serial *info = zs_consinfo;
volatile unsigned char junk;
char c;
if (info == 0) return;
if (info->xmit_buf == 0) return;
save_flags(flags); cli();
left = info->xmit_cnt;
while (left != 0) {
c = info->xmit_buf[info->xmit_tail];
info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt--;
restore_flags(flags);
zs_cons_put_char(c);
save_flags(flags); cli();
left = MIN(info->xmit_cnt, left-1);
}
/* Last character is being transmitted now (hopefully). */
udelay(2);
zs_conschan->control = RES_Tx_P;
junk = ioc_icontrol->istat0;
restore_flags(flags);
return;
}
static int rs_write(struct tty_struct * tty, int from_user,
const unsigned char *buf, int count)
{
int c, total = 0;
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "rs_write"))
return 0;
if (!tty || !info->xmit_buf)
return 0;
save_flags(flags);
while (1) {
cli();
c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
SERIAL_XMIT_SIZE - info->xmit_head));
if (c <= 0)
break;
if (from_user) {
down(&tmp_buf_sem);
copy_from_user(tmp_buf, buf, c);
c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
SERIAL_XMIT_SIZE - info->xmit_head));
memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
up(&tmp_buf_sem);
} else
memcpy(info->xmit_buf + info->xmit_head, buf, c);
info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt += c;
restore_flags(flags);
buf += c;
count -= c;
total += c;
}
if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
/*
* The above test used to include the condition
* "&& !(info->curregs[5] & TxENAB)", but there
* is reason to suspect that it is never statisfied
* when the port is running. The problem may in fact
* have been masked by the fact that, if O_POST is set,
* there is always a rs_flush_xx operation following the
* rs_write, and the flush ignores that condition when
* it kicks off the transmit.
*/
/* Enable transmitter */
info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
info->pendregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
write_zsreg(info->zs_channel, 1, info->curregs[1]);
info->curregs[5] |= TxENAB;
info->pendregs[5] |= TxENAB;
write_zsreg(info->zs_channel, 5, info->curregs[5]);
/*
* The following code is imported from the 2.3.6 Sun sbus zs.c
* driver, of which an earlier version served as the basis
* for sgiserial.c. Perhaps due to changes over time in
* the line discipline code, ns_write()s with from_user
* set would not otherwise actually kick-off output in
* Linux 2.2.x or later. Maybe it never really worked.
*/
rs_put_char(tty, info->xmit_buf[info->xmit_tail++]);
info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt--;
}
restore_flags(flags);
return total;
}
static int rs_write_room(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
int ret;
if (serial_paranoia_check(info, tty->name, "rs_write_room"))
return 0;
ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
if (ret < 0)
ret = 0;
return ret;
}
static int rs_chars_in_buffer(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
return 0;
return info->xmit_cnt;
}
static void rs_flush_buffer(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
return;
cli();
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
sti();
wake_up_interruptible(&tty->write_wait);
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
tty->ldisc.write_wakeup)
(tty->ldisc.write_wakeup)(tty);
}
static void rs_flush_chars(struct tty_struct *tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
return;
if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
!info->xmit_buf)
return;
/* Enable transmitter */
save_flags(flags); cli();
info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
info->pendregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
write_zsreg(info->zs_channel, 1, info->curregs[1]);
info->curregs[5] |= TxENAB;
info->pendregs[5] |= TxENAB;
write_zsreg(info->zs_channel, 5, info->curregs[5]);
/*
* Send a first (bootstrapping) character. A best solution is
* to call transmit_chars() here which handles output in a
* generic way. Current transmit_chars() not only transmits,
* but resets interrupts also what we do not desire here.
* XXX Discuss with David.
*/
if (info->zs_channel->control & Tx_BUF_EMP) {
volatile unsigned char junk;
/* Send char */
udelay(2);
info->zs_channel->data = info->xmit_buf[info->xmit_tail++];
junk = ioc_icontrol->istat0;
info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt--;
}
restore_flags(flags);
}
/*
* ------------------------------------------------------------
* rs_throttle()
*
* This routine is called by the upper-layer tty layer to signal that
* incoming characters should be throttled.
* ------------------------------------------------------------
*/
static void rs_throttle(struct tty_struct * tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];
printk("throttle %s: %d....\n", _tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif
if (serial_paranoia_check(info, tty->name, "rs_throttle"))
return;
if (I_IXOFF(tty))
info->x_char = STOP_CHAR(tty);
/* Turn off RTS line */
cli();
info->curregs[5] &= ~RTS;
info->pendregs[5] &= ~RTS;
write_zsreg(info->zs_channel, 5, info->curregs[5]);
sti();
}
static void rs_unthrottle(struct tty_struct * tty)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];
printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif
if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
return;
if (I_IXOFF(tty)) {
if (info->x_char)
info->x_char = 0;
else
info->x_char = START_CHAR(tty);
}
/* Assert RTS line */
cli();
info->curregs[5] |= RTS;
info->pendregs[5] |= RTS;
write_zsreg(info->zs_channel, 5, info->curregs[5]);
sti();
}
/*
* ------------------------------------------------------------
* rs_ioctl() and friends
* ------------------------------------------------------------
*/
static int get_serial_info(struct sgi_serial * info,
struct serial_struct * retinfo)
{
struct serial_struct tmp;
if (!retinfo)
return -EFAULT;
memset(&tmp, 0, sizeof(tmp));
tmp.type = info->type;
tmp.line = info->line;
tmp.port = info->port;
tmp.irq = info->irq;
tmp.flags = info->flags;
tmp.baud_base = info->baud_base;
tmp.close_delay = info->close_delay;
tmp.closing_wait = info->closing_wait;
tmp.custom_divisor = info->custom_divisor;
return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
}
static int set_serial_info(struct sgi_serial * info,
struct serial_struct * new_info)
{
struct serial_struct new_serial;
struct sgi_serial old_info;
int retval = 0;
if (!new_info)
return -EFAULT;
copy_from_user(&new_serial,new_info,sizeof(new_serial));
old_info = *info;
if (!capable(CAP_SYS_ADMIN)) {
if ((new_serial.baud_base != info->baud_base) ||
(new_serial.type != info->type) ||
(new_serial.close_delay != info->close_delay) ||
((new_serial.flags & ~ZILOG_USR_MASK) !=
(info->flags & ~ZILOG_USR_MASK)))
return -EPERM;
info->flags = ((info->flags & ~ZILOG_USR_MASK) |
(new_serial.flags & ZILOG_USR_MASK));
info->custom_divisor = new_serial.custom_divisor;
goto check_and_exit;
}
if (info->count > 1)
return -EBUSY;
/*
* OK, past this point, all the error checking has been done.
* At this point, we start making changes.....
*/
info->baud_base = new_serial.baud_base;
info->flags = ((info->flags & ~ZILOG_FLAGS) |
(new_serial.flags & ZILOG_FLAGS));
info->type = new_serial.type;
info->close_delay = new_serial.close_delay;
info->closing_wait = new_serial.closing_wait;
check_and_exit:
retval = startup(info);
return retval;
}
/*
* get_lsr_info - get line status register info
*
* Purpose: Let user call ioctl() to get info when the UART physically
* is emptied. On bus types like RS485, the transmitter must
* release the bus after transmitting. This must be done when
* the transmit shift register is empty, not be done when the
* transmit holding register is empty. This functionality
* allows an RS485 driver to be written in user space.
*/
static int get_lsr_info(struct sgi_serial * info, unsigned int *value)
{
volatile unsigned char junk;
unsigned char status;
cli();
udelay(2);
status = info->zs_channel->control;
junk = ioc_icontrol->istat0;
sti();
return put_user(status,value);
}
static int get_modem_info(struct sgi_serial * info, unsigned int *value)
{
unsigned char status;
unsigned int result;
cli();
status = info->zs_channel->control;
udelay(2);
sti();
result = ((info->curregs[5] & RTS) ? TIOCM_RTS : 0)
| ((info->curregs[5] & DTR) ? TIOCM_DTR : 0)
| ((status & DCD) ? TIOCM_CAR : 0)
| ((status & SYNC) ? TIOCM_DSR : 0)
| ((status & CTS) ? TIOCM_CTS : 0);
if (put_user(result, value))
return -EFAULT;
return 0;
}
static int set_modem_info(struct sgi_serial * info, unsigned int cmd,
unsigned int *value)
{
unsigned int arg;
if (get_user(arg, value))
return -EFAULT;
switch (cmd) {
case TIOCMBIS:
if (arg & TIOCM_RTS)
info->curregs[5] |= RTS;
if (arg & TIOCM_DTR)
info->curregs[5] |= DTR;
break;
case TIOCMBIC:
if (arg & TIOCM_RTS)
info->curregs[5] &= ~RTS;
if (arg & TIOCM_DTR)
info->curregs[5] &= ~DTR;
break;
case TIOCMSET:
info->curregs[5] = ((info->curregs[5] & ~(RTS | DTR))
| ((arg & TIOCM_RTS) ? RTS : 0)
| ((arg & TIOCM_DTR) ? DTR : 0));
break;
default:
return -EINVAL;
}
cli();
write_zsreg(info->zs_channel, 5, info->curregs[5]);
sti();
return 0;
}
/*
* This routine sends a break character out the serial port.
*/
static void send_break( struct sgi_serial * info, int duration)
{
if (!info->port)
return;
current->state = TASK_INTERRUPTIBLE;
cli();
write_zsreg(info->zs_channel, 5, (info->curregs[5] | SND_BRK));
schedule_timeout(duration);
write_zsreg(info->zs_channel, 5, info->curregs[5]);
sti();
}
static int rs_ioctl(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg)
{
struct sgi_serial * info = (struct sgi_serial *) tty->driver_data;
int retval;
if (serial_paranoia_check(info, tty->name, "zs_ioctl"))
return -ENODEV;
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
(cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
if (tty->flags & (1 << TTY_IO_ERROR))
return -EIO;
}
switch (cmd) {
case TCSBRK: /* SVID version: non-zero arg --> no break */
retval = tty_check_change(tty);
if (retval)
return retval;
tty_wait_until_sent(tty, 0);
if (!arg)
send_break(info, HZ/4); /* 1/4 second */
return 0;
case TCSBRKP: /* support for POSIX tcsendbreak() */
retval = tty_check_change(tty);
if (retval)
return retval;
tty_wait_until_sent(tty, 0);
send_break(info, arg ? arg*(HZ/10) : HZ/4);
return 0;
case TIOCGSOFTCAR:
if (put_user(C_CLOCAL(tty) ? 1 : 0,
(unsigned long *) arg))
return -EFAULT;
return 0;
case TIOCSSOFTCAR:
if (get_user(arg, (unsigned long *) arg))
return -EFAULT;
tty->termios->c_cflag =
((tty->termios->c_cflag & ~CLOCAL) |
(arg ? CLOCAL : 0));
return 0;
case TIOCMGET:
return get_modem_info(info, (unsigned int *) arg);
case TIOCMBIS:
case TIOCMBIC:
case TIOCMSET:
return set_modem_info(info, cmd, (unsigned int *) arg);
case TIOCGSERIAL:
return get_serial_info(info,
(struct serial_struct *) arg);
case TIOCSSERIAL:
return set_serial_info(info,
(struct serial_struct *) arg);
case TIOCSERGETLSR: /* Get line status register */
return get_lsr_info(info, (unsigned int *) arg);
case TIOCSERGSTRUCT:
if (copy_to_user((struct sgi_serial *) arg,
info, sizeof(struct sgi_serial)))
return -EFAULT;
return 0;
default:
return -ENOIOCTLCMD;
}
return 0;
}
static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
{
struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
if (tty->termios->c_cflag == old_termios->c_cflag)
return;
change_speed(info);
if ((old_termios->c_cflag & CRTSCTS) &&
!(tty->termios->c_cflag & CRTSCTS)) {
tty->hw_stopped = 0;
rs_start(tty);
}
}
/*
* ------------------------------------------------------------
* rs_close()
*
* This routine is called when the serial port gets closed. First, we
* wait for the last remaining data to be sent. Then, we unlink its
* ZILOG structure from the interrupt chain if necessary, and we free
* that IRQ if nothing is left in the chain.
* ------------------------------------------------------------
*/
static void rs_close(struct tty_struct *tty, struct file * filp)
{
struct sgi_serial * info = (struct sgi_serial *)tty->driver_data;
unsigned long flags;
if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
return;
save_flags(flags); cli();
if (tty_hung_up_p(filp)) {
restore_flags(flags);
return;
}
#ifdef SERIAL_DEBUG_OPEN
printk("rs_close ttys%d, count = %d\n", info->line, info->count);
#endif
if ((tty->count == 1) && (info->count != 1)) {
/*
* Uh, oh. tty->count is 1, which means that the tty
* structure will be freed. Info->count should always
* be one in these conditions. If it's greater than
* one, we've got real problems, since it means the
* serial port won't be shutdown.
*/
printk("rs_close: bad serial port count; tty->count is 1, "
"info->count is %d\n", info->count);
info->count = 1;
}
if (--info->count < 0) {
printk("rs_close: bad serial port count for ttys%d: %d\n",
info->line, info->count);
info->count = 0;
}
if (info->count) {
restore_flags(flags);
return;
}
info->flags |= ZILOG_CLOSING;
/*
* Now we wait for the transmit buffer to clear; and we notify
* the line discipline to only process XON/XOFF characters.
*/
tty->closing = 1;
if (info->closing_wait != ZILOG_CLOSING_WAIT_NONE)
tty_wait_until_sent(tty, info->closing_wait);
/*
* At this point we stop accepting input. To do this, we
* disable the receive line status interrupts, and tell the
* interrupt driver to stop checking the data ready bit in the
* line status register.
*/
/** if (!info->iscons) ... **/
info->curregs[3] &= ~RxENABLE;
info->pendregs[3] = info->curregs[3];
write_zsreg(info->zs_channel, 3, info->curregs[3]);
info->curregs[1] &= ~(0x18);
info->pendregs[1] = info->curregs[1];
write_zsreg(info->zs_channel, 1, info->curregs[1]);
ZS_CLEARFIFO(info->zs_channel);
shutdown(info);
if (tty->driver->flush_buffer)
tty->driver->flush_buffer(tty);
if (tty->ldisc.flush_buffer)
tty->ldisc.flush_buffer(tty);
tty->closing = 0;
info->event = 0;
info->tty = 0;
if (tty->ldisc.num != ldiscs[N_TTY].num) {
if (tty->ldisc.close)
(tty->ldisc.close)(tty);
tty->ldisc = ldiscs[N_TTY];
tty->termios->c_line = N_TTY;
if (tty->ldisc.open)
(tty->ldisc.open)(tty);
}
if (info->blocked_open) {
if (info->close_delay) {
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(info->close_delay);
}
wake_up_interruptible(&info->open_wait);
}
info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CLOSING);
wake_up_interruptible(&info->close_wait);
restore_flags(flags);
}
/*
* rs_hangup() --- called by tty_hangup() when a hangup is signaled.
*/
void rs_hangup(struct tty_struct *tty)
{
struct sgi_serial * info = (struct sgi_serial *)tty->driver_data;
if (serial_paranoia_check(info, tty->name, "rs_hangup"))
return;
rs_flush_buffer(tty);
shutdown(info);
info->event = 0;
info->count = 0;
info->flags &= ~ZILOG_NORMAL_ACTIVE;
info->tty = 0;
wake_up_interruptible(&info->open_wait);
}
/*
* ------------------------------------------------------------
* rs_open() and friends
* ------------------------------------------------------------
*/
static int block_til_ready(struct tty_struct *tty, struct file * filp,
struct sgi_serial *info)
{
DECLARE_WAITQUEUE(wait, current);
int retval;
int do_clocal = 0;
/*
* If the device is in the middle of being closed, then block
* until it's done, and then try again.
*/
if (info->flags & ZILOG_CLOSING) {
interruptible_sleep_on(&info->close_wait);
#ifdef SERIAL_DO_RESTART
if (info->flags & ZILOG_HUP_NOTIFY)
return -EAGAIN;
else
return -ERESTARTSYS;
#else
return -EAGAIN;
#endif
}
/*
* If non-blocking mode is set, or the port is not enabled,
* then make the check up front and then exit.
*/
if ((filp->f_flags & O_NONBLOCK) ||
(tty->flags & (1 << TTY_IO_ERROR))) {
info->flags |= ZILOG_NORMAL_ACTIVE;
return 0;
}
if (tty->termios->c_cflag & CLOCAL)
do_clocal = 1;
/*
* Block waiting for the carrier detect and the line to become
* free (i.e., not in use by the callout). While we are in
* this loop, info->count is dropped by one, so that
* rs_close() knows when to free things. We restore it upon
* exit, either normal or abnormal.
*/
retval = 0;
add_wait_queue(&info->open_wait, &wait);
#ifdef SERIAL_DEBUG_OPEN
printk("block_til_ready before block: ttys%d, count = %d\n",
info->line, info->count);
#endif
info->count--;
info->blocked_open++;
while (1) {
cli();
zs_rtsdtr(info, 1);
sti();
set_current_state(TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) ||
!(info->flags & ZILOG_INITIALIZED)) {
#ifdef SERIAL_DO_RESTART
if (info->flags & ZILOG_HUP_NOTIFY)
retval = -EAGAIN;
else
retval = -ERESTARTSYS;
#else
retval = -EAGAIN;
#endif
break;
}
if (!(info->flags & ZILOG_CLOSING) && do_clocal)
break;
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
#ifdef SERIAL_DEBUG_OPEN
printk("block_til_ready blocking: ttys%d, count = %d\n",
info->line, info->count);
#endif
schedule();
}
current->state = TASK_RUNNING;
remove_wait_queue(&info->open_wait, &wait);
if (!tty_hung_up_p(filp))
info->count++;
info->blocked_open--;
#ifdef SERIAL_DEBUG_OPEN
printk("block_til_ready after blocking: ttys%d, count = %d\n",
info->line, info->count);
#endif
if (retval)
return retval;
info->flags |= ZILOG_NORMAL_ACTIVE;
return 0;
}
/*
* This routine is called whenever a serial port is opened. It
* enables interrupts for a serial port, linking in its ZILOG structure into
* the IRQ chain. It also performs the serial-specific
* initialization for the tty structure.
*/
int rs_open(struct tty_struct *tty, struct file * filp)
{
struct sgi_serial *info;
int retval, line;
line = tty->index;
/* The zilog lines for the mouse/keyboard must be
* opened using their respective drivers.
*/
if ((line < 0) || (line >= NUM_CHANNELS))
return -ENODEV;
info = zs_soft + line;
/* Is the kgdb running over this line? */
if (info->kgdb_channel)
return -ENODEV;
if (serial_paranoia_check(info, tty->name, "rs_open"))
return -ENODEV;
#ifdef SERIAL_DEBUG_OPEN
printk("rs_open %s, count = %d\n", tty->name, info->count);
#endif
info->count++;
tty->driver_data = info;
info->tty = tty;
/*
* Start up serial port
*/
retval = startup(info);
if (retval)
return retval;
retval = block_til_ready(tty, filp, info);
if (retval) {
#ifdef SERIAL_DEBUG_OPEN
printk("rs_open returning after block_til_ready with %d\n",
retval);
#endif
return retval;
}
/* If this is the serial console change the speed to
* the right value
*/
if (info->is_cons) {
info->tty->termios->c_cflag = sgisercon->cflag;
change_speed(info);
}
#ifdef SERIAL_DEBUG_OPEN
printk("rs_open %s successful...\n", tty->name);
#endif
return 0;
}
/* Finally, routines used to initialize the serial driver. */
static void show_serial_version(void)
{
printk("SGI Zilog8530 serial driver version 1.00\n");
}
/* Return layout for the requested zs chip number. */
static inline struct sgi_zslayout *get_zs(int chip)
{
extern struct hpc3_miscregs *hpc3mregs;
if (chip > 0)
panic("Wheee, bogus zs chip number requested.");
return (struct sgi_zslayout *) (&hpc3mregs->ser1cmd);
}
static inline void
rs_cons_check(struct sgi_serial *ss, int channel)
{
int i, o, io;
static int msg_printed = 0;
i = o = io = 0;
/* Is this one of the serial console lines? */
if((zs_cons_chanout != channel) &&
(zs_cons_chanin != channel))
return;
zs_conschan = ss->zs_channel;
zs_consinfo = ss;
/* If this is console input, we handle the break received
* status interrupt on this line to mean prom_halt().
*/
if(zs_cons_chanin == channel) {
ss->break_abort = 1;
i = 1;
}
if(o && i)
io = 1;
/* Set flag variable for this port so that it cannot be
* opened for other uses by accident.
*/
ss->is_cons = 1;
if(io) {
if (!msg_printed) {
printk("zs%d: console I/O\n", ((channel>>1)&1));
msg_printed = 1;
}
} else {
printk("zs%d: console %s\n", ((channel>>1)&1),
(i==1 ? "input" : (o==1 ? "output" : "WEIRD")));
}
}
static struct tty_operations serial_ops = {
.open = rs_open,
.close = rs_close,
.write = rs_write,
.flush_chars = rs_flush_chars,
.write_room = rs_write_room,
.chars_in_buffer = rs_chars_in_buffer,
.flush_buffer = rs_flush_buffer,
.ioctl = rs_ioctl,
.throttle = rs_throttle,
.unthrottle = rs_unthrottle,
.set_termios = rs_set_termios,
.stop = rs_stop,
.start = rs_start,
.hangup = rs_hangup,
};
/* rs_init inits the driver */
int rs_init(void)
{
int chip, channel, i, flags;
struct sgi_serial *info;
serial_driver = tty_alloc_serial(NUM_CHANNELS);
if (!serial_driver)
return -ENOMEM;
/* Setup base handler, and timer table. */
init_bh(SERIAL_BH, do_serial_bh);
show_serial_version();
/* Initialize the tty_driver structure */
/* SGI: Not all of this is exactly right for us. */
serial_driver->owner = THIS_MODULE;
serial_driver->name = "ttyS";
serial_driver->major = TTY_MAJOR;
serial_driver->minor_start = 64;
serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
serial_driver->subtype = SERIAL_TYPE_NORMAL;
serial_driver->init_termios = tty_std_termios;
serial_driver->init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
serial_driver->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(serial_driver, &serial_ops);
if (tty_register_driver(serial_driver))
panic("Couldn't register serial driver\n");
save_flags(flags); cli();
/* Set up our interrupt linked list */
zs_chain = &zs_soft[0];
zs_soft[0].zs_next = &zs_soft[1];
zs_soft[1].zs_next = 0;
for(chip = 0; chip < NUM_SERIAL; chip++) {
/* If we are doing kgdb over one of the channels on
* chip zero, kgdb_channel will be set to 1 by the
* rs_kgdb_hook() routine below.
*/
if(!zs_chips[chip]) {
zs_chips[chip] = get_zs(chip);
/* Two channels per chip */
zs_channels[(chip*2)] = &zs_chips[chip]->channelB;
zs_channels[(chip*2)+1] = &zs_chips[chip]->channelA;
zs_soft[(chip*2)].kgdb_channel = 0;
zs_soft[(chip*2)+1].kgdb_channel = 0;
}
/* First, set up channel A on this chip. */
channel = chip * 2;
zs_soft[channel].zs_channel = zs_channels[channel];
zs_soft[channel].change_needed = 0;
zs_soft[channel].clk_divisor = 16;
zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
zs_soft[channel].cons_mouse = 0;
/* If not keyboard/mouse and is console serial
* line, then enable receiver interrupts.
*/
if(zs_soft[channel].is_cons) {
write_zsreg(zs_soft[channel].zs_channel, R1,
(EXT_INT_ENAB | INT_ALL_Rx));
write_zsreg(zs_soft[channel].zs_channel, R9, (NV | MIE));
write_zsreg(zs_soft[channel].zs_channel, R10, (NRZ));
write_zsreg(zs_soft[channel].zs_channel, R3, (Rx8|RxENABLE));
write_zsreg(zs_soft[channel].zs_channel, R5, (Tx8 | TxENAB));
}
/* If this is the kgdb line, enable interrupts because we
* now want to receive the 'control-c' character from the
* client attached to us asynchronously.
*/
if(zs_soft[channel].kgdb_channel)
kgdb_chaninit(&zs_soft[channel], 1,
zs_soft[channel].zs_baud);
/* Now, channel B */
channel++;
zs_soft[channel].zs_channel = zs_channels[channel];
zs_soft[channel].change_needed = 0;
zs_soft[channel].clk_divisor = 16;
zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
zs_soft[channel].cons_keyb = 0;
/* If console serial line, then enable receiver interrupts. */
if(zs_soft[channel].is_cons) {
write_zsreg(zs_soft[channel].zs_channel, R1,
(EXT_INT_ENAB | INT_ALL_Rx));
write_zsreg(zs_soft[channel].zs_channel, R9,
(NV | MIE));
write_zsreg(zs_soft[channel].zs_channel, R10,
(NRZ));
write_zsreg(zs_soft[channel].zs_channel, R3,
(Rx8|RxENABLE));
write_zsreg(zs_soft[channel].zs_channel, R5,
(Tx8 | TxENAB | RTS | DTR));
}
}
for(info=zs_chain, i=0; info; info = info->zs_next, i++)
{
info->magic = SERIAL_MAGIC;
info->port = (int) info->zs_channel;
info->line = i;
info->tty = 0;
info->irq = zilog_irq;
info->custom_divisor = 16;
info->close_delay = 50;
info->closing_wait = 3000;
info->x_char = 0;
info->event = 0;
info->count = 0;
info->blocked_open = 0;
info->tqueue.routine = do_softint;
info->tqueue.data = info;
info->tqueue_hangup.routine = do_serial_hangup;
info->tqueue_hangup.data = info;
init_waitqueue_head(&info->open_wait);
init_waitqueue_head(&info->close_wait);
printk("tty%02d at 0x%04x (irq = %d)", info->line,
info->port, info->irq);
printk(" is a Zilog8530\n");
}
if (request_irq(zilog_irq, rs_interrupt, (SA_INTERRUPT),
"Zilog8530", zs_chain))
panic("Unable to attach zs intr\n");
restore_flags(flags);
return 0;
}
/*
* register_serial and unregister_serial allows for serial ports to be
* configured at run-time, to support PCMCIA modems.
*/
/* SGI: Unused at this time, just here to make things link. */
int register_serial(struct serial_struct *req)
{
return -1;
}
void unregister_serial(int line)
{
return;
}
/* Hooks for running a serial console. con_init() calls this if the
* console is being run over one of the ttya/ttyb serial ports.
* 'chip' should be zero, as chip 1 drives the mouse/keyboard.
* 'channel' is decoded as 0=TTYA 1=TTYB, note that the channels
* are addressed backwards, channel B is first, then channel A.
*/
void
rs_cons_hook(int chip, int out, int line)
{
int channel;
if(chip)
panic("rs_cons_hook called with chip not zero");
if(line != 0 && line != 1)
panic("rs_cons_hook called with line not ttya or ttyb");
channel = line;
if(!zs_chips[chip]) {
zs_chips[chip] = get_zs(chip);
/* Two channels per chip */
zs_channels[(chip*2)] = &zs_chips[chip]->channelB;
zs_channels[(chip*2)+1] = &zs_chips[chip]->channelA;
}
zs_soft[channel].zs_channel = zs_channels[channel];
zs_soft[channel].change_needed = 0;
zs_soft[channel].clk_divisor = 16;
zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
if(out)
zs_cons_chanout = ((chip * 2) + channel);
else
zs_cons_chanin = ((chip * 2) + channel);
rs_cons_check(&zs_soft[channel], channel);
}
/* This is called at boot time to prime the kgdb serial debugging
* serial line. The 'tty_num' argument is 0 for /dev/ttyd2 and 1 for
* /dev/ttyd1 (yes they are backwards on purpose) which is determined
* in setup_arch() from the boot command line flags.
*/
void
rs_kgdb_hook(int tty_num)
{
int chip = 0;
if(!zs_chips[chip]) {
zs_chips[chip] = get_zs(chip);
/* Two channels per chip */
zs_channels[(chip*2)] = &zs_chips[chip]->channelA;
zs_channels[(chip*2)+1] = &zs_chips[chip]->channelB;
}
zs_soft[tty_num].zs_channel = zs_channels[tty_num];
zs_kgdbchan = zs_soft[tty_num].zs_channel;
zs_soft[tty_num].change_needed = 0;
zs_soft[tty_num].clk_divisor = 16;
zs_soft[tty_num].zs_baud = get_zsbaud(&zs_soft[tty_num]);
zs_soft[tty_num].kgdb_channel = 1; /* This runs kgdb */
zs_soft[tty_num ^ 1].kgdb_channel = 0; /* This does not */
/* Turn on transmitter/receiver at 8-bits/char */
kgdb_chaninit(&zs_soft[tty_num], 0, 9600);
ZS_CLEARERR(zs_kgdbchan);
udelay(5);
ZS_CLEARFIFO(zs_kgdbchan);
}
static void zs_console_write(struct console *co, const char *str,
unsigned int count)
{
while(count--) {
if(*str == '\n')
zs_cons_put_char('\r');
zs_cons_put_char(*str++);
}
/* Comment this if you want to have a strict interrupt-driven output */
rs_fair_output();
}
static struct tty_driver *zs_console_device(struct console *con, int *index)
{
*index = con->index;
return serial_driver;
}
static int __init zs_console_setup(struct console *con, char *options)
{
struct sgi_serial *info;
int baud;
int bits = 8;
int parity = 'n';
int cflag = CREAD | HUPCL | CLOCAL;
char *s, *dbaud;
int i, brg;
if (options) {
baud = simple_strtoul(options, NULL, 10);
s = options;
while(*s >= '0' && *s <= '9')
s++;
if (*s) parity = *s++;
if (*s) bits = *s - '0';
}
else {
/* If the user doesn't set console=... try to read the
* PROM variable - if this fails use 9600 baud and
* inform the user about the problem
*/
dbaud = ArcGetEnvironmentVariable("dbaud");
if(dbaud) baud = simple_strtoul(dbaud, NULL, 10);
else {
/* Use prom_printf() to make sure that the user
* is getting anything ...
*/
prom_printf("No dbaud set in PROM ?!? Using 9600.\n");
baud = 9600;
}
}
/*
* Now construct a cflag setting.
*/
switch(baud) {
case 1200:
cflag |= B1200;
break;
case 2400:
cflag |= B2400;
break;
case 4800:
cflag |= B4800;
break;
case 19200:
cflag |= B19200;
break;
case 38400:
cflag |= B38400;
break;
case 57600:
cflag |= B57600;
break;
case 115200:
cflag |= B115200;
break;
case 9600:
default:
cflag |= B9600;
break;
}
switch(bits) {
case 7:
cflag |= CS7;
break;
default:
case 8:
cflag |= CS8;
break;
}
switch(parity) {
case 'o': case 'O':
cflag |= PARODD;
break;
case 'e': case 'E':
cflag |= PARENB;
break;
}
con->cflag = cflag;
rs_cons_hook(0, 0, con->index);
info = zs_soft + con->index;
info->is_cons = 1;
printk("Console: ttyS%d (Zilog8530), %d baud\n",
info->line, baud);
i = con->cflag & CBAUD;
if (con->cflag & CBAUDEX) {
i &= ~CBAUDEX;
con->cflag &= ~CBAUDEX;
}
info->zs_baud = baud;
switch (con->cflag & CSIZE) {
case CS5:
zscons_regs[3] = Rx5 | RxENABLE;
zscons_regs[5] = Tx5 | TxENAB;
break;
case CS6:
zscons_regs[3] = Rx6 | RxENABLE;
zscons_regs[5] = Tx6 | TxENAB;
break;
case CS7:
zscons_regs[3] = Rx7 | RxENABLE;
zscons_regs[5] = Tx7 | TxENAB;
break;
default:
case CS8:
zscons_regs[3] = Rx8 | RxENABLE;
zscons_regs[5] = Tx8 | TxENAB;
break;
}
zscons_regs[5] |= DTR;
if (con->cflag & PARENB)
zscons_regs[4] |= PAR_ENA;
if (!(con->cflag & PARODD))
zscons_regs[4] |= PAR_EVEN;
if (con->cflag & CSTOPB)
zscons_regs[4] |= SB2;
else
zscons_regs[4] |= SB1;
sgisercon = con;
brg = BPS_TO_BRG(baud, ZS_CLOCK / info->clk_divisor);
zscons_regs[12] = brg & 0xff;
zscons_regs[13] = (brg >> 8) & 0xff;
memcpy(info->curregs, zscons_regs, sizeof(zscons_regs));
memcpy(info->pendregs, zscons_regs, sizeof(zscons_regs));
load_zsregs(info->zs_channel, zscons_regs);
ZS_CLEARERR(info->zs_channel);
ZS_CLEARFIFO(info->zs_channel);
return 0;
}
static struct console sgi_console_driver = {
.name = "ttyS",
.write = zs_console_write,
.device = zs_console_device,
.setup = zs_console_setup,
.flags = CON_PRINTBUFFER,
.index = -1,
};
/*
* Register console.
*/
static void __init sgi_serial_console_init(void)
{
register_console(&sgi_console_driver);
}
console_initcall(sgi_serial_console_init);
__initcall(rs_init);
/* sgiserial.h: Definitions for the SGI Zilog85C30 serial driver.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
*/
#ifndef _SGI_SERIAL_H
#define _SGI_SERIAL_H
/* Just one channel */
struct sgi_zschannel {
#ifdef __MIPSEB__
volatile unsigned char unused0[3];
volatile unsigned char control;
volatile unsigned char unused1[3];
volatile unsigned char data;
#else /* __MIPSEL__ */
volatile unsigned char control;
volatile unsigned char unused0[3];
volatile unsigned char data;
volatile unsigned char unused1[3];
#endif
};
/* The address space layout for each zs chip. Yes they are
* backwards.
*/
struct sgi_zslayout {
struct sgi_zschannel channelB;
struct sgi_zschannel channelA;
};
#define NUM_ZSREGS 16
struct serial_struct {
int type;
int line;
int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char reserved_char[2];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
int reserved[4];
};
/*
* For the close wait times, 0 means wait forever for serial port to
* flush its output. 65535 means don't wait at all.
*/
#define ZILOG_CLOSING_WAIT_INF 0
#define ZILOG_CLOSING_WAIT_NONE 65535
/*
* Definitions for ZILOG_struct (and serial_struct) flags field
*/
#define ZILOG_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
on the callout port */
#define ZILOG_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
#define ZILOG_SAK 0x0004 /* Secure Attention Key (Orange book) */
#define ZILOG_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
#define ZILOG_SPD_MASK 0x0030
#define ZILOG_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
#define ZILOG_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
#define ZILOG_SPD_CUST 0x0030 /* Use user-specified divisor */
#define ZILOG_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
#define ZILOG_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
#define ZILOG_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
#define ZILOG_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
#define ZILOG_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
#define ZILOG_FLAGS 0x0FFF /* Possible legal ZILOG flags */
#define ZILOG_USR_MASK 0x0430 /* Legal flags that non-privileged
* users can set or reset */
/* Internal flags used only by kernel/chr_drv/serial.c */
#define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */
#define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
#define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
#define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
#define ZILOG_CLOSING 0x08000000 /* Serial port is closing */
#define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */
#define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */
/* Software state per channel */
#ifdef __KERNEL__
/*
* This is our internal structure for each serial port's state.
*
* Many fields are paralleled by the structure used by the serial_struct
* structure.
*
* For definitions of the flags field, see tty.h
*/
struct sgi_serial {
struct sgi_serial *zs_next; /* For IRQ servicing chain */
struct sgi_zschannel *zs_channel; /* Channel registers */
unsigned char read_reg_zero;
char soft_carrier; /* Use soft carrier on this channel */
char cons_keyb; /* Channel runs the keyboard */
char cons_mouse; /* Channel runs the mouse */
char break_abort; /* Is serial console in, so process brk/abrt */
char kgdb_channel; /* Kgdb is running on this channel */
char is_cons; /* Is this our console. */
/* We need to know the current clock divisor
* to read the bps rate the chip has currently
* loaded.
*/
unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */
int zs_baud;
/* Current write register values */
unsigned char curregs[NUM_ZSREGS];
/* Values we need to set next opportunity */
unsigned char pendregs[NUM_ZSREGS];
char change_needed;
int magic;
int baud_base;
int port;
int irq;
int flags; /* defined in tty.h */
int type; /* UART type */
struct tty_struct *tty;
int read_status_mask;
int ignore_status_mask;
int timeout;
int xmit_fifo_size;
int custom_divisor;
int x_char; /* xon/xoff character */
int close_delay;
unsigned short closing_wait;
unsigned short closing_wait2;
unsigned long event;
unsigned long last_active;
int line;
int count; /* # of fd on device */
int blocked_open; /* # of blocked opens */
unsigned char *xmit_buf;
int xmit_head;
int xmit_tail;
int xmit_cnt;
struct tq_struct tqueue;
struct tq_struct tqueue_hangup;
wait_queue_head_t open_wait;
wait_queue_head_t close_wait;
};
#define SERIAL_MAGIC 0x5301
/*
* The size of the serial xmit buffer is 1 page, or 4096 bytes
*/
#define SERIAL_XMIT_SIZE 4096
/*
* Events are used to schedule things to happen at timer-interrupt
* time, instead of at rs interrupt time.
*/
#define RS_EVENT_WRITE_WAKEUP 0
#endif /* __KERNEL__ */
/* Conversion routines to/from brg time constants from/to bits
* per second.
*/
#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
/* The Zilog register set */
#define FLAG 0x7e
/* Write Register 0 */
#define R0 0 /* Register selects */
#define R1 1
#define R2 2
#define R3 3
#define R4 4
#define R5 5
#define R6 6
#define R7 7
#define R8 8
#define R9 9
#define R10 10
#define R11 11
#define R12 12
#define R13 13
#define R14 14
#define R15 15
#define NULLCODE 0 /* Null Code */
#define POINT_HIGH 0x8 /* Select upper half of registers */
#define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
#define SEND_ABORT 0x18 /* HDLC Abort */
#define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
#define RES_Tx_P 0x28 /* Reset TxINT Pending */
#define ERR_RES 0x30 /* Error Reset */
#define RES_H_IUS 0x38 /* Reset highest IUS */
#define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
#define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
#define RES_EOM_L 0xC0 /* Reset EOM latch */
/* Write Register 1 */
#define EXT_INT_ENAB 0x1 /* Ext Int Enable */
#define TxINT_ENAB 0x2 /* Tx Int Enable */
#define PAR_SPEC 0x4 /* Parity is special condition */
#define RxINT_DISAB 0 /* Rx Int Disable */
#define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
#define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */
#define INT_ERR_Rx 0x18 /* Int on error only */
#define WT_RDY_RT 0x20 /* Wait/Ready on R/T */
#define WT_FN_RDYFN 0x40 /* Wait/FN/Ready FN */
#define WT_RDY_ENAB 0x80 /* Wait/Ready Enable */
/* Write Register #2 (Interrupt Vector) */
/* Write Register 3 */
#define RxENABLE 0x1 /* Rx Enable */
#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
#define ADD_SM 0x4 /* Address Search Mode (SDLC) */
#define RxCRC_ENAB 0x8 /* Rx CRC Enable */
#define ENT_HM 0x10 /* Enter Hunt Mode */
#define AUTO_ENAB 0x20 /* Auto Enables */
#define Rx5 0x0 /* Rx 5 Bits/Character */
#define Rx7 0x40 /* Rx 7 Bits/Character */
#define Rx6 0x80 /* Rx 6 Bits/Character */
#define Rx8 0xc0 /* Rx 8 Bits/Character */
/* Write Register 4 */
#define PAR_ENA 0x1 /* Parity Enable */
#define PAR_EVEN 0x2 /* Parity Even/Odd* */
#define SYNC_ENAB 0 /* Sync Modes Enable */
#define SB1 0x4 /* 1 stop bit/char */
#define SB15 0x8 /* 1.5 stop bits/char */
#define SB2 0xc /* 2 stop bits/char */
#define MONSYNC 0 /* 8 Bit Sync character */
#define BISYNC 0x10 /* 16 bit sync character */
#define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
#define EXTSYNC 0x30 /* External Sync Mode */
#define X1CLK 0x0 /* x1 clock mode */
#define X16CLK 0x40 /* x16 clock mode */
#define X32CLK 0x80 /* x32 clock mode */
#define X64CLK 0xC0 /* x64 clock mode */
/* Write Register 5 */
#define TxCRC_ENAB 0x1 /* Tx CRC Enable */
#define RTS 0x2 /* RTS */
#define SDLC_CRC 0x4 /* SDLC/CRC-16 */
#define TxENAB 0x8 /* Tx Enable */
#define SND_BRK 0x10 /* Send Break */
#define Tx5 0x0 /* Tx 5 bits (or less)/character */
#define Tx7 0x20 /* Tx 7 bits/character */
#define Tx6 0x40 /* Tx 6 bits/character */
#define Tx8 0x60 /* Tx 8 bits/character */
#define DTR 0x80 /* DTR */
/* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
/* Write Register 8 (transmit buffer) */
/* Write Register 9 (Master interrupt control) */
#define VIS 1 /* Vector Includes Status */
#define NV 2 /* No Vector */
#define DLC 4 /* Disable Lower Chain */
#define MIE 8 /* Master Interrupt Enable */
#define STATHI 0x10 /* Status high */
#define NORESET 0 /* No reset on write to R9 */
#define CHRB 0x40 /* Reset channel B */
#define CHRA 0x80 /* Reset channel A */
#define FHWRES 0xc0 /* Force hardware reset */
/* Write Register 10 (misc control bits) */
#define BIT6 1 /* 6 bit/8bit sync */
#define LOOPMODE 2 /* SDLC Loop mode */
#define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
#define MARKIDLE 8 /* Mark/flag on idle */
#define GAOP 0x10 /* Go active on poll */
#define NRZ 0 /* NRZ mode */
#define NRZI 0x20 /* NRZI mode */
#define FM1 0x40 /* FM1 (transition = 1) */
#define FM0 0x60 /* FM0 (transition = 0) */
#define CRCPS 0x80 /* CRC Preset I/O */
/* Write Register 11 (Clock Mode control) */
#define TRxCXT 0 /* TRxC = Xtal output */
#define TRxCTC 1 /* TRxC = Transmit clock */
#define TRxCBR 2 /* TRxC = BR Generator Output */
#define TRxCDP 3 /* TRxC = DPLL output */
#define TRxCOI 4 /* TRxC O/I */
#define TCRTxCP 0 /* Transmit clock = RTxC pin */
#define TCTRxCP 8 /* Transmit clock = TRxC pin */
#define TCBR 0x10 /* Transmit clock = BR Generator output */
#define TCDPLL 0x18 /* Transmit clock = DPLL output */
#define RCRTxCP 0 /* Receive clock = RTxC pin */
#define RCTRxCP 0x20 /* Receive clock = TRxC pin */
#define RCBR 0x40 /* Receive clock = BR Generator output */
#define RCDPLL 0x60 /* Receive clock = DPLL output */
#define RTxCX 0x80 /* RTxC Xtal/No Xtal */
/* Write Register 12 (lower byte of baud rate generator time constant) */
/* Write Register 13 (upper byte of baud rate generator time constant) */
/* Write Register 14 (Misc control bits) */
#define BRENABL 1 /* Baud rate generator enable */
#define BRSRC 2 /* Baud rate generator source */
#define DTRREQ 4 /* DTR/Request function */
#define AUTOECHO 8 /* Auto Echo */
#define LOOPBAK 0x10 /* Local loopback */
#define SEARCH 0x20 /* Enter search mode */
#define RMC 0x40 /* Reset missing clock */
#define DISDPLL 0x60 /* Disable DPLL */
#define SSBR 0x80 /* Set DPLL source = BR generator */
#define SSRTxC 0xa0 /* Set DPLL source = RTxC */
#define SFMM 0xc0 /* Set FM mode */
#define SNRZI 0xe0 /* Set NRZI mode */
/* Write Register 15 (external/status interrupt control) */
#define ZCIE 2 /* Zero count IE */
#define DCDIE 8 /* DCD IE */
#define SYNCIE 0x10 /* Sync/hunt IE */
#define CTSIE 0x20 /* CTS IE */
#define TxUIE 0x40 /* Tx Underrun/EOM IE */
#define BRKIE 0x80 /* Break/Abort IE */
/* Read Register 0 */
#define Rx_CH_AV 0x1 /* Rx Character Available */
#define ZCOUNT 0x2 /* Zero count */
#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
#define DCD 0x8 /* DCD */
#define SYNC 0x10 /* Sync/hunt */
#define CTS 0x20 /* CTS */
#define TxEOM 0x40 /* Tx underrun */
#define BRK_ABRT 0x80 /* Break/Abort */
/* Read Register 1 */
#define ALL_SNT 0x1 /* All sent */
/* Residue Data for 8 Rx bits/char programmed */
#define RES3 0x8 /* 0/3 */
#define RES4 0x4 /* 0/4 */
#define RES5 0xc /* 0/5 */
#define RES6 0x2 /* 0/6 */
#define RES7 0xa /* 0/7 */
#define RES8 0x6 /* 0/8 */
#define RES18 0xe /* 1/8 */
#define RES28 0x0 /* 2/8 */
/* Special Rx Condition Interrupts */
#define PAR_ERR 0x10 /* Parity error */
#define Rx_OVR 0x20 /* Rx Overrun Error */
#define CRC_ERR 0x40 /* CRC/Framing Error */
#define END_FR 0x80 /* End of Frame (SDLC) */
/* Read Register 2 (channel b only) - Interrupt vector */
/* Read Register 3 (interrupt pending register) ch a only */
#define CHBEXT 0x1 /* Channel B Ext/Stat IP */
#define CHBTxIP 0x2 /* Channel B Tx IP */
#define CHBRxIP 0x4 /* Channel B Rx IP */
#define CHAEXT 0x8 /* Channel A Ext/Stat IP */
#define CHATxIP 0x10 /* Channel A Tx IP */
#define CHARxIP 0x20 /* Channel A Rx IP */
/* Read Register 8 (receive data register) */
/* Read Register 10 (misc status bits) */
#define ONLOOP 2 /* On loop */
#define LOOPSEND 0x10 /* Loop sending */
#define CLK2MIS 0x40 /* Two clocks missing */
#define CLK1MIS 0x80 /* One clock missing */
/* Read Register 12 (lower byte of baud rate generator constant) */
/* Read Register 13 (upper byte of baud rate generator constant) */
/* Read Register 15 (value of WR 15) */
/* Misc inlines */
extern inline void ZS_CLEARERR(struct sgi_zschannel *channel)
{
volatile unsigned char junk;
udelay(2);
channel->control = ERR_RES;
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
}
extern inline void ZS_CLEARFIFO(struct sgi_zschannel *channel)
{
volatile unsigned char junk;
udelay(2);
junk = channel->data;
udelay(2);
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
junk = channel->data;
udelay(2);
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
junk = channel->data;
udelay(2);
if (ioc_icontrol)
junk = ioc_icontrol->istat0;
}
#if 0
#define ZS_CLEARERR(channel) (channel->control = ERR_RES)
#define ZS_CLEARFIFO(channel) do { volatile unsigned char garbage; \
garbage = channel->data; \
udelay(2); \
garbage = channel->data; \
udelay(2); \
garbage = channel->data; \
udelay(2); } while(0)
#endif
#endif /* !(_SPARC_SERIAL_H) */
/*
* shmiq.c: shared memory input queue driver
* written 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
*
* We implement /dev/shmiq, /dev/qcntlN here
* this is different from IRIX that has shmiq as a misc
* streams device and the and qcntl devices as a major device.
*
* minor number 0 implements /dev/shmiq,
* any other number implements /dev/qcntl${minor-1}
*
* /dev/shmiq is used by the X server for two things:
*
* 1. for I_LINK()ing trough ioctl the file handle of a
* STREAMS device.
*
* 2. To send STREAMS-commands to the devices with the
* QIO ioctl interface.
*
* I have not yet figured how to make multiple X servers share
* /dev/shmiq for having different servers running. So, for now
* I keep a kernel-global array of inodes that are pushed into
* /dev/shmiq.
*
* /dev/qcntlN is used by the X server for two things:
*
* 1. Issuing the QIOCATTACH for mapping the shared input
* queue into the address space of the X server (yeah, yeah,
* I did not invent this interface).
*
* 2. used by select. I bet it is used for checking for events on
* the queue.
*
* Now the problem is that there does not seem anything that
* establishes a connection between /dev/shmiq and the qcntlN file. I
* need an strace from an X server that runs on a machine with more
* than one keyboard. And this is a problem since the file handles
* are pushed in /dev/shmiq, while the events should be dispatched to
* the /dev/qcntlN device.
*
* Until then, I just allow for 1 qcntl device.
*
*/
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/file.h>
#include <linux/interrupt.h>
#include <linux/poll.h>
#include <linux/vmalloc.h>
#include <linux/wait.h>
#include <linux/major.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/shmiq.h>
#include <asm/gfx.h>
#include <asm/mman.h>
#include <asm/uaccess.h>
#include <asm/poll.h>
#include "graphics.h"
/* we are not really getting any more than a few files in the shmiq */
#define MAX_SHMIQ_DEVS 10
/*
* One per X server running, not going to get very big.
* Even if we have this we now assume just 1 /dev/qcntl can be
* active, I need to find how this works on multi-headed machines.
*/
#define MAX_SHMI_QUEUES 4
static struct {
int used;
struct file *filp;
struct shmiqsetcpos cpos;
} shmiq_pushed_devices [MAX_SHMIQ_DEVS];
/* /dev/qcntlN attached memory regions, location and size of the event queue */
static struct {
int opened;
void *shmiq_vaddr; /* mapping in kernel-land */
spinlock_t shmiq_lock:SPIN_LOCK_UNLOCKED;
/* protects vaddr and opened */
int tail; /* our copy of the shmiq->tail */
int events;
int mapped;
wait_queue_head_t proc_list;
struct fasync_struct *fasync;
} shmiqs [MAX_SHMI_QUEUES];
void
shmiq_push_event (struct shmqevent *e)
{
struct sharedMemoryInputQueue *s;
int device = 0; /* FIXME: here is the assumption /dev/shmiq == /dev/qcntl0 */
int tail_next;
if (!shmiqs [device].mapped)
return;
s = shmiqs [device].shmiq_vaddr;
s->flags = 0;
if (s->tail != shmiqs [device].tail){
s->flags |= SHMIQ_CORRUPTED;
return;
}
tail_next = (s->tail + 1) % (shmiqs [device].events);
if (tail_next == s->head){
s->flags |= SHMIQ_OVERFLOW;
return;
}
e->un.time = jiffies;
s->events [s->tail] = *e;
printk ("KERNEL: dev=%d which=%d type=%d flags=%d\n",
e->data.device, e->data.which, e->data.type, e->data.flags);
s->tail = tail_next;
shmiqs [device].tail = tail_next;
kill_fasync (&shmiqs [device].fasync, SIGIO, POLL_IN);
wake_up_interruptible (&shmiqs [device].proc_list);
}
static int
shmiq_manage_file (struct file *filp)
{
int i;
if (!filp->f_op || !filp->f_op->ioctl)
return -ENOSR;
for (i = 0; i < MAX_SHMIQ_DEVS; i++){
if (shmiq_pushed_devices [i].used)
continue;
if ((*filp->f_op->ioctl)(filp->f_dentry->d_inode, filp, SHMIQ_ON, i) != 0)
return -ENOSR;
shmiq_pushed_devices [i].used = 1;
shmiq_pushed_devices [i].filp = filp;
shmiq_pushed_devices [i].cpos.x = 0;
shmiq_pushed_devices [i].cpos.y = 0;
return i;
}
return -ENOSR;
}
static int
shmiq_forget_file (unsigned long fdes)
{
struct file *filp;
if (fdes > MAX_SHMIQ_DEVS)
return -EINVAL;
if (!shmiq_pushed_devices [fdes].used)
return -EINVAL;
filp = shmiq_pushed_devices [fdes].filp;
if (filp){
(*filp->f_op->ioctl)(filp->f_dentry->d_inode, filp, SHMIQ_OFF, 0);
shmiq_pushed_devices [fdes].filp = 0;
fput (filp);
}
shmiq_pushed_devices [fdes].used = 0;
return 0;
}
static int
shmiq_sioc (int device, int cmd, struct strioctl *s)
{
switch (cmd){
case QIOCGETINDX:
/*
* Ok, we just return the index they are providing us
*/
printk ("QIOCGETINDX: returning %d\n", *(int *)s->ic_dp);
return 0;
case QIOCIISTR: {
struct muxioctl *mux = (struct muxioctl *) s->ic_dp;
printk ("Double indirect ioctl: [%d, %x\n", mux->index, mux->realcmd);
return -EINVAL;
}
case QIOCSETCPOS: {
if (copy_from_user (&shmiq_pushed_devices [device].cpos, s->ic_dp,
sizeof (struct shmiqsetcpos)))
return -EFAULT;
return 0;
}
}
printk ("Unknown I_STR request for shmiq device: 0x%x\n", cmd);
return -EINVAL;
}
static int
shmiq_ioctl (struct inode *inode, struct file *f, unsigned int cmd, unsigned long arg)
{
struct file *file;
struct strioctl sioc;
int v;
switch (cmd){
/*
* They are giving us the file descriptor for one
* of their streams devices
*/
case I_LINK:
file = fget (arg);
if (!file)
goto bad_file;
v = shmiq_manage_file (file);
if (v<0)
fput(file);
return v;
/*
* Remove a device from our list of managed
* stream devices
*/
case I_UNLINK:
v = shmiq_forget_file (arg);
return v;
case I_STR:
v = get_sioc (&sioc, arg);
if (v)
return v;
/* FIXME: This forces device = 0 */
return shmiq_sioc (0, sioc.ic_cmd, &sioc);
}
return -EINVAL;
bad_file:
return -EBADF;
}
extern long sys_munmap(unsigned long addr, size_t len);
static int
qcntl_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg, int minor)
{
struct shmiqreq req;
struct vm_area_struct *vma;
int v;
switch (cmd) {
/*
* The address space is already mapped as a /dev/zero
* mapping. FIXME: check that /dev/zero is what the user
* had mapped before :-)
*/
case QIOCATTACH: {
unsigned long vaddr;
int s;
v = verify_area (VERIFY_READ, (void *) arg,
sizeof (struct shmiqreq));
if (v)
return v;
if (copy_from_user(&req, (void *) arg, sizeof (req)))
return -EFAULT;
/*
* Do not allow to attach to another region if it has
* already been attached
*/
if (shmiqs [minor].mapped) {
printk("SHMIQ:The thingie is already mapped\n");
return -EINVAL;
}
vaddr = (unsigned long) req.user_vaddr;
vma = find_vma (current->mm, vaddr);
if (!vma) {
printk ("SHMIQ: could not find %lx the vma\n",
vaddr);
return -EINVAL;
}
s = req.arg * sizeof (struct shmqevent) +
sizeof (struct sharedMemoryInputQueue);
v = sys_munmap (vaddr, s);
down_write(&current->mm->mmap_sem);
do_munmap(current->mm, vaddr, s);
do_mmap(filp, vaddr, s, PROT_READ | PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 0);
up_write(&current->mm->mmap_sem);
shmiqs[minor].events = req.arg;
shmiqs[minor].mapped = 1;
return 0;
}
}
return -EINVAL;
}
struct page *
shmiq_nopage (struct vm_area_struct *vma, unsigned long address,
int write_access)
{
/* Do not allow for mremap to expand us */
return NULL;
}
static struct vm_operations_struct qcntl_mmap = {
.nopage = shmiq_nopage, /* our magic no-page fault handler */
};
static int
shmiq_qcntl_mmap (struct file *file, struct vm_area_struct *vma)
{
int minor = MINOR (file->f_dentry->d_inode->i_rdev), error;
unsigned int size;
unsigned long mem, start;
/* mmap is only supported on the qcntl devices */
if (minor-- == 0)
return -EINVAL;
if (vma->vm_pgoff != 0)
return -EINVAL;
size = vma->vm_end - vma->vm_start;
start = vma->vm_start;
mem = vmalloc_uncached (size);
if (!mem)
return -EINVAL;
spin_lock( &shmiqs [minor].shmiq_lock );
hmiqs [minor].shmiq_vaddr = mem;
/* Prevent the swapper from considering these pages for swap and touching them */
vma->vm_flags |= (VM_SHM | VM_LOCKED | VM_IO);
vma->vm_ops = &qcntl_mmap;
/* Uncache the pages */
vma->vm_page_prot = PAGE_USERIO;
shmiqs [minor].tail = 0;
/* Init the shared memory input queue */
spin_unlock( &shmiqs [minor].shmiq_lock );
memset (shmiqs [minor].shmiq_vaddr, 0, size);
error = vmap_page_range (vma, vma->vm_start, size, mem);
return error;
}
static int
shmiq_qcntl_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
int minor = MINOR (inode->i_rdev);
if (minor-- == 0)
return shmiq_ioctl (inode, filp, cmd, arg);
return qcntl_ioctl (inode, filp, cmd, arg, minor);
}
static unsigned int
shmiq_qcntl_poll (struct file *filp, poll_table *wait)
{
struct sharedMemoryInputQueue *s;
int minor = MINOR (filp->f_dentry->d_inode->i_rdev);
if (minor-- == 0)
return 0;
if (!shmiqs [minor].mapped)
return 0;
poll_wait (filp, &shmiqs [minor].proc_list, wait);
s = shmiqs [minor].shmiq_vaddr;
if (s->head != s->tail)
return POLLIN | POLLRDNORM;
return 0;
}
static int
shmiq_qcntl_open (struct inode *inode, struct file *filp)
{
int minor = MINOR (inode->i_rdev);
if (minor == 0)
return 0;
minor--;
if (minor > MAX_SHMI_QUEUES)
return -EINVAL;
spin_lock( &shmiqs [minor].shmiq_lock );
if (shmiqs [minor].opened)
{
spin_unlock( &shmiqs [minor].shmiq_lock );
return -EBUSY;
}
shmiqs [minor].opened = 1;
shmiqs [minor].shmiq_vaddr = 0;
spin_unlock( &shmiqs [minor].shmiq_lock );
return 0;
}
static int
shmiq_qcntl_fasync (int fd, struct file *file, int on)
{
int retval;
int minor = MINOR (file->f_dentry->d_inode->i_rdev);
retval = fasync_helper (fd, file, on, &shmiqs [minor].fasync);
if (retval < 0)
return retval;
return 0;
}
static int
shmiq_qcntl_close (struct inode *inode, struct file *filp)
{
int minor = MINOR (inode->i_rdev);
int j;
if (minor-- == 0){
for (j = 0; j < MAX_SHMIQ_DEVS; j++)
shmiq_forget_file (j);
}
if (minor > MAX_SHMI_QUEUES)
return -EINVAL;
spin_lock( &shmiqs [minor].shmiq_lock );
if (shmiqs [minor].opened == 0) {
spin_unlock( &shmiqs [minor].shmiq_lock );
return -EINVAL;
}
shmiq_qcntl_fasync (-1, filp, 0);
shmiqs [minor].opened = 0;
shmiqs [minor].mapped = 0;
shmiqs [minor].events = 0;
shmiqs [minor].fasync = 0;
vfree (shmiqs [minor].shmiq_vaddr);
shmiqs [minor].shmiq_vaddr = 0;
spin_unlock( &shmiqs [minor].shmiq_lock );
return 0;
}
static struct file_operations shmiq_fops =
{
.poll = shmiq_qcntl_poll,
.ioctl = shmiq_qcntl_ioctl,
.mmap = shmiq_qcntl_mmap,
.open = shmiq_qcntl_open,
.release = shmiq_qcntl_close,
.fasync = shmiq_qcntl_fasync,
};
void
shmiq_init (void)
{
static char names[3] = { "shmiq", "qcntl0", "qcntl1" };
int i;
printk ("SHMIQ setup\n");
register_chrdev(SHMIQ_MAJOR, "shmiq", &shmiq_fops);
for (i = 0; i < 3; i++) {
devfs_mk_cdev(MKDEV(SHMIQ_MAJOR, i),
S_IFCHR | S_IRUSR | S_IWUSR, names[i]);
}
}
EXPORT_SYMBOL(shmiq_init);
/* $Id: streamable.c,v 1.10 2000/02/05 06:47:30 ralf Exp $
*
* streamable.c: streamable devices. /dev/gfx
* (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
*
* Major 10 is the streams clone device. The IRIX Xsgi server just
* opens /dev/gfx and closes it inmediately.
*
*/
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/kbd_kern.h>
#include <linux/vt_kern.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/shmiq.h>
#include <asm/keyboard.h>
#include "graphics.h"
extern struct kbd_struct kbd_table [MAX_NR_CONSOLES];
/* console number where forwarding is enabled */
int forward_chars;
/* To which shmiq this keyboard is assigned */
int kbd_assigned_device;
/* previous kbd_mode for the forward_chars terminal */
int kbd_prev_mode;
/* Fetchs the strioctl information from user space for I_STR ioctls */
int
get_sioc (struct strioctl *sioc, unsigned long arg)
{
int v;
v = verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct strioctl));
if (v)
return v;
if (copy_from_user (sioc, (void *) arg, sizeof (struct strioctl)))
return -EFAULT;
v = verify_area (VERIFY_WRITE, (void *) sioc->ic_dp, sioc->ic_len);
if (v)
return v;
return 0;
}
/* /dev/gfx device */
static int
sgi_gfx_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
printk ("GFX: ioctl 0x%x %ld called\n", cmd, arg);
return 0;
return -EINVAL;
}
struct file_operations sgi_gfx_fops = {
.ioctl = sgi_gfx_ioctl,
};
static struct miscdevice dev_gfx = {
SGI_GFX_MINOR, "sgi-gfx", &sgi_gfx_fops
};
/* /dev/input/keyboard streams device */
static idevDesc sgi_kbd_desc = {
"keyboard", /* devName */
"KEYBOARD", /* devType */
240, /* nButtons */
0, /* nValuators */
0, /* nLEDs */
0, /* nStrDpys */
0, /* nIntDpys */
0, /* nBells */
IDEV_HAS_KEYMAP | IDEV_HAS_PCKBD
};
static int
sgi_kbd_sioc (idevInfo *dinfo, int cmd, int size, char *data, int *found)
{
*found = 1;
switch (cmd){
case IDEVINITDEVICE:
return 0;
case IDEVGETDEVICEDESC:
if (size >= sizeof (idevDesc)){
if (copy_to_user (data, &sgi_kbd_desc, sizeof (sgi_kbd_desc)))
return -EFAULT;
return 0;
}
return -EINVAL;
case IDEVGETKEYMAPDESC:
if (size >= sizeof (idevKeymapDesc)){
if (copy_to_user (data, "US", 3))
return -EFAULT;
return 0;
}
return -EINVAL;
}
*found = 0;
return -EINVAL;
}
static int
sgi_keyb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
struct strioctl sioc;
int f, v;
/* IRIX calls I_PUSH on the opened device, go figure */
if (cmd == I_PUSH)
return 0;
if (cmd == I_STR){
v = get_sioc (&sioc, arg);
if (v)
return v;
/* Why like this? Because this is a sample piece of code
* that can be copied into other drivers and shows how to
* call a stock IRIX xxx_wioctl routine
*
* The NULL is supposed to be a idevInfo, right now we
* do not support this in our kernel.
*/
return sgi_kbd_sioc (NULL, sioc.ic_cmd, sioc.ic_len, sioc.ic_dp, &f);
}
if (cmd == SHMIQ_ON){
kbd_assigned_device = arg;
forward_chars = fg_console + 1;
kbd_prev_mode = kbd_table [fg_console].kbdmode;
kbd_table [fg_console].kbdmode = VC_RAW;
} else if (cmd == SHMIQ_OFF && forward_chars){
kbd_table [forward_chars-1].kbdmode = kbd_prev_mode;
forward_chars = 0;
} else
return -EINVAL;
return 0;
}
void
kbd_forward_char (int ch)
{
static struct shmqevent ev;
ev.data.flags = (ch & 0200) ? 0 : 1;
ev.data.which = ch;
ev.data.device = kbd_assigned_device + 0x11;
shmiq_push_event (&ev);
}
static int
sgi_keyb_open (struct inode *inode, struct file *file)
{
/* Nothing, but required by the misc driver */
return 0;
}
struct file_operations sgi_keyb_fops = {
.ioctl = sgi_keyb_ioctl,
.open = sgi_keyb_open,
};
static struct miscdevice dev_input_keyboard = {
SGI_STREAMS_KEYBOARD, "streams-keyboard", &sgi_keyb_fops
};
/* /dev/input/mouse streams device */
#define MOUSE_VALUATORS 2
static idevDesc sgi_mouse_desc = {
"mouse", /* devName */
"MOUSE", /* devType */
3, /* nButtons */
MOUSE_VALUATORS, /* nValuators */
0, /* nLEDs */
0, /* nStrDpys */
0, /* nIntDpys */
0, /* nBells */
0 /* flags */
};
static idevValuatorDesc mouse_default_valuator = {
200, /* hwMinRes */
200, /* hwMaxRes */
0, /* hwMinVal */
65000, /* hwMaxVal */
IDEV_EITHER, /* possibleModes */
IDEV_ABSOLUTE, /* default mode */
200, /* resolution */
0, /* minVal */
65000 /* maxVal */
};
static int mouse_opened;
static idevValuatorDesc mouse_valuators [MOUSE_VALUATORS];
int
sgi_mouse_open (struct inode *inode, struct file *file)
{
int i;
if (mouse_opened)
return -EBUSY;
mouse_opened = 1;
for (i = 0; i < MOUSE_VALUATORS; i++)
mouse_valuators [i] = mouse_default_valuator;
return 0;
}
static int
sgi_mouse_close (struct inode *inode, struct file *filp)
{
mouse_opened = 0;
return 0;
}
static int
sgi_mouse_sioc (idevInfo *dinfo, int cmd, int size, char *data, int *found)
{
*found = 1;
switch (cmd){
case IDEVINITDEVICE:
return 0;
case IDEVGETDEVICEDESC:
if (size >= sizeof (idevDesc)){
if (copy_to_user (data, &sgi_mouse_desc, sizeof (sgi_mouse_desc)))
return -EFAULT;
return 0;
}
return -EINVAL;
case IDEVGETVALUATORDESC: {
idevGetSetValDesc request, *ureq = (idevGetSetValDesc *) data;
if (size < sizeof (idevGetSetValDesc))
return -EINVAL;
if (copy_from_user (&request, data, sizeof (request)))
return -EFAULT;
if (request.valNum >= MOUSE_VALUATORS)
return -EINVAL;
if (copy_to_user ((void *)&ureq->desc,
(void *)&mouse_valuators [request.valNum],
sizeof (idevValuatorDesc)))
return -EFAULT;
return 0;
}
}
*found = 0;
return -EINVAL;
}
static int
sgi_mouse_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
struct strioctl sioc;
int f, v;
/* IRIX calls I_PUSH on the opened device, go figure */
switch (cmd){
case I_PUSH:
return 0;
case I_STR:
v = get_sioc (&sioc, arg);
if (v)
return v;
/* Why like this? Because this is a sample piece of code
* that can be copied into other drivers and shows how to
* call a stock IRIX xxx_wioctl routine
*
* The NULL is supposed to be a idevInfo, right now we
* do not support this in our kernel.
*/
return sgi_mouse_sioc (NULL, sioc.ic_cmd, sioc.ic_len, sioc.ic_dp, &f);
case SHMIQ_ON:
case SHMIQ_OFF:
return 0;
}
return 0;
}
struct file_operations sgi_mouse_fops = {
.ioctl = sgi_mouse_ioctl,
.open = sgi_mouse_open,
.release = sgi_mouse_close,
};
/* /dev/input/mouse */
static struct miscdevice dev_input_mouse = {
SGI_STREAMS_KEYBOARD, "streams-mouse", &sgi_mouse_fops
};
void
streamable_init (void)
{
if (misc_register (&dev_gfx) < 0) {
printk(KERN_ERR
"streamable: cannot register gfx misc device.\n");
return;
}
if (misc_register (&dev_input_keyboard) < 0) {
printk(KERN_ERR
"streamable: cannot register keyboard misc device.\n");
misc_deregister(&dev_gfx);
return;
}
if (misc_register (&dev_input_mouse) < 0) {
printk(KERN_ERR
"streamable: cannot register mouse misc device.\n");
misc_deregister(&dev_input_keyboard);
misc_deregister(&dev_gfx);
return;
}
printk ("streamable: misc devices registered (keyb:%d, gfx:%d)\n",
SGI_STREAMS_KEYBOARD, SGI_GFX_MINOR);
}
/*
* usema.c: software semaphore driver (see IRIX's usema(7M))
* written 1997 Mike Shaver (shaver@neon.ingenia.ca)
* 1997 Miguel de Icaza (miguel@kernel.org)
*
* This file contains the implementation of /dev/usemaclone,
* the devices used by IRIX's us* semaphore routines.
*
* /dev/usemaclone is used to create a new semaphore device, and then
* the semaphore is manipulated via ioctls.
*
* At least for the zero-contention case, lock set and unset as well
* as semaphore P and V are done in userland, which makes things a
* little bit better. I suspect that the ioctls are used to register
* the process as blocking, etc.
*
* Much inspiration and structure stolen from Miguel's shmiq work.
*
* For more information:
* usema(7m), usinit(3p), usnewsema(3p)
* /usr/include/sys/usioctl.h
*
*/
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/file.h>
#include <linux/major.h>
#include <linux/poll.h>
#include <linux/string.h>
#include <linux/dcache.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include "usema.h"
#include <asm/usioctl.h>
#include <asm/mman.h>
#include <asm/uaccess.h>
struct irix_usema {
struct file *filp;
wait_queue_head_t proc_list;
};
static int
sgi_usema_attach (usattach_t * attach, struct irix_usema *usema)
{
int newfd;
newfd = get_unused_fd();
if (newfd < 0)
return newfd;
get_file(usema->filp);
fd_install(newfd, usema->filp);
/* Is that it? */
printk("UIOCATTACHSEMA: new usema fd is %d", newfd);
return newfd;
}
static int
sgi_usemaclone_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg)
{
struct irix_usema *usema = file->private_data;
int retval;
printk("[%s:%d] wants ioctl 0x%xd (arg 0x%lx)",
current->comm, current->pid, cmd, arg);
switch(cmd) {
case UIOCATTACHSEMA: {
/* They pass us information about the semaphore to
which they wish to be attached, and we create&return
a new fd corresponding to the appropriate semaphore.
*/
usattach_t *attach = (usattach_t *)arg;
retval = verify_area(VERIFY_READ, attach, sizeof(usattach_t));
if (retval) {
printk("[%s:%d] sgi_usema_ioctl(UIOCATTACHSEMA): "
"verify_area failure",
current->comm, current->pid);
return retval;
}
if (usema == 0)
return -EINVAL;
printk("UIOCATTACHSEMA: attaching usema %p to process %d\n",
usema, current->pid);
/* XXX what is attach->us_handle for? */
return sgi_usema_attach(attach, usema);
break;
}
case UIOCABLOCK: /* XXX make `async' */
case UIOCNOIBLOCK: /* XXX maybe? */
case UIOCBLOCK: {
/* Block this process on the semaphore */
usattach_t *attach = (usattach_t *)arg;
retval = verify_area(VERIFY_READ, attach, sizeof(usattach_t));
if (retval) {
printk("[%s:%d] sgi_usema_ioctl(UIOC*BLOCK): "
"verify_area failure",
current->comm, current->pid);
return retval;
}
printk("UIOC*BLOCK: putting process %d to sleep on usema %p",
current->pid, usema);
if (cmd == UIOCNOIBLOCK)
interruptible_sleep_on(&usema->proc_list);
else
sleep_on(&usema->proc_list);
return 0;
}
case UIOCAUNBLOCK: /* XXX make `async' */
case UIOCUNBLOCK: {
/* Wake up all process waiting on this semaphore */
usattach_t *attach = (usattach_t *)arg;
retval = verify_area(VERIFY_READ, attach, sizeof(usattach_t));
if (retval) {
printk("[%s:%d] sgi_usema_ioctl(UIOC*BLOCK): "
"verify_area failure",
current->comm, current->pid);
return retval;
}
printk("[%s:%d] releasing usema %p",
current->comm, current->pid, usema);
wake_up(&usema->proc_list);
return 0;
}
}
return -ENOSYS;
}
static unsigned int
sgi_usemaclone_poll(struct file *filp, poll_table *wait)
{
struct irix_usema *usema = filp->private_data;
printk("[%s:%d] wants to poll usema %p",
current->comm, current->pid, usema);
return 0;
}
static int
sgi_usemaclone_open(struct inode *inode, struct file *filp)
{
struct irix_usema *usema;
usema = kmalloc (sizeof (struct irix_usema), GFP_KERNEL);
if (!usema)
return -ENOMEM;
usema->filp = filp;
init_waitqueue_head(&usema->proc_list);
filp->private_data = usema;
return 0;
}
struct file_operations sgi_usemaclone_fops = {
.poll = sgi_usemaclone_poll,
.ioctl = sgi_usemaclone_ioctl,
.open = sgi_usemaclone_open,
};
static struct miscdevice dev_usemaclone = {
SGI_USEMACLONE, "usemaclone", &sgi_usemaclone_fops
};
void
usema_init(void)
{
if (misc_register(&dev_usemaclone) < 0) {
printk(KERN_ERR "usemaclone: cannot register misc device.\n");
return;
}
printk("usemaclone misc device registered (minor: %d)\n",
SGI_USEMACLONE);
}
EXPORT_SYMBOL(usema_init);
/* usema.h
*
* Copyright (C) 1996 Alex deVries <puffin@redhat.com>
*/
#ifndef _SGI_USEMA_H
#define _SGI_USEMA_H
void usema_init (void);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment