xref: /freebsd/sys/kern/serdev_if.m (revision 031beb4e)
16174e6edSMarcel Moolenaar#-
26174e6edSMarcel Moolenaar# Copyright (c) 2006 Marcel Moolenaar
36174e6edSMarcel Moolenaar# All rights reserved.
46174e6edSMarcel Moolenaar#
56174e6edSMarcel Moolenaar# Redistribution and use in source and binary forms, with or without
66174e6edSMarcel Moolenaar# modification, are permitted provided that the following conditions
76174e6edSMarcel Moolenaar# are met:
86174e6edSMarcel Moolenaar# 1. Redistributions of source code must retain the above copyright
96174e6edSMarcel Moolenaar#    notice, this list of conditions and the following disclaimer.
106174e6edSMarcel Moolenaar# 2. Redistributions in binary form must reproduce the above copyright
116174e6edSMarcel Moolenaar#    notice, this list of conditions and the following disclaimer in the
126174e6edSMarcel Moolenaar#    documentation and/or other materials provided with the distribution.
136174e6edSMarcel Moolenaar#
146174e6edSMarcel Moolenaar# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156174e6edSMarcel Moolenaar# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166174e6edSMarcel Moolenaar# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176174e6edSMarcel Moolenaar# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186174e6edSMarcel Moolenaar# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196174e6edSMarcel Moolenaar# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206174e6edSMarcel Moolenaar# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216174e6edSMarcel Moolenaar# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226174e6edSMarcel Moolenaar# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236174e6edSMarcel Moolenaar# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246174e6edSMarcel Moolenaar# SUCH DAMAGE.
256174e6edSMarcel Moolenaar#
266174e6edSMarcel Moolenaar#
276174e6edSMarcel Moolenaar
286174e6edSMarcel Moolenaar#include <sys/bus.h>
296174e6edSMarcel Moolenaar#include <sys/serial.h>
306174e6edSMarcel Moolenaar
316174e6edSMarcel Moolenaar# The serdev interface is used by umbrella drivers and children thereof to
326174e6edSMarcel Moolenaar# establish a more intimate relationship, necessary for efficient handling
336174e6edSMarcel Moolenaar# of multiple (concurrent) serial communication channels.  Examples include
346174e6edSMarcel Moolenaar# serial communications controller (SCC) drivers, multi-I/O adapter drivers
356174e6edSMarcel Moolenaar# and intelligent multi-port serial drivers.  Methods specifically deal
366174e6edSMarcel Moolenaar# with interrupt handling and configuration.  Conceptually, the umbrella
376174e6edSMarcel Moolenaar# driver is responsible for the overall operation of the hardware and uses
386174e6edSMarcel Moolenaar# child drivers to handle each individual channel.
396174e6edSMarcel Moolenaar# The serdev interface is intended to inherit the device interface.
406174e6edSMarcel Moolenaar
416174e6edSMarcel MoolenaarINTERFACE serdev;
426174e6edSMarcel Moolenaar
436174e6edSMarcel Moolenaar# Default implementations of some methods.
446174e6edSMarcel MoolenaarCODE {
456174e6edSMarcel Moolenaar	static serdev_intr_t *
466174e6edSMarcel Moolenaar	default_ihand(device_t dev, int ipend)
476174e6edSMarcel Moolenaar	{
486174e6edSMarcel Moolenaar		return (NULL);
496174e6edSMarcel Moolenaar	}
506174e6edSMarcel Moolenaar
516174e6edSMarcel Moolenaar	static int
52845652ddSMarcel Moolenaar	default_ipend(device_t dev)
53845652ddSMarcel Moolenaar	{
54845652ddSMarcel Moolenaar		return (-1);
55845652ddSMarcel Moolenaar	}
56845652ddSMarcel Moolenaar
57845652ddSMarcel Moolenaar	static int
586174e6edSMarcel Moolenaar	default_sysdev(device_t dev)
596174e6edSMarcel Moolenaar	{
606174e6edSMarcel Moolenaar		return (0);
616174e6edSMarcel Moolenaar	}
626174e6edSMarcel Moolenaar};
636174e6edSMarcel Moolenaar
646174e6edSMarcel Moolenaar# ihand() - Query serial device interrupt handler.
656174e6edSMarcel Moolenaar# This method is called by the umbrella driver to obtain function pointers
666174e6edSMarcel Moolenaar# to interrupt handlers for each individual interrupt source. This allows
676174e6edSMarcel Moolenaar# the umbralla driver to control the servicing of interrupts between the
686174e6edSMarcel Moolenaar# different channels in the most flexible way.
696174e6edSMarcel MoolenaarMETHOD serdev_intr_t* ihand {
706174e6edSMarcel Moolenaar	device_t dev;
716174e6edSMarcel Moolenaar	int ipend;
726174e6edSMarcel Moolenaar} DEFAULT default_ihand;
736174e6edSMarcel Moolenaar
74845652ddSMarcel Moolenaar# ipend() - Query pending interrupt status.
75845652ddSMarcel Moolenaar# This method is called by the umbrella driver to obtain interrupt status
76845652ddSMarcel Moolenaar# for the UART in question. This allows the umbrella driver to build a
77845652ddSMarcel Moolenaar# matrix and service the interrupts in the most flexible way by calling
78845652ddSMarcel Moolenaar# interrupt handlers collected with the ihand() method.
79845652ddSMarcel MoolenaarMETHOD int ipend {
80845652ddSMarcel Moolenaar	device_t dev;
81845652ddSMarcel Moolenaar} DEFAULT default_ipend;
82845652ddSMarcel Moolenaar
836174e6edSMarcel Moolenaar# sysdev() - Query system device status
846174e6edSMarcel Moolenaar# This method may be called by the umbrella driver for each child driver
856174e6edSMarcel Moolenaar# to establish if a particular channel and mode is currently being used
866174e6edSMarcel Moolenaar# for system specific usage. If this is the case, the hardware is not
876174e6edSMarcel Moolenaar# reset and the channel will not change its operation mode.
886174e6edSMarcel Moolenaar# The return value is !0 if the channel and mode are used for a system
896174e6edSMarcel Moolenaar# device and 0 otherwise.
906174e6edSMarcel MoolenaarMETHOD int sysdev {
916174e6edSMarcel Moolenaar	device_t dev;
926174e6edSMarcel Moolenaar} DEFAULT default_sysdev;
936174e6edSMarcel Moolenaar
94