Skip to content

Commit c0e1aa6

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250: Extract RSA bits
Extract RSA bits to a separate module for better maintenance and to reduce a churn on 8250_core part changes when it's solely related to the former. No functional changes intended. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3093f18 commit c0e1aa6

File tree

4 files changed

+145
-120
lines changed

4 files changed

+145
-120
lines changed

drivers/tty/serial/8250/8250.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct serial8250_config {
111111

112112
#define SERIAL8250_PORT(_base, _irq) SERIAL8250_PORT_FLAGS(_base, _irq, 0)
113113

114+
extern const struct uart_ops *univ8250_port_base_ops;
114115

115116
static inline int serial_in(struct uart_8250_port *up, int offset)
116117
{
@@ -301,6 +302,12 @@ static inline int serial8250_pnp_init(void) { return 0; }
301302
static inline void serial8250_pnp_exit(void) { }
302303
#endif
303304

305+
#ifdef CONFIG_SERIAL_8250_RSA
306+
void univ8250_rsa_support(struct uart_ops *ops);
307+
#else
308+
static inline void univ8250_rsa_support(struct uart_ops *ops) { }
309+
#endif
310+
304311
#ifdef CONFIG_SERIAL_8250_FINTEK
305312
int fintek_8250_probe(struct uart_8250_port *uart);
306313
#else

drivers/tty/serial/8250/8250_core.c

Lines changed: 4 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ static const struct old_serial_port old_serial_port[] = {
7777

7878
#define UART_NR CONFIG_SERIAL_8250_NR_UARTS
7979

80-
#ifdef CONFIG_SERIAL_8250_RSA
81-
82-
#define PORT_RSA_MAX 4
83-
static unsigned long probe_rsa[PORT_RSA_MAX];
84-
static unsigned int probe_rsa_count;
85-
#endif /* CONFIG_SERIAL_8250_RSA */
86-
8780
struct irq_info {
8881
struct hlist_node node;
8982
int irq;
@@ -348,44 +341,7 @@ static void univ8250_release_irq(struct uart_8250_port *up)
348341
serial_unlink_irq_chain(up);
349342
}
350343

351-
#ifdef CONFIG_SERIAL_8250_RSA
352-
static int serial8250_request_rsa_resource(struct uart_8250_port *up)
353-
{
354-
unsigned long start = UART_RSA_BASE << up->port.regshift;
355-
unsigned int size = 8 << up->port.regshift;
356-
struct uart_port *port = &up->port;
357-
int ret = -EINVAL;
358-
359-
switch (port->iotype) {
360-
case UPIO_HUB6:
361-
case UPIO_PORT:
362-
start += port->iobase;
363-
if (request_region(start, size, "serial-rsa"))
364-
ret = 0;
365-
else
366-
ret = -EBUSY;
367-
break;
368-
}
369-
370-
return ret;
371-
}
372-
373-
static void serial8250_release_rsa_resource(struct uart_8250_port *up)
374-
{
375-
unsigned long offset = UART_RSA_BASE << up->port.regshift;
376-
unsigned int size = 8 << up->port.regshift;
377-
struct uart_port *port = &up->port;
378-
379-
switch (port->iotype) {
380-
case UPIO_HUB6:
381-
case UPIO_PORT:
382-
release_region(port->iobase + offset, size);
383-
break;
384-
}
385-
}
386-
#endif
387-
388-
static const struct uart_ops *base_ops;
344+
const struct uart_ops *univ8250_port_base_ops = NULL;
389345
static struct uart_ops univ8250_port_ops;
390346

391347
static const struct uart_8250_ops univ8250_driver_ops = {
@@ -424,69 +380,6 @@ void serial8250_set_isa_configurator(
424380
}
425381
EXPORT_SYMBOL(serial8250_set_isa_configurator);
426382

427-
#ifdef CONFIG_SERIAL_8250_RSA
428-
429-
static void univ8250_config_port(struct uart_port *port, int flags)
430-
{
431-
struct uart_8250_port *up = up_to_u8250p(port);
432-
433-
up->probe &= ~UART_PROBE_RSA;
434-
if (port->type == PORT_RSA) {
435-
if (serial8250_request_rsa_resource(up) == 0)
436-
up->probe |= UART_PROBE_RSA;
437-
} else if (flags & UART_CONFIG_TYPE) {
438-
int i;
439-
440-
for (i = 0; i < probe_rsa_count; i++) {
441-
if (probe_rsa[i] == up->port.iobase) {
442-
if (serial8250_request_rsa_resource(up) == 0)
443-
up->probe |= UART_PROBE_RSA;
444-
break;
445-
}
446-
}
447-
}
448-
449-
base_ops->config_port(port, flags);
450-
451-
if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA)
452-
serial8250_release_rsa_resource(up);
453-
}
454-
455-
static int univ8250_request_port(struct uart_port *port)
456-
{
457-
struct uart_8250_port *up = up_to_u8250p(port);
458-
int ret;
459-
460-
ret = base_ops->request_port(port);
461-
if (ret == 0 && port->type == PORT_RSA) {
462-
ret = serial8250_request_rsa_resource(up);
463-
if (ret < 0)
464-
base_ops->release_port(port);
465-
}
466-
467-
return ret;
468-
}
469-
470-
static void univ8250_release_port(struct uart_port *port)
471-
{
472-
struct uart_8250_port *up = up_to_u8250p(port);
473-
474-
if (port->type == PORT_RSA)
475-
serial8250_release_rsa_resource(up);
476-
base_ops->release_port(port);
477-
}
478-
479-
static void univ8250_rsa_support(struct uart_ops *ops)
480-
{
481-
ops->config_port = univ8250_config_port;
482-
ops->request_port = univ8250_request_port;
483-
ops->release_port = univ8250_release_port;
484-
}
485-
486-
#else
487-
#define univ8250_rsa_support(x) do { } while (0)
488-
#endif /* CONFIG_SERIAL_8250_RSA */
489-
490383
static inline void serial8250_apply_quirks(struct uart_8250_port *up)
491384
{
492385
up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
@@ -504,8 +397,8 @@ static struct uart_8250_port *serial8250_setup_port(int index)
504397
up->port.port_id = index;
505398

506399
serial8250_init_port(up);
507-
if (!base_ops)
508-
base_ops = up->port.ops;
400+
if (!univ8250_port_base_ops)
401+
univ8250_port_base_ops = up->port.ops;
509402
up->port.ops = &univ8250_port_ops;
510403

511404
timer_setup(&up->timer, serial8250_timeout, 0);
@@ -539,7 +432,7 @@ static void __init serial8250_isa_init_ports(void)
539432
serial8250_setup_port(i);
540433

541434
/* chain base port ops to support Remote Supervisor Adapter */
542-
univ8250_port_ops = *base_ops;
435+
univ8250_port_ops = *univ8250_port_base_ops;
543436
univ8250_rsa_support(&univ8250_port_ops);
544437

545438
if (share_irqs)
@@ -1312,10 +1205,6 @@ MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STR
13121205
module_param(skip_txen_test, uint, 0644);
13131206
MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
13141207

1315-
#ifdef CONFIG_SERIAL_8250_RSA
1316-
module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
1317-
MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
1318-
#endif
13191208
MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
13201209

13211210
#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
@@ -1338,11 +1227,6 @@ static void __used s8250_options(void)
13381227
module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644);
13391228
module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644);
13401229
module_param_cb(skip_txen_test, &param_ops_uint, &skip_txen_test, 0644);
1341-
#ifdef CONFIG_SERIAL_8250_RSA
1342-
__module_param_call(MODULE_PARAM_PREFIX, probe_rsa,
1343-
&param_array_ops, .arr = &__param_arr_probe_rsa,
1344-
0444, -1, 0);
1345-
#endif
13461230
}
13471231
#else
13481232
MODULE_ALIAS("8250_core");

drivers/tty/serial/8250/8250_rsa.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <linux/errno.h>
4+
#include <linux/ioport.h>
5+
#include <linux/module.h>
6+
#include <linux/moduleparam.h>
7+
8+
#include <linux/serial.h>
9+
#include <linux/serial_8250.h>
10+
11+
#include "8250.h"
12+
13+
#define PORT_RSA_MAX 4
14+
static unsigned long probe_rsa[PORT_RSA_MAX];
15+
static unsigned int probe_rsa_count;
16+
17+
static int rsa8250_request_resource(struct uart_8250_port *up)
18+
{
19+
unsigned long start = UART_RSA_BASE << up->port.regshift;
20+
unsigned int size = 8 << up->port.regshift;
21+
struct uart_port *port = &up->port;
22+
int ret = -EINVAL;
23+
24+
switch (port->iotype) {
25+
case UPIO_HUB6:
26+
case UPIO_PORT:
27+
start += port->iobase;
28+
if (request_region(start, size, "serial-rsa"))
29+
ret = 0;
30+
else
31+
ret = -EBUSY;
32+
break;
33+
}
34+
35+
return ret;
36+
}
37+
38+
static void rsa8250_release_resource(struct uart_8250_port *up)
39+
{
40+
unsigned long offset = UART_RSA_BASE << up->port.regshift;
41+
unsigned int size = 8 << up->port.regshift;
42+
struct uart_port *port = &up->port;
43+
44+
switch (port->iotype) {
45+
case UPIO_HUB6:
46+
case UPIO_PORT:
47+
release_region(port->iobase + offset, size);
48+
break;
49+
}
50+
}
51+
52+
static void univ8250_config_port(struct uart_port *port, int flags)
53+
{
54+
struct uart_8250_port *up = up_to_u8250p(port);
55+
unsigned int i;
56+
57+
up->probe &= ~UART_PROBE_RSA;
58+
if (port->type == PORT_RSA) {
59+
if (rsa8250_request_resource(up) == 0)
60+
up->probe |= UART_PROBE_RSA;
61+
} else if (flags & UART_CONFIG_TYPE) {
62+
for (i = 0; i < probe_rsa_count; i++) {
63+
if (probe_rsa[i] == up->port.iobase) {
64+
if (rsa8250_request_resource(up) == 0)
65+
up->probe |= UART_PROBE_RSA;
66+
break;
67+
}
68+
}
69+
}
70+
71+
univ8250_port_base_ops->config_port(port, flags);
72+
73+
if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA)
74+
rsa8250_release_resource(up);
75+
}
76+
77+
static int univ8250_request_port(struct uart_port *port)
78+
{
79+
struct uart_8250_port *up = up_to_u8250p(port);
80+
int ret;
81+
82+
ret = univ8250_port_base_ops->request_port(port);
83+
if (ret == 0 && port->type == PORT_RSA) {
84+
ret = rsa8250_request_resource(up);
85+
if (ret < 0)
86+
univ8250_port_base_ops->release_port(port);
87+
}
88+
89+
return ret;
90+
}
91+
92+
static void univ8250_release_port(struct uart_port *port)
93+
{
94+
struct uart_8250_port *up = up_to_u8250p(port);
95+
96+
if (port->type == PORT_RSA)
97+
rsa8250_release_resource(up);
98+
univ8250_port_base_ops->release_port(port);
99+
}
100+
101+
void univ8250_rsa_support(struct uart_ops *ops)
102+
{
103+
ops->config_port = univ8250_config_port;
104+
ops->request_port = univ8250_request_port;
105+
ops->release_port = univ8250_release_port;
106+
}
107+
108+
module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
109+
MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
110+
111+
#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
112+
#ifndef MODULE
113+
/*
114+
* Keep the old "8250" name working as well for the module options so we don't
115+
* break people. We need to keep the names identical and the convenient macros
116+
* will happily refuse to let us do that by failing the build with redefinition
117+
* errors of global variables. So we stick them inside a dummy function to
118+
* avoid those conflicts. The options still get parsed, and the redefined
119+
* MODULE_PARAM_PREFIX lets us keep the "8250." syntax alive.
120+
*
121+
* This is hacky. I'm sorry.
122+
*/
123+
static void __used rsa8250_options(void)
124+
{
125+
#undef MODULE_PARAM_PREFIX
126+
#define MODULE_PARAM_PREFIX "8250_core."
127+
128+
__module_param_call(MODULE_PARAM_PREFIX, probe_rsa,
129+
&param_array_ops, .arr = &__param_arr_probe_rsa,
130+
0444, -1, 0);
131+
}
132+
#endif
133+
#endif

drivers/tty/serial/8250/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
obj-$(CONFIG_SERIAL_8250) += 8250.o 8250_base.o
77
8250-y := 8250_core.o
88
8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
9+
8250-$(CONFIG_SERIAL_8250_RSA) += 8250_rsa.o
910
8250_base-y := 8250_port.o
1011
8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o
1112
8250_base-$(CONFIG_SERIAL_8250_DWLIB) += 8250_dwlib.o

0 commit comments

Comments
 (0)