]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/uart/uart_bus_pccard.c
Ensure a minimum packet length before creating a mbuf in if_ure.
[FreeBSD/FreeBSD.git] / sys / dev / uart / uart_bus_pccard.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2003 Norikatsu Shigemura, Takenori Watanabe All rights reserved.
5  * Copyright (c) 2001 M. Warner Losh <imp@FreeBSD.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/conf.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39
40 #include <dev/pccard/pccard_cis.h>
41 #include <dev/pccard/pccardvar.h>
42
43 #include <dev/uart/uart.h>
44 #include <dev/uart/uart_bus.h>
45
46 #include "pccarddevs.h"
47
48 static  int     uart_pccard_probe(device_t dev);
49 static  int     uart_pccard_attach(device_t dev);
50
51 static device_method_t uart_pccard_methods[] = {
52         /* Device interface */
53         DEVMETHOD(device_probe,         uart_pccard_probe),
54         DEVMETHOD(device_attach,        uart_pccard_attach),
55         DEVMETHOD(device_detach,        uart_bus_detach),
56         { 0, 0 }
57 };
58
59 static uint32_t uart_pccard_function = PCCARD_FUNCTION_SERIAL;
60
61 static driver_t uart_pccard_driver = {
62         uart_driver_name,
63         uart_pccard_methods,
64         sizeof(struct uart_softc),
65 };
66
67 static int
68 uart_pccard_probe(device_t dev)
69 {
70         int error;
71         uint32_t fcn;
72
73         fcn = PCCARD_FUNCTION_UNSPEC;
74         error = pccard_get_function(dev, &fcn);
75         if (error != 0)
76                 return (error);
77         /*
78          * If a serial card, we are likely the right driver.  However,
79          * some serial cards are better serviced by other drivers, so
80          * allow other drivers to claim it, if they want.
81          */
82         if (fcn == uart_pccard_function)
83                 return (BUS_PROBE_GENERIC);
84
85         return (ENXIO);
86 }
87
88 static int
89 uart_pccard_attach(device_t dev)
90 {
91         struct uart_softc *sc;
92         int error;
93
94         sc = device_get_softc(dev);
95         sc->sc_class = &uart_ns8250_class;
96
97         error = uart_bus_probe(dev, 0, 0, 0, 0, 0, 0);
98         if (error > 0)
99                 return (error);
100         gone_in_dev(dev, 13, "pccard removed");
101         return (uart_bus_attach(dev));
102 }
103
104 DRIVER_MODULE(uart, pccard, uart_pccard_driver, uart_devclass, 0, 0);
105 MODULE_PNP_INFO("U32:function_type;", pccard, uart, &uart_pccard_function,
106     1);