Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/atkbdc/atkbdc_subr.c
39507 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 1999 Kazutaka YOKOTA <[email protected]>
5
* All rights reserved.
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 as
12
* the first lines of this file unmodified.
13
* 2. Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*
28
* from: FreeBSD: src/sys/isa/atkbdc_isa.c,v 1.31 2005/05/29 04:42:28 nyan Exp
29
*/
30
31
#include <sys/cdefs.h>
32
#include "opt_kbd.h"
33
34
#include <sys/param.h>
35
#include <sys/systm.h>
36
#include <sys/kernel.h>
37
#include <sys/module.h>
38
#include <sys/bus.h>
39
#include <sys/malloc.h>
40
#include <machine/resource.h>
41
#include <sys/rman.h>
42
43
#include <dev/atkbdc/atkbdc_subr.h>
44
#include <dev/atkbdc/atkbdcreg.h>
45
46
MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
47
48
int
49
atkbdc_print_child(device_t bus, device_t dev)
50
{
51
atkbdc_device_t *kbdcdev;
52
rman_res_t irq;
53
int flags;
54
int retval = 0;
55
56
kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
57
58
retval += bus_print_child_header(bus, dev);
59
flags = device_get_flags(dev);
60
if (flags != 0)
61
retval += printf(" flags 0x%x", flags);
62
irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
63
if (irq != 0)
64
retval += printf(" irq %jd", irq);
65
retval += bus_print_child_footer(bus, dev);
66
67
return (retval);
68
}
69
70
int
71
atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
72
{
73
atkbdc_device_t *ivar;
74
75
ivar = (atkbdc_device_t *)device_get_ivars(dev);
76
switch (index) {
77
case KBDC_IVAR_VENDORID:
78
*val = (u_long)ivar->vendorid;
79
break;
80
case KBDC_IVAR_SERIAL:
81
*val = (u_long)ivar->serial;
82
break;
83
case KBDC_IVAR_LOGICALID:
84
*val = (u_long)ivar->logicalid;
85
break;
86
case KBDC_IVAR_COMPATID:
87
*val = (u_long)ivar->compatid;
88
break;
89
default:
90
return ENOENT;
91
}
92
return 0;
93
}
94
95
int
96
atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
97
{
98
atkbdc_device_t *ivar;
99
100
ivar = (atkbdc_device_t *)device_get_ivars(dev);
101
switch (index) {
102
case KBDC_IVAR_VENDORID:
103
ivar->vendorid = (u_int32_t)val;
104
break;
105
case KBDC_IVAR_SERIAL:
106
ivar->serial = (u_int32_t)val;
107
break;
108
case KBDC_IVAR_LOGICALID:
109
ivar->logicalid = (u_int32_t)val;
110
break;
111
case KBDC_IVAR_COMPATID:
112
ivar->compatid = (u_int32_t)val;
113
break;
114
default:
115
return ENOENT;
116
}
117
return 0;
118
}
119
120
struct resource_list
121
*atkbdc_get_resource_list(device_t bus, device_t dev)
122
{
123
atkbdc_device_t *ivar;
124
125
ivar = (atkbdc_device_t *)device_get_ivars(dev);
126
return &ivar->resources;
127
}
128
129