1157299Smarcel#-
2157299Smarcel# Copyright (c) 2006 Marcel Moolenaar
3157299Smarcel# All rights reserved.
4157299Smarcel#
5157299Smarcel# Redistribution and use in source and binary forms, with or without
6157299Smarcel# modification, are permitted provided that the following conditions
7157299Smarcel# are met:
8157299Smarcel# 1. Redistributions of source code must retain the above copyright
9157299Smarcel#    notice, this list of conditions and the following disclaimer.
10157299Smarcel# 2. Redistributions in binary form must reproduce the above copyright
11157299Smarcel#    notice, this list of conditions and the following disclaimer in the
12157299Smarcel#    documentation and/or other materials provided with the distribution.
13157299Smarcel#
14157299Smarcel# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15157299Smarcel# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16157299Smarcel# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17157299Smarcel# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18157299Smarcel# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19157299Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20157299Smarcel# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21157299Smarcel# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22157299Smarcel# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23157299Smarcel# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24157299Smarcel# SUCH DAMAGE.
25157299Smarcel#
26157299Smarcel# $FreeBSD$
27157299Smarcel#
28157299Smarcel
29157299Smarcel#include <sys/bus.h>
30157299Smarcel#include <sys/serial.h>
31157299Smarcel
32157299Smarcel# The serdev interface is used by umbrella drivers and children thereof to
33157299Smarcel# establish a more intimate relationship, necessary for efficient handling
34157299Smarcel# of multiple (concurrent) serial communication channels.  Examples include
35157299Smarcel# serial communications controller (SCC) drivers, multi-I/O adapter drivers
36157299Smarcel# and intelligent multi-port serial drivers.  Methods specifically deal
37157299Smarcel# with interrupt handling and configuration.  Conceptually, the umbrella
38157299Smarcel# driver is responsible for the overall operation of the hardware and uses
39157299Smarcel# child drivers to handle each individual channel.
40157299Smarcel# The serdev interface is intended to inherit the device interface.
41157299Smarcel
42157299SmarcelINTERFACE serdev;
43157299Smarcel
44157299Smarcel# Default implementations of some methods.
45157299SmarcelCODE {
46157299Smarcel	static serdev_intr_t *
47157299Smarcel	default_ihand(device_t dev, int ipend)
48157299Smarcel	{
49157299Smarcel		return (NULL);
50157299Smarcel	}
51157299Smarcel
52157299Smarcel	static int
53157990Smarcel	default_ipend(device_t dev)
54157990Smarcel	{
55157990Smarcel		return (-1);
56157990Smarcel	}
57157990Smarcel
58157990Smarcel	static int
59157299Smarcel	default_sysdev(device_t dev)
60157299Smarcel	{
61157299Smarcel		return (0);
62157299Smarcel	}
63157299Smarcel};
64157299Smarcel
65157299Smarcel# ihand() - Query serial device interrupt handler.
66157299Smarcel# This method is called by the umbrella driver to obtain function pointers
67157299Smarcel# to interrupt handlers for each individual interrupt source. This allows
68157299Smarcel# the umbralla driver to control the servicing of interrupts between the
69157299Smarcel# different channels in the most flexible way.
70157299SmarcelMETHOD serdev_intr_t* ihand {
71157299Smarcel	device_t dev;
72157299Smarcel	int ipend;
73157299Smarcel} DEFAULT default_ihand;
74157299Smarcel
75157990Smarcel# ipend() - Query pending interrupt status.
76157990Smarcel# This method is called by the umbrella driver to obtain interrupt status
77157990Smarcel# for the UART in question. This allows the umbrella driver to build a
78157990Smarcel# matrix and service the interrupts in the most flexible way by calling
79157990Smarcel# interrupt handlers collected with the ihand() method.
80157990SmarcelMETHOD int ipend {
81157990Smarcel	device_t dev;
82157990Smarcel} DEFAULT default_ipend;
83157990Smarcel
84157299Smarcel# sysdev() - Query system device status 
85157299Smarcel# This method may be called by the umbrella driver for each child driver
86157299Smarcel# to establish if a particular channel and mode is currently being used
87157299Smarcel# for system specific usage. If this is the case, the hardware is not
88157299Smarcel# reset and the channel will not change its operation mode.
89157299Smarcel# The return value is !0 if the channel and mode are used for a system
90157299Smarcel# device and 0 otherwise.
91157299SmarcelMETHOD int sysdev {
92157299Smarcel	device_t dev;
93157299Smarcel} DEFAULT default_sysdev;
94157299Smarcel
95