Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240506140308.4040735-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
c0e1aa60 3093f180

+145 -120
+7
drivers/tty/serial/8250/8250.h
··· 111 111 112 112 #define SERIAL8250_PORT(_base, _irq) SERIAL8250_PORT_FLAGS(_base, _irq, 0) 113 113 114 + extern const struct uart_ops *univ8250_port_base_ops; 114 115 115 116 static inline int serial_in(struct uart_8250_port *up, int offset) 116 117 { ··· 300 299 #else 301 300 static inline int serial8250_pnp_init(void) { return 0; } 302 301 static inline void serial8250_pnp_exit(void) { } 302 + #endif 303 + 304 + #ifdef CONFIG_SERIAL_8250_RSA 305 + void univ8250_rsa_support(struct uart_ops *ops); 306 + #else 307 + static inline void univ8250_rsa_support(struct uart_ops *ops) { } 303 308 #endif 304 309 305 310 #ifdef CONFIG_SERIAL_8250_FINTEK
+4 -120
drivers/tty/serial/8250/8250_core.c
··· 77 77 78 78 #define UART_NR CONFIG_SERIAL_8250_NR_UARTS 79 79 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 - 87 80 struct irq_info { 88 81 struct hlist_node node; 89 82 int irq; ··· 341 348 serial_unlink_irq_chain(up); 342 349 } 343 350 344 - #ifdef CONFIG_SERIAL_8250_RSA 345 - static int serial8250_request_rsa_resource(struct uart_8250_port *up) 346 - { 347 - unsigned long start = UART_RSA_BASE << up->port.regshift; 348 - unsigned int size = 8 << up->port.regshift; 349 - struct uart_port *port = &up->port; 350 - int ret = -EINVAL; 351 - 352 - switch (port->iotype) { 353 - case UPIO_HUB6: 354 - case UPIO_PORT: 355 - start += port->iobase; 356 - if (request_region(start, size, "serial-rsa")) 357 - ret = 0; 358 - else 359 - ret = -EBUSY; 360 - break; 361 - } 362 - 363 - return ret; 364 - } 365 - 366 - static void serial8250_release_rsa_resource(struct uart_8250_port *up) 367 - { 368 - unsigned long offset = UART_RSA_BASE << up->port.regshift; 369 - unsigned int size = 8 << up->port.regshift; 370 - struct uart_port *port = &up->port; 371 - 372 - switch (port->iotype) { 373 - case UPIO_HUB6: 374 - case UPIO_PORT: 375 - release_region(port->iobase + offset, size); 376 - break; 377 - } 378 - } 379 - #endif 380 - 381 - static const struct uart_ops *base_ops; 351 + const struct uart_ops *univ8250_port_base_ops = NULL; 382 352 static struct uart_ops univ8250_port_ops; 383 353 384 354 static const struct uart_8250_ops univ8250_driver_ops = { ··· 380 424 } 381 425 EXPORT_SYMBOL(serial8250_set_isa_configurator); 382 426 383 - #ifdef CONFIG_SERIAL_8250_RSA 384 - 385 - static void univ8250_config_port(struct uart_port *port, int flags) 386 - { 387 - struct uart_8250_port *up = up_to_u8250p(port); 388 - 389 - up->probe &= ~UART_PROBE_RSA; 390 - if (port->type == PORT_RSA) { 391 - if (serial8250_request_rsa_resource(up) == 0) 392 - up->probe |= UART_PROBE_RSA; 393 - } else if (flags & UART_CONFIG_TYPE) { 394 - int i; 395 - 396 - for (i = 0; i < probe_rsa_count; i++) { 397 - if (probe_rsa[i] == up->port.iobase) { 398 - if (serial8250_request_rsa_resource(up) == 0) 399 - up->probe |= UART_PROBE_RSA; 400 - break; 401 - } 402 - } 403 - } 404 - 405 - base_ops->config_port(port, flags); 406 - 407 - if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA) 408 - serial8250_release_rsa_resource(up); 409 - } 410 - 411 - static int univ8250_request_port(struct uart_port *port) 412 - { 413 - struct uart_8250_port *up = up_to_u8250p(port); 414 - int ret; 415 - 416 - ret = base_ops->request_port(port); 417 - if (ret == 0 && port->type == PORT_RSA) { 418 - ret = serial8250_request_rsa_resource(up); 419 - if (ret < 0) 420 - base_ops->release_port(port); 421 - } 422 - 423 - return ret; 424 - } 425 - 426 - static void univ8250_release_port(struct uart_port *port) 427 - { 428 - struct uart_8250_port *up = up_to_u8250p(port); 429 - 430 - if (port->type == PORT_RSA) 431 - serial8250_release_rsa_resource(up); 432 - base_ops->release_port(port); 433 - } 434 - 435 - static void univ8250_rsa_support(struct uart_ops *ops) 436 - { 437 - ops->config_port = univ8250_config_port; 438 - ops->request_port = univ8250_request_port; 439 - ops->release_port = univ8250_release_port; 440 - } 441 - 442 - #else 443 - #define univ8250_rsa_support(x) do { } while (0) 444 - #endif /* CONFIG_SERIAL_8250_RSA */ 445 - 446 427 static inline void serial8250_apply_quirks(struct uart_8250_port *up) 447 428 { 448 429 up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0; ··· 397 504 up->port.port_id = index; 398 505 399 506 serial8250_init_port(up); 400 - if (!base_ops) 401 - base_ops = up->port.ops; 507 + if (!univ8250_port_base_ops) 508 + univ8250_port_base_ops = up->port.ops; 402 509 up->port.ops = &univ8250_port_ops; 403 510 404 511 timer_setup(&up->timer, serial8250_timeout, 0); ··· 432 539 serial8250_setup_port(i); 433 540 434 541 /* chain base port ops to support Remote Supervisor Adapter */ 435 - univ8250_port_ops = *base_ops; 542 + univ8250_port_ops = *univ8250_port_base_ops; 436 543 univ8250_rsa_support(&univ8250_port_ops); 437 544 438 545 if (share_irqs) ··· 1205 1312 module_param(skip_txen_test, uint, 0644); 1206 1313 MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time"); 1207 1314 1208 - #ifdef CONFIG_SERIAL_8250_RSA 1209 - module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444); 1210 - MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA"); 1211 - #endif 1212 1315 MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); 1213 1316 1214 1317 #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS ··· 1227 1338 module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644); 1228 1339 module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644); 1229 1340 module_param_cb(skip_txen_test, &param_ops_uint, &skip_txen_test, 0644); 1230 - #ifdef CONFIG_SERIAL_8250_RSA 1231 - __module_param_call(MODULE_PARAM_PREFIX, probe_rsa, 1232 - &param_array_ops, .arr = &__param_arr_probe_rsa, 1233 - 0444, -1, 0); 1234 - #endif 1235 1341 } 1236 1342 #else 1237 1343 MODULE_ALIAS("8250_core");
+133
drivers/tty/serial/8250/8250_rsa.c
··· 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
+1
drivers/tty/serial/8250/Makefile
··· 6 6 obj-$(CONFIG_SERIAL_8250) += 8250.o 8250_base.o 7 7 8250-y := 8250_core.o 8 8 8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 9 + 8250-$(CONFIG_SERIAL_8250_RSA) += 8250_rsa.o 9 10 8250_base-y := 8250_port.o 10 11 8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 11 12 8250_base-$(CONFIG_SERIAL_8250_DWLIB) += 8250_dwlib.o