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

misc: pti: Remove driver for deprecated platform

Intel Moorestown and Medfield are quite old Intel Atom based
32-bit platforms, which were in limited use in some Android phones,
tablets and consumer electronics more than eight years ago.

There are no bugs or problems ever reported outside from Intel
for breaking any of that platforms for years. It seems no real
users exists who run more or less fresh kernel on it. The commit
05f4434bc130 ("ASoC: Intel: remove mfld_machine") also in align
with this theory.

Due to above and to reduce a burden of supporting outdated drivers
we remove the support of outdated platforms completely.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210122114358.39299-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
8ba59e9d cae2181b

-1624
-108
Documentation/driver-api/pti_intel_mid.rst
··· 1 - .. SPDX-License-Identifier: GPL-2.0 2 - 3 - ============= 4 - Intel MID PTI 5 - ============= 6 - 7 - The Intel MID PTI project is HW implemented in Intel Atom 8 - system-on-a-chip designs based on the Parallel Trace 9 - Interface for MIPI P1149.7 cJTAG standard. The kernel solution 10 - for this platform involves the following files:: 11 - 12 - ./include/linux/pti.h 13 - ./drivers/.../n_tracesink.h 14 - ./drivers/.../n_tracerouter.c 15 - ./drivers/.../n_tracesink.c 16 - ./drivers/.../pti.c 17 - 18 - pti.c is the driver that enables various debugging features 19 - popular on platforms from certain mobile manufacturers. 20 - n_tracerouter.c and n_tracesink.c allow extra system information to 21 - be collected and routed to the pti driver, such as trace 22 - debugging data from a modem. Although n_tracerouter 23 - and n_tracesink are a part of the complete PTI solution, 24 - these two line disciplines can work separately from 25 - pti.c and route any data stream from one /dev/tty node 26 - to another /dev/tty node via kernel-space. This provides 27 - a stable, reliable connection that will not break unless 28 - the user-space application shuts down (plus avoids 29 - kernel->user->kernel context switch overheads of routing 30 - data). 31 - 32 - An example debugging usage for this driver system: 33 - 34 - * Hook /dev/ttyPTI0 to syslogd. Opening this port will also start 35 - a console device to further capture debugging messages to PTI. 36 - * Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW. 37 - This is where n_tracerouter and n_tracesink are used. 38 - * Hook /dev/pti to a user-level debugging application for writing 39 - to PTI HW. 40 - * `Use mipi_` Kernel Driver API in other device drivers for 41 - debugging to PTI by first requesting a PTI write address via 42 - mipi_request_masterchannel(1). 43 - 44 - Below is example pseudo-code on how a 'privileged' application 45 - can hook up n_tracerouter and n_tracesink to any tty on 46 - a system. 'Privileged' means the application has enough 47 - privileges to successfully manipulate the ldisc drivers 48 - but is not just blindly executing as 'root'. Keep in mind 49 - the use of ioctl(,TIOCSETD,) is not specific to the n_tracerouter 50 - and n_tracesink line discpline drivers but is a generic 51 - operation for a program to use a line discpline driver 52 - on a tty port other than the default n_tty: 53 - 54 - .. code-block:: c 55 - 56 - /////////// To hook up n_tracerouter and n_tracesink ///////// 57 - 58 - // Note that n_tracerouter depends on n_tracesink. 59 - #include <errno.h> 60 - #define ONE_TTY "/dev/ttyOne" 61 - #define TWO_TTY "/dev/ttyTwo" 62 - 63 - // needed global to hand onto ldisc connection 64 - static int g_fd_source = -1; 65 - static int g_fd_sink = -1; 66 - 67 - // these two vars used to grab LDISC values from loaded ldisc drivers 68 - // in OS. Look at /proc/tty/ldiscs to get the right numbers from 69 - // the ldiscs loaded in the system. 70 - int source_ldisc_num, sink_ldisc_num = -1; 71 - int retval; 72 - 73 - g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W 74 - g_fd_sink = open(TWO_TTY, O_RDWR); // must be R/W 75 - 76 - if (g_fd_source <= 0) || (g_fd_sink <= 0) { 77 - // doubt you'll want to use these exact error lines of code 78 - printf("Error on open(). errno: %d\n",errno); 79 - return errno; 80 - } 81 - 82 - retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num); 83 - if (retval < 0) { 84 - printf("Error on ioctl(). errno: %d\n", errno); 85 - return errno; 86 - } 87 - 88 - retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num); 89 - if (retval < 0) { 90 - printf("Error on ioctl(). errno: %d\n", errno); 91 - return errno; 92 - } 93 - 94 - /////////// To disconnect n_tracerouter and n_tracesink //////// 95 - 96 - // First make sure data through the ldiscs has stopped. 97 - 98 - // Second, disconnect ldiscs. This provides a 99 - // little cleaner shutdown on tty stack. 100 - sink_ldisc_num = 0; 101 - source_ldisc_num = 0; 102 - ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num); 103 - ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num); 104 - 105 - // Three, program closes connection, and cleanup: 106 - close(g_fd_uart); 107 - close(g_fd_gadget); 108 - g_fd_uart = g_fd_gadget = NULL;
-13
drivers/misc/Kconfig
··· 104 104 If you choose to build module, its name will be phantom. If unsure, 105 105 say N here. 106 106 107 - config INTEL_MID_PTI 108 - tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard" 109 - depends on PCI && TTY && (X86_INTEL_MID || COMPILE_TEST) 110 - help 111 - The PTI (Parallel Trace Interface) driver directs 112 - trace data routed from various parts in the system out 113 - through an Intel Penwell PTI port and out of the mobile 114 - device for analysis with a debugging tool (Lauterbach or Fido). 115 - 116 - You should select this driver if the target kernel is meant for 117 - an Intel Atom (non-netbook) mobile device containing a MIPI 118 - P1149.7 standard implementation. 119 - 120 107 config TIFM_CORE 121 108 tristate "TI Flash Media interface support" 122 109 depends on PCI
-1
drivers/misc/Makefile
··· 8 8 obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o 9 9 obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o 10 10 obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o 11 - obj-$(CONFIG_INTEL_MID_PTI) += pti.o 12 11 obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 13 12 obj-$(CONFIG_DUMMY_IRQ) += dummy-irq.o 14 13 obj-$(CONFIG_ICS932S401) += ics932s401.o
-978
drivers/misc/pti.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * pti.c - PTI driver for cJTAG data extration 4 - * 5 - * Copyright (C) Intel 2010 6 - * 7 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 - * 9 - * The PTI (Parallel Trace Interface) driver directs trace data routed from 10 - * various parts in the system out through the Intel Penwell PTI port and 11 - * out of the mobile device for analysis with a debugging tool 12 - * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7, 13 - * compact JTAG, standard. 14 - */ 15 - 16 - #include <linux/init.h> 17 - #include <linux/sched.h> 18 - #include <linux/interrupt.h> 19 - #include <linux/console.h> 20 - #include <linux/kernel.h> 21 - #include <linux/module.h> 22 - #include <linux/tty.h> 23 - #include <linux/tty_driver.h> 24 - #include <linux/pci.h> 25 - #include <linux/mutex.h> 26 - #include <linux/miscdevice.h> 27 - #include <linux/intel-pti.h> 28 - #include <linux/slab.h> 29 - #include <linux/uaccess.h> 30 - 31 - #define DRIVERNAME "pti" 32 - #define PCINAME "pciPTI" 33 - #define TTYNAME "ttyPTI" 34 - #define CHARNAME "pti" 35 - #define PTITTY_MINOR_START 0 36 - #define PTITTY_MINOR_NUM 2 37 - #define MAX_APP_IDS 16 /* 128 channel ids / u8 bit size */ 38 - #define MAX_OS_IDS 16 /* 128 channel ids / u8 bit size */ 39 - #define MAX_MODEM_IDS 16 /* 128 channel ids / u8 bit size */ 40 - #define MODEM_BASE_ID 71 /* modem master ID address */ 41 - #define CONTROL_ID 72 /* control master ID address */ 42 - #define CONSOLE_ID 73 /* console master ID address */ 43 - #define OS_BASE_ID 74 /* base OS master ID address */ 44 - #define APP_BASE_ID 80 /* base App master ID address */ 45 - #define CONTROL_FRAME_LEN 32 /* PTI control frame maximum size */ 46 - #define USER_COPY_SIZE 8192 /* 8Kb buffer for user space copy */ 47 - #define APERTURE_14 0x3800000 /* offset to first OS write addr */ 48 - #define APERTURE_LEN 0x400000 /* address length */ 49 - 50 - struct pti_tty { 51 - struct pti_masterchannel *mc; 52 - }; 53 - 54 - struct pti_dev { 55 - struct tty_port port[PTITTY_MINOR_NUM]; 56 - unsigned long pti_addr; 57 - unsigned long aperture_base; 58 - void __iomem *pti_ioaddr; 59 - u8 ia_app[MAX_APP_IDS]; 60 - u8 ia_os[MAX_OS_IDS]; 61 - u8 ia_modem[MAX_MODEM_IDS]; 62 - }; 63 - 64 - /* 65 - * This protects access to ia_app, ia_os, and ia_modem, 66 - * which keeps track of channels allocated in 67 - * an aperture write id. 68 - */ 69 - static DEFINE_MUTEX(alloclock); 70 - 71 - static const struct pci_device_id pci_ids[] = { 72 - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B)}, 73 - {0} 74 - }; 75 - 76 - static struct tty_driver *pti_tty_driver; 77 - static struct pti_dev *drv_data; 78 - 79 - static unsigned int pti_console_channel; 80 - static unsigned int pti_control_channel; 81 - 82 - /** 83 - * pti_write_to_aperture()- The private write function to PTI HW. 84 - * 85 - * @mc: The 'aperture'. It's part of a write address that holds 86 - * a master and channel ID. 87 - * @buf: Data being written to the HW that will ultimately be seen 88 - * in a debugging tool (Fido, Lauterbach). 89 - * @len: Size of buffer. 90 - * 91 - * Since each aperture is specified by a unique 92 - * master/channel ID, no two processes will be writing 93 - * to the same aperture at the same time so no lock is required. The 94 - * PTI-Output agent will send these out in the order that they arrived, and 95 - * thus, it will intermix these messages. The debug tool can then later 96 - * regroup the appropriate message segments together reconstituting each 97 - * message. 98 - */ 99 - static void pti_write_to_aperture(struct pti_masterchannel *mc, 100 - u8 *buf, 101 - int len) 102 - { 103 - int dwordcnt; 104 - int final; 105 - int i; 106 - u32 ptiword; 107 - u32 __iomem *aperture; 108 - u8 *p = buf; 109 - 110 - /* 111 - * calculate the aperture offset from the base using the master and 112 - * channel id's. 113 - */ 114 - aperture = drv_data->pti_ioaddr + (mc->master << 15) 115 - + (mc->channel << 8); 116 - 117 - dwordcnt = len >> 2; 118 - final = len - (dwordcnt << 2); /* final = trailing bytes */ 119 - if (final == 0 && dwordcnt != 0) { /* always need a final dword */ 120 - final += 4; 121 - dwordcnt--; 122 - } 123 - 124 - for (i = 0; i < dwordcnt; i++) { 125 - ptiword = be32_to_cpu(*(u32 *)p); 126 - p += 4; 127 - iowrite32(ptiword, aperture); 128 - } 129 - 130 - aperture += PTI_LASTDWORD_DTS; /* adding DTS signals that is EOM */ 131 - 132 - ptiword = 0; 133 - for (i = 0; i < final; i++) 134 - ptiword |= *p++ << (24-(8*i)); 135 - 136 - iowrite32(ptiword, aperture); 137 - return; 138 - } 139 - 140 - /** 141 - * pti_control_frame_built_and_sent()- control frame build and send function. 142 - * 143 - * @mc: The master / channel structure on which the function 144 - * built a control frame. 145 - * @thread_name: The thread name associated with the master / channel or 146 - * 'NULL' if using the 'current' global variable. 147 - * 148 - * To be able to post process the PTI contents on host side, a control frame 149 - * is added before sending any PTI content. So the host side knows on 150 - * each PTI frame the name of the thread using a dedicated master / channel. 151 - * The thread name is retrieved from 'current' global variable if 'thread_name' 152 - * is 'NULL', else it is retrieved from 'thread_name' parameter. 153 - * This function builds this frame and sends it to a master ID CONTROL_ID. 154 - * The overhead is only 32 bytes since the driver only writes to HW 155 - * in 32 byte chunks. 156 - */ 157 - static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc, 158 - const char *thread_name) 159 - { 160 - /* 161 - * Since we access the comm member in current's task_struct, we only 162 - * need to be as large as what 'comm' in that structure is. 163 - */ 164 - char comm[TASK_COMM_LEN]; 165 - struct pti_masterchannel mccontrol = {.master = CONTROL_ID, 166 - .channel = 0}; 167 - const char *thread_name_p; 168 - const char *control_format = "%3d %3d %s"; 169 - u8 control_frame[CONTROL_FRAME_LEN]; 170 - 171 - if (!thread_name) { 172 - if (!in_interrupt()) 173 - get_task_comm(comm, current); 174 - else 175 - strncpy(comm, "Interrupt", TASK_COMM_LEN); 176 - 177 - /* Absolutely ensure our buffer is zero terminated. */ 178 - comm[TASK_COMM_LEN-1] = 0; 179 - thread_name_p = comm; 180 - } else { 181 - thread_name_p = thread_name; 182 - } 183 - 184 - mccontrol.channel = pti_control_channel; 185 - pti_control_channel = (pti_control_channel + 1) & 0x7f; 186 - 187 - snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master, 188 - mc->channel, thread_name_p); 189 - pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame)); 190 - } 191 - 192 - /** 193 - * pti_write_full_frame_to_aperture()- high level function to 194 - * write to PTI. 195 - * 196 - * @mc: The 'aperture'. It's part of a write address that holds 197 - * a master and channel ID. 198 - * @buf: Data being written to the HW that will ultimately be seen 199 - * in a debugging tool (Fido, Lauterbach). 200 - * @len: Size of buffer. 201 - * 202 - * All threads sending data (either console, user space application, ...) 203 - * are calling the high level function to write to PTI meaning that it is 204 - * possible to add a control frame before sending the content. 205 - */ 206 - static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc, 207 - const unsigned char *buf, 208 - int len) 209 - { 210 - pti_control_frame_built_and_sent(mc, NULL); 211 - pti_write_to_aperture(mc, (u8 *)buf, len); 212 - } 213 - 214 - /** 215 - * get_id()- Allocate a master and channel ID. 216 - * 217 - * @id_array: an array of bits representing what channel 218 - * id's are allocated for writing. 219 - * @max_ids: The max amount of available write IDs to use. 220 - * @base_id: The starting SW channel ID, based on the Intel 221 - * PTI arch. 222 - * @thread_name: The thread name associated with the master / channel or 223 - * 'NULL' if using the 'current' global variable. 224 - * 225 - * Returns: 226 - * pti_masterchannel struct with master, channel ID address 227 - * 0 for error 228 - * 229 - * Each bit in the arrays ia_app and ia_os correspond to a master and 230 - * channel id. The bit is one if the id is taken and 0 if free. For 231 - * every master there are 128 channel id's. 232 - */ 233 - static struct pti_masterchannel *get_id(u8 *id_array, 234 - int max_ids, 235 - int base_id, 236 - const char *thread_name) 237 - { 238 - struct pti_masterchannel *mc; 239 - int i, j, mask; 240 - 241 - mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL); 242 - if (mc == NULL) 243 - return NULL; 244 - 245 - /* look for a byte with a free bit */ 246 - for (i = 0; i < max_ids; i++) 247 - if (id_array[i] != 0xff) 248 - break; 249 - if (i == max_ids) { 250 - kfree(mc); 251 - return NULL; 252 - } 253 - /* find the bit in the 128 possible channel opportunities */ 254 - mask = 0x80; 255 - for (j = 0; j < 8; j++) { 256 - if ((id_array[i] & mask) == 0) 257 - break; 258 - mask >>= 1; 259 - } 260 - 261 - /* grab it */ 262 - id_array[i] |= mask; 263 - mc->master = base_id; 264 - mc->channel = ((i & 0xf)<<3) + j; 265 - /* write new master Id / channel Id allocation to channel control */ 266 - pti_control_frame_built_and_sent(mc, thread_name); 267 - return mc; 268 - } 269 - 270 - /* 271 - * The following three functions: 272 - * pti_request_mastercahannel(), mipi_release_masterchannel() 273 - * and pti_writedata() are an API for other kernel drivers to 274 - * access PTI. 275 - */ 276 - 277 - /** 278 - * pti_request_masterchannel()- Kernel API function used to allocate 279 - * a master, channel ID address 280 - * to write to PTI HW. 281 - * 282 - * @type: 0- request Application master, channel aperture ID 283 - * write address. 284 - * 1- request OS master, channel aperture ID write 285 - * address. 286 - * 2- request Modem master, channel aperture ID 287 - * write address. 288 - * Other values, error. 289 - * @thread_name: The thread name associated with the master / channel or 290 - * 'NULL' if using the 'current' global variable. 291 - * 292 - * Returns: 293 - * pti_masterchannel struct 294 - * 0 for error 295 - */ 296 - struct pti_masterchannel *pti_request_masterchannel(u8 type, 297 - const char *thread_name) 298 - { 299 - struct pti_masterchannel *mc; 300 - 301 - mutex_lock(&alloclock); 302 - 303 - switch (type) { 304 - 305 - case 0: 306 - mc = get_id(drv_data->ia_app, MAX_APP_IDS, 307 - APP_BASE_ID, thread_name); 308 - break; 309 - 310 - case 1: 311 - mc = get_id(drv_data->ia_os, MAX_OS_IDS, 312 - OS_BASE_ID, thread_name); 313 - break; 314 - 315 - case 2: 316 - mc = get_id(drv_data->ia_modem, MAX_MODEM_IDS, 317 - MODEM_BASE_ID, thread_name); 318 - break; 319 - default: 320 - mc = NULL; 321 - } 322 - 323 - mutex_unlock(&alloclock); 324 - return mc; 325 - } 326 - EXPORT_SYMBOL_GPL(pti_request_masterchannel); 327 - 328 - /** 329 - * pti_release_masterchannel()- Kernel API function used to release 330 - * a master, channel ID address 331 - * used to write to PTI HW. 332 - * 333 - * @mc: master, channel apeture ID address to be released. This 334 - * will de-allocate the structure via kfree(). 335 - */ 336 - void pti_release_masterchannel(struct pti_masterchannel *mc) 337 - { 338 - u8 master, channel, i; 339 - 340 - mutex_lock(&alloclock); 341 - 342 - if (mc) { 343 - master = mc->master; 344 - channel = mc->channel; 345 - 346 - if (master == APP_BASE_ID) { 347 - i = channel >> 3; 348 - drv_data->ia_app[i] &= ~(0x80>>(channel & 0x7)); 349 - } else if (master == OS_BASE_ID) { 350 - i = channel >> 3; 351 - drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7)); 352 - } else { 353 - i = channel >> 3; 354 - drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7)); 355 - } 356 - 357 - kfree(mc); 358 - } 359 - 360 - mutex_unlock(&alloclock); 361 - } 362 - EXPORT_SYMBOL_GPL(pti_release_masterchannel); 363 - 364 - /** 365 - * pti_writedata()- Kernel API function used to write trace 366 - * debugging data to PTI HW. 367 - * 368 - * @mc: Master, channel aperture ID address to write to. 369 - * Null value will return with no write occurring. 370 - * @buf: Trace debuging data to write to the PTI HW. 371 - * Null value will return with no write occurring. 372 - * @count: Size of buf. Value of 0 or a negative number will 373 - * return with no write occuring. 374 - */ 375 - void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count) 376 - { 377 - /* 378 - * since this function is exported, this is treated like an 379 - * API function, thus, all parameters should 380 - * be checked for validity. 381 - */ 382 - if ((mc != NULL) && (buf != NULL) && (count > 0)) 383 - pti_write_to_aperture(mc, buf, count); 384 - return; 385 - } 386 - EXPORT_SYMBOL_GPL(pti_writedata); 387 - 388 - /* 389 - * for the tty_driver_*() basic function descriptions, see tty_driver.h. 390 - * Specific header comments made for PTI-related specifics. 391 - */ 392 - 393 - /** 394 - * pti_tty_driver_open()- Open an Application master, channel aperture 395 - * ID to the PTI device via tty device. 396 - * 397 - * @tty: tty interface. 398 - * @filp: filp interface pased to tty_port_open() call. 399 - * 400 - * Returns: 401 - * int, 0 for success 402 - * otherwise, fail value 403 - * 404 - * The main purpose of using the tty device interface is for 405 - * each tty port to have a unique PTI write aperture. In an 406 - * example use case, ttyPTI0 gets syslogd and an APP aperture 407 - * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route 408 - * modem messages into PTI. Modem trace data does not have to 409 - * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct 410 - * master IDs. These messages go through the PTI HW and out of 411 - * the handheld platform and to the Fido/Lauterbach device. 412 - */ 413 - static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp) 414 - { 415 - /* 416 - * we actually want to allocate a new channel per open, per 417 - * system arch. HW gives more than plenty channels for a single 418 - * system task to have its own channel to write trace data. This 419 - * also removes a locking requirement for the actual write 420 - * procedure. 421 - */ 422 - return tty_port_open(tty->port, tty, filp); 423 - } 424 - 425 - /** 426 - * pti_tty_driver_close()- close tty device and release Application 427 - * master, channel aperture ID to the PTI device via tty device. 428 - * 429 - * @tty: tty interface. 430 - * @filp: filp interface pased to tty_port_close() call. 431 - * 432 - * The main purpose of using the tty device interface is to route 433 - * syslog daemon messages to the PTI HW and out of the handheld platform 434 - * and to the Fido/Lauterbach device. 435 - */ 436 - static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp) 437 - { 438 - tty_port_close(tty->port, tty, filp); 439 - } 440 - 441 - /** 442 - * pti_tty_install()- Used to set up specific master-channels 443 - * to tty ports for organizational purposes when 444 - * tracing viewed from debuging tools. 445 - * 446 - * @driver: tty driver information. 447 - * @tty: tty struct containing pti information. 448 - * 449 - * Returns: 450 - * 0 for success 451 - * otherwise, error 452 - */ 453 - static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty) 454 - { 455 - int idx = tty->index; 456 - struct pti_tty *pti_tty_data; 457 - int ret = tty_standard_install(driver, tty); 458 - 459 - if (ret == 0) { 460 - pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL); 461 - if (pti_tty_data == NULL) 462 - return -ENOMEM; 463 - 464 - if (idx == PTITTY_MINOR_START) 465 - pti_tty_data->mc = pti_request_masterchannel(0, NULL); 466 - else 467 - pti_tty_data->mc = pti_request_masterchannel(2, NULL); 468 - 469 - if (pti_tty_data->mc == NULL) { 470 - kfree(pti_tty_data); 471 - return -ENXIO; 472 - } 473 - tty->driver_data = pti_tty_data; 474 - } 475 - 476 - return ret; 477 - } 478 - 479 - /** 480 - * pti_tty_cleanup()- Used to de-allocate master-channel resources 481 - * tied to tty's of this driver. 482 - * 483 - * @tty: tty struct containing pti information. 484 - */ 485 - static void pti_tty_cleanup(struct tty_struct *tty) 486 - { 487 - struct pti_tty *pti_tty_data = tty->driver_data; 488 - if (pti_tty_data == NULL) 489 - return; 490 - pti_release_masterchannel(pti_tty_data->mc); 491 - kfree(pti_tty_data); 492 - tty->driver_data = NULL; 493 - } 494 - 495 - /** 496 - * pti_tty_driver_write()- Write trace debugging data through the char 497 - * interface to the PTI HW. Part of the misc device implementation. 498 - * 499 - * @tty: tty struct containing pti information. 500 - * @buf: trace data to be written. 501 - * @len: # of byte to write. 502 - * 503 - * Returns: 504 - * int, # of bytes written 505 - * otherwise, error 506 - */ 507 - static int pti_tty_driver_write(struct tty_struct *tty, 508 - const unsigned char *buf, int len) 509 - { 510 - struct pti_tty *pti_tty_data = tty->driver_data; 511 - if ((pti_tty_data != NULL) && (pti_tty_data->mc != NULL)) { 512 - pti_write_to_aperture(pti_tty_data->mc, (u8 *)buf, len); 513 - return len; 514 - } 515 - /* 516 - * we can't write to the pti hardware if the private driver_data 517 - * and the mc address is not there. 518 - */ 519 - else 520 - return -EFAULT; 521 - } 522 - 523 - /** 524 - * pti_tty_write_room()- Always returns 2048. 525 - * 526 - * @tty: contains tty info of the pti driver. 527 - */ 528 - static int pti_tty_write_room(struct tty_struct *tty) 529 - { 530 - return 2048; 531 - } 532 - 533 - /** 534 - * pti_char_open()- Open an Application master, channel aperture 535 - * ID to the PTI device. Part of the misc device implementation. 536 - * 537 - * @inode: not used. 538 - * @filp: Output- will have a masterchannel struct set containing 539 - * the allocated application PTI aperture write address. 540 - * 541 - * Returns: 542 - * int, 0 for success 543 - * otherwise, a fail value 544 - */ 545 - static int pti_char_open(struct inode *inode, struct file *filp) 546 - { 547 - struct pti_masterchannel *mc; 548 - 549 - /* 550 - * We really do want to fail immediately if 551 - * pti_request_masterchannel() fails, 552 - * before assigning the value to filp->private_data. 553 - * Slightly easier to debug if this driver needs debugging. 554 - */ 555 - mc = pti_request_masterchannel(0, NULL); 556 - if (mc == NULL) 557 - return -ENOMEM; 558 - filp->private_data = mc; 559 - return 0; 560 - } 561 - 562 - /** 563 - * pti_char_release()- Close a char channel to the PTI device. Part 564 - * of the misc device implementation. 565 - * 566 - * @inode: Not used in this implementaiton. 567 - * @filp: Contains private_data that contains the master, channel 568 - * ID to be released by the PTI device. 569 - * 570 - * Returns: 571 - * always 0 572 - */ 573 - static int pti_char_release(struct inode *inode, struct file *filp) 574 - { 575 - pti_release_masterchannel(filp->private_data); 576 - filp->private_data = NULL; 577 - return 0; 578 - } 579 - 580 - /** 581 - * pti_char_write()- Write trace debugging data through the char 582 - * interface to the PTI HW. Part of the misc device implementation. 583 - * 584 - * @filp: Contains private data which is used to obtain 585 - * master, channel write ID. 586 - * @data: trace data to be written. 587 - * @len: # of byte to write. 588 - * @ppose: Not used in this function implementation. 589 - * 590 - * Returns: 591 - * int, # of bytes written 592 - * otherwise, error value 593 - * 594 - * Notes: From side discussions with Alan Cox and experimenting 595 - * with PTI debug HW like Nokia's Fido box and Lauterbach 596 - * devices, 8192 byte write buffer used by USER_COPY_SIZE was 597 - * deemed an appropriate size for this type of usage with 598 - * debugging HW. 599 - */ 600 - static ssize_t pti_char_write(struct file *filp, const char __user *data, 601 - size_t len, loff_t *ppose) 602 - { 603 - struct pti_masterchannel *mc; 604 - void *kbuf; 605 - const char __user *tmp; 606 - size_t size = USER_COPY_SIZE; 607 - size_t n = 0; 608 - 609 - tmp = data; 610 - mc = filp->private_data; 611 - 612 - kbuf = kmalloc(size, GFP_KERNEL); 613 - if (kbuf == NULL) { 614 - pr_err("%s(%d): buf allocation failed\n", 615 - __func__, __LINE__); 616 - return -ENOMEM; 617 - } 618 - 619 - do { 620 - if (len - n > USER_COPY_SIZE) 621 - size = USER_COPY_SIZE; 622 - else 623 - size = len - n; 624 - 625 - if (copy_from_user(kbuf, tmp, size)) { 626 - kfree(kbuf); 627 - return n ? n : -EFAULT; 628 - } 629 - 630 - pti_write_to_aperture(mc, kbuf, size); 631 - n += size; 632 - tmp += size; 633 - 634 - } while (len > n); 635 - 636 - kfree(kbuf); 637 - return len; 638 - } 639 - 640 - static const struct tty_operations pti_tty_driver_ops = { 641 - .open = pti_tty_driver_open, 642 - .close = pti_tty_driver_close, 643 - .write = pti_tty_driver_write, 644 - .write_room = pti_tty_write_room, 645 - .install = pti_tty_install, 646 - .cleanup = pti_tty_cleanup 647 - }; 648 - 649 - static const struct file_operations pti_char_driver_ops = { 650 - .owner = THIS_MODULE, 651 - .write = pti_char_write, 652 - .open = pti_char_open, 653 - .release = pti_char_release, 654 - }; 655 - 656 - static struct miscdevice pti_char_driver = { 657 - .minor = MISC_DYNAMIC_MINOR, 658 - .name = CHARNAME, 659 - .fops = &pti_char_driver_ops 660 - }; 661 - 662 - /** 663 - * pti_console_write()- Write to the console that has been acquired. 664 - * 665 - * @c: Not used in this implementaiton. 666 - * @buf: Data to be written. 667 - * @len: Length of buf. 668 - */ 669 - static void pti_console_write(struct console *c, const char *buf, unsigned len) 670 - { 671 - static struct pti_masterchannel mc = {.master = CONSOLE_ID, 672 - .channel = 0}; 673 - 674 - mc.channel = pti_console_channel; 675 - pti_console_channel = (pti_console_channel + 1) & 0x7f; 676 - 677 - pti_write_full_frame_to_aperture(&mc, buf, len); 678 - } 679 - 680 - /** 681 - * pti_console_device()- Return the driver tty structure and set the 682 - * associated index implementation. 683 - * 684 - * @c: Console device of the driver. 685 - * @index: index associated with c. 686 - * 687 - * Returns: 688 - * always value of pti_tty_driver structure when this function 689 - * is called. 690 - */ 691 - static struct tty_driver *pti_console_device(struct console *c, int *index) 692 - { 693 - *index = c->index; 694 - return pti_tty_driver; 695 - } 696 - 697 - /** 698 - * pti_console_setup()- Initialize console variables used by the driver. 699 - * 700 - * @c: Not used. 701 - * @opts: Not used. 702 - * 703 - * Returns: 704 - * always 0. 705 - */ 706 - static int pti_console_setup(struct console *c, char *opts) 707 - { 708 - pti_console_channel = 0; 709 - pti_control_channel = 0; 710 - return 0; 711 - } 712 - 713 - /* 714 - * pti_console struct, used to capture OS printk()'s and shift 715 - * out to the PTI device for debugging. This cannot be 716 - * enabled upon boot because of the possibility of eating 717 - * any serial console printk's (race condition discovered). 718 - * The console should be enabled upon when the tty port is 719 - * used for the first time. Since the primary purpose for 720 - * the tty port is to hook up syslog to it, the tty port 721 - * will be open for a really long time. 722 - */ 723 - static struct console pti_console = { 724 - .name = TTYNAME, 725 - .write = pti_console_write, 726 - .device = pti_console_device, 727 - .setup = pti_console_setup, 728 - .flags = CON_PRINTBUFFER, 729 - .index = 0, 730 - }; 731 - 732 - /** 733 - * pti_port_activate()- Used to start/initialize any items upon 734 - * first opening of tty_port(). 735 - * 736 - * @port: The tty port number of the PTI device. 737 - * @tty: The tty struct associated with this device. 738 - * 739 - * Returns: 740 - * always returns 0 741 - * 742 - * Notes: The primary purpose of the PTI tty port 0 is to hook 743 - * the syslog daemon to it; thus this port will be open for a 744 - * very long time. 745 - */ 746 - static int pti_port_activate(struct tty_port *port, struct tty_struct *tty) 747 - { 748 - if (port->tty->index == PTITTY_MINOR_START) 749 - console_start(&pti_console); 750 - return 0; 751 - } 752 - 753 - /** 754 - * pti_port_shutdown()- Used to stop/shutdown any items upon the 755 - * last tty port close. 756 - * 757 - * @port: The tty port number of the PTI device. 758 - * 759 - * Notes: The primary purpose of the PTI tty port 0 is to hook 760 - * the syslog daemon to it; thus this port will be open for a 761 - * very long time. 762 - */ 763 - static void pti_port_shutdown(struct tty_port *port) 764 - { 765 - if (port->tty->index == PTITTY_MINOR_START) 766 - console_stop(&pti_console); 767 - } 768 - 769 - static const struct tty_port_operations tty_port_ops = { 770 - .activate = pti_port_activate, 771 - .shutdown = pti_port_shutdown, 772 - }; 773 - 774 - /* 775 - * Note the _probe() call sets everything up and ties the char and tty 776 - * to successfully detecting the PTI device on the pci bus. 777 - */ 778 - 779 - /** 780 - * pti_pci_probe()- Used to detect pti on the pci bus and set 781 - * things up in the driver. 782 - * 783 - * @pdev: pci_dev struct values for pti. 784 - * @ent: pci_device_id struct for pti driver. 785 - * 786 - * Returns: 787 - * 0 for success 788 - * otherwise, error 789 - */ 790 - static int pti_pci_probe(struct pci_dev *pdev, 791 - const struct pci_device_id *ent) 792 - { 793 - unsigned int a; 794 - int retval; 795 - int pci_bar = 1; 796 - 797 - dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__, 798 - __func__, __LINE__, pdev->vendor, pdev->device); 799 - 800 - retval = misc_register(&pti_char_driver); 801 - if (retval) { 802 - pr_err("%s(%d): CHAR registration failed of pti driver\n", 803 - __func__, __LINE__); 804 - pr_err("%s(%d): Error value returned: %d\n", 805 - __func__, __LINE__, retval); 806 - goto err; 807 - } 808 - 809 - retval = pci_enable_device(pdev); 810 - if (retval != 0) { 811 - dev_err(&pdev->dev, 812 - "%s: pci_enable_device() returned error %d\n", 813 - __func__, retval); 814 - goto err_unreg_misc; 815 - } 816 - 817 - drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); 818 - if (drv_data == NULL) { 819 - retval = -ENOMEM; 820 - dev_err(&pdev->dev, 821 - "%s(%d): kmalloc() returned NULL memory.\n", 822 - __func__, __LINE__); 823 - goto err_disable_pci; 824 - } 825 - drv_data->pti_addr = pci_resource_start(pdev, pci_bar); 826 - 827 - retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev)); 828 - if (retval != 0) { 829 - dev_err(&pdev->dev, 830 - "%s(%d): pci_request_region() returned error %d\n", 831 - __func__, __LINE__, retval); 832 - goto err_free_dd; 833 - } 834 - drv_data->aperture_base = drv_data->pti_addr+APERTURE_14; 835 - drv_data->pti_ioaddr = 836 - ioremap((u32)drv_data->aperture_base, 837 - APERTURE_LEN); 838 - if (!drv_data->pti_ioaddr) { 839 - retval = -ENOMEM; 840 - goto err_rel_reg; 841 - } 842 - 843 - pci_set_drvdata(pdev, drv_data); 844 - 845 - for (a = 0; a < PTITTY_MINOR_NUM; a++) { 846 - struct tty_port *port = &drv_data->port[a]; 847 - tty_port_init(port); 848 - port->ops = &tty_port_ops; 849 - 850 - tty_port_register_device(port, pti_tty_driver, a, &pdev->dev); 851 - } 852 - 853 - register_console(&pti_console); 854 - 855 - return 0; 856 - err_rel_reg: 857 - pci_release_region(pdev, pci_bar); 858 - err_free_dd: 859 - kfree(drv_data); 860 - err_disable_pci: 861 - pci_disable_device(pdev); 862 - err_unreg_misc: 863 - misc_deregister(&pti_char_driver); 864 - err: 865 - return retval; 866 - } 867 - 868 - /** 869 - * pti_pci_remove()- Driver exit method to remove PTI from 870 - * PCI bus. 871 - * @pdev: variable containing pci info of PTI. 872 - */ 873 - static void pti_pci_remove(struct pci_dev *pdev) 874 - { 875 - struct pti_dev *drv_data = pci_get_drvdata(pdev); 876 - unsigned int a; 877 - 878 - unregister_console(&pti_console); 879 - 880 - for (a = 0; a < PTITTY_MINOR_NUM; a++) { 881 - tty_unregister_device(pti_tty_driver, a); 882 - tty_port_destroy(&drv_data->port[a]); 883 - } 884 - 885 - iounmap(drv_data->pti_ioaddr); 886 - kfree(drv_data); 887 - pci_release_region(pdev, 1); 888 - pci_disable_device(pdev); 889 - 890 - misc_deregister(&pti_char_driver); 891 - } 892 - 893 - static struct pci_driver pti_pci_driver = { 894 - .name = PCINAME, 895 - .id_table = pci_ids, 896 - .probe = pti_pci_probe, 897 - .remove = pti_pci_remove, 898 - }; 899 - 900 - /** 901 - * pti_init()- Overall entry/init call to the pti driver. 902 - * It starts the registration process with the kernel. 903 - * 904 - * Returns: 905 - * int __init, 0 for success 906 - * otherwise value is an error 907 - * 908 - */ 909 - static int __init pti_init(void) 910 - { 911 - int retval; 912 - 913 - /* First register module as tty device */ 914 - 915 - pti_tty_driver = alloc_tty_driver(PTITTY_MINOR_NUM); 916 - if (pti_tty_driver == NULL) { 917 - pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n", 918 - __func__, __LINE__); 919 - return -ENOMEM; 920 - } 921 - 922 - pti_tty_driver->driver_name = DRIVERNAME; 923 - pti_tty_driver->name = TTYNAME; 924 - pti_tty_driver->major = 0; 925 - pti_tty_driver->minor_start = PTITTY_MINOR_START; 926 - pti_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM; 927 - pti_tty_driver->subtype = SYSTEM_TYPE_SYSCONS; 928 - pti_tty_driver->flags = TTY_DRIVER_REAL_RAW | 929 - TTY_DRIVER_DYNAMIC_DEV; 930 - pti_tty_driver->init_termios = tty_std_termios; 931 - 932 - tty_set_operations(pti_tty_driver, &pti_tty_driver_ops); 933 - 934 - retval = tty_register_driver(pti_tty_driver); 935 - if (retval) { 936 - pr_err("%s(%d): TTY registration failed of pti driver\n", 937 - __func__, __LINE__); 938 - pr_err("%s(%d): Error value returned: %d\n", 939 - __func__, __LINE__, retval); 940 - 941 - goto put_tty; 942 - } 943 - 944 - retval = pci_register_driver(&pti_pci_driver); 945 - if (retval) { 946 - pr_err("%s(%d): PCI registration failed of pti driver\n", 947 - __func__, __LINE__); 948 - pr_err("%s(%d): Error value returned: %d\n", 949 - __func__, __LINE__, retval); 950 - goto unreg_tty; 951 - } 952 - 953 - return 0; 954 - unreg_tty: 955 - tty_unregister_driver(pti_tty_driver); 956 - put_tty: 957 - put_tty_driver(pti_tty_driver); 958 - pti_tty_driver = NULL; 959 - return retval; 960 - } 961 - 962 - /** 963 - * pti_exit()- Unregisters this module as a tty and pci driver. 964 - */ 965 - static void __exit pti_exit(void) 966 - { 967 - tty_unregister_driver(pti_tty_driver); 968 - pci_unregister_driver(&pti_pci_driver); 969 - put_tty_driver(pti_tty_driver); 970 - } 971 - 972 - module_init(pti_init); 973 - module_exit(pti_exit); 974 - 975 - MODULE_LICENSE("GPL"); 976 - MODULE_AUTHOR("Ken Mills, Jay Freyensee"); 977 - MODULE_DESCRIPTION("PTI Driver"); 978 -
-2
drivers/tty/Makefile
··· 9 9 obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o 10 10 obj-$(CONFIG_N_HDLC) += n_hdlc.o 11 11 obj-$(CONFIG_N_GSM) += n_gsm.o 12 - obj-$(CONFIG_TRACE_ROUTER) += n_tracerouter.o 13 - obj-$(CONFIG_TRACE_SINK) += n_tracesink.o 14 12 obj-$(CONFIG_R3964) += n_r3964.o 15 13 16 14 obj-y += vt/
-233
drivers/tty/n_tracerouter.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * n_tracerouter.c - Trace data router through tty space 4 - * 5 - * Copyright (C) Intel 2011 6 - * 7 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 - * 9 - * This trace router uses the Linux line discipline framework to route 10 - * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port. 11 - * The solution is not specific to a HW modem and this line disciple can 12 - * be used to route any stream of data in kernel space. 13 - * This is part of a solution for the P1149.7, compact JTAG, standard. 14 - */ 15 - 16 - #include <linux/init.h> 17 - #include <linux/kernel.h> 18 - #include <linux/module.h> 19 - #include <linux/types.h> 20 - #include <linux/ioctl.h> 21 - #include <linux/tty.h> 22 - #include <linux/tty_ldisc.h> 23 - #include <linux/errno.h> 24 - #include <linux/string.h> 25 - #include <linux/mutex.h> 26 - #include <linux/slab.h> 27 - #include <linux/bug.h> 28 - #include "n_tracesink.h" 29 - 30 - /* 31 - * Other ldisc drivers use 65536 which basically means, 32 - * 'I can always accept 64k' and flow control is off. 33 - * This number is deemed appropriate for this driver. 34 - */ 35 - #define RECEIVE_ROOM 65536 36 - #define DRIVERNAME "n_tracerouter" 37 - 38 - /* 39 - * struct to hold private configuration data for this ldisc. 40 - * opencalled is used to hold if this ldisc has been opened. 41 - * kref_tty holds the tty reference the ldisc sits on top of. 42 - */ 43 - struct tracerouter_data { 44 - u8 opencalled; 45 - struct tty_struct *kref_tty; 46 - }; 47 - static struct tracerouter_data *tr_data; 48 - 49 - /* lock for when tty reference is being used */ 50 - static DEFINE_MUTEX(routelock); 51 - 52 - /** 53 - * n_tracerouter_open() - Called when a tty is opened by a SW entity. 54 - * @tty: terminal device to the ldisc. 55 - * 56 - * Return: 57 - * 0 for success. 58 - * 59 - * Caveats: This should only be opened one time per SW entity. 60 - */ 61 - static int n_tracerouter_open(struct tty_struct *tty) 62 - { 63 - int retval = -EEXIST; 64 - 65 - mutex_lock(&routelock); 66 - if (tr_data->opencalled == 0) { 67 - 68 - tr_data->kref_tty = tty_kref_get(tty); 69 - if (tr_data->kref_tty == NULL) { 70 - retval = -EFAULT; 71 - } else { 72 - tr_data->opencalled = 1; 73 - tty->disc_data = tr_data; 74 - tty->receive_room = RECEIVE_ROOM; 75 - tty_driver_flush_buffer(tty); 76 - retval = 0; 77 - } 78 - } 79 - mutex_unlock(&routelock); 80 - return retval; 81 - } 82 - 83 - /** 84 - * n_tracerouter_close() - close connection 85 - * @tty: terminal device to the ldisc. 86 - * 87 - * Called when a software entity wants to close a connection. 88 - */ 89 - static void n_tracerouter_close(struct tty_struct *tty) 90 - { 91 - struct tracerouter_data *tptr = tty->disc_data; 92 - 93 - mutex_lock(&routelock); 94 - WARN_ON(tptr->kref_tty != tr_data->kref_tty); 95 - tty_driver_flush_buffer(tty); 96 - tty_kref_put(tr_data->kref_tty); 97 - tr_data->kref_tty = NULL; 98 - tr_data->opencalled = 0; 99 - tty->disc_data = NULL; 100 - mutex_unlock(&routelock); 101 - } 102 - 103 - /** 104 - * n_tracerouter_read() - read request from user space 105 - * @tty: terminal device passed into the ldisc. 106 - * @file: pointer to open file object. 107 - * @buf: pointer to the data buffer that gets eventually returned. 108 - * @nr: number of bytes of the data buffer that is returned. 109 - * 110 - * function that allows read() functionality in userspace. By default if this 111 - * is not implemented it returns -EIO. This module is functioning like a 112 - * router via n_tracerouter_receivebuf(), and there is no real requirement 113 - * to implement this function. However, an error return value other than 114 - * -EIO should be used just to show that there was an intent not to have 115 - * this function implemented. Return value based on read() man pages. 116 - * 117 - * Return: 118 - * -EINVAL 119 - */ 120 - static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file, 121 - unsigned char __user *buf, size_t nr) { 122 - return -EINVAL; 123 - } 124 - 125 - /** 126 - * n_tracerouter_write() - Function that allows write() in userspace. 127 - * @tty: terminal device passed into the ldisc. 128 - * @file: pointer to open file object. 129 - * @buf: pointer to the data buffer that gets eventually returned. 130 - * @nr: number of bytes of the data buffer that is returned. 131 - * 132 - * By default if this is not implemented, it returns -EIO. 133 - * This should not be implemented, ever, because 134 - * 1. this driver is functioning like a router via 135 - * n_tracerouter_receivebuf() 136 - * 2. No writes to HW will ever go through this line discpline driver. 137 - * However, an error return value other than -EIO should be used 138 - * just to show that there was an intent not to have this function 139 - * implemented. Return value based on write() man pages. 140 - * 141 - * Return: 142 - * -EINVAL 143 - */ 144 - static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file, 145 - const unsigned char *buf, size_t nr) { 146 - return -EINVAL; 147 - } 148 - 149 - /** 150 - * n_tracerouter_receivebuf() - Routing function for driver. 151 - * @tty: terminal device passed into the ldisc. It's assumed 152 - * tty will never be NULL. 153 - * @cp: buffer, block of characters to be eventually read by 154 - * someone, somewhere (user read() call or some kernel function). 155 - * @fp: flag buffer. 156 - * @count: number of characters (aka, bytes) in cp. 157 - * 158 - * This function takes the input buffer, cp, and passes it to 159 - * an external API function for processing. 160 - */ 161 - static void n_tracerouter_receivebuf(struct tty_struct *tty, 162 - const unsigned char *cp, 163 - char *fp, int count) 164 - { 165 - mutex_lock(&routelock); 166 - n_tracesink_datadrain((u8 *) cp, count); 167 - mutex_unlock(&routelock); 168 - } 169 - 170 - /* 171 - * Flush buffer is not impelemented as the ldisc has no internal buffering 172 - * so the tty_driver_flush_buffer() is sufficient for this driver's needs. 173 - */ 174 - 175 - static struct tty_ldisc_ops tty_ptirouter_ldisc = { 176 - .owner = THIS_MODULE, 177 - .magic = TTY_LDISC_MAGIC, 178 - .name = DRIVERNAME, 179 - .open = n_tracerouter_open, 180 - .close = n_tracerouter_close, 181 - .read = n_tracerouter_read, 182 - .write = n_tracerouter_write, 183 - .receive_buf = n_tracerouter_receivebuf 184 - }; 185 - 186 - /** 187 - * n_tracerouter_init - module initialisation 188 - * 189 - * Registers this module as a line discipline driver. 190 - * 191 - * Return: 192 - * 0 for success, any other value error. 193 - */ 194 - static int __init n_tracerouter_init(void) 195 - { 196 - int retval; 197 - 198 - tr_data = kzalloc(sizeof(struct tracerouter_data), GFP_KERNEL); 199 - if (tr_data == NULL) 200 - return -ENOMEM; 201 - 202 - 203 - /* Note N_TRACEROUTER is defined in linux/tty.h */ 204 - retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc); 205 - if (retval < 0) { 206 - pr_err("%s: Registration failed: %d\n", __func__, retval); 207 - kfree(tr_data); 208 - } 209 - return retval; 210 - } 211 - 212 - /** 213 - * n_tracerouter_exit - module unload 214 - * 215 - * Removes this module as a line discipline driver. 216 - */ 217 - static void __exit n_tracerouter_exit(void) 218 - { 219 - int retval = tty_unregister_ldisc(N_TRACEROUTER); 220 - 221 - if (retval < 0) 222 - pr_err("%s: Unregistration failed: %d\n", __func__, retval); 223 - else 224 - kfree(tr_data); 225 - } 226 - 227 - module_init(n_tracerouter_init); 228 - module_exit(n_tracerouter_exit); 229 - 230 - MODULE_LICENSE("GPL"); 231 - MODULE_AUTHOR("Jay Freyensee"); 232 - MODULE_ALIAS_LDISC(N_TRACEROUTER); 233 - MODULE_DESCRIPTION("Trace router ldisc driver");
-228
drivers/tty/n_tracesink.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * n_tracesink.c - Trace data router and sink path through tty space. 4 - * 5 - * Copyright (C) Intel 2011 6 - * 7 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 - * 9 - * The trace sink uses the Linux line discipline framework to receive 10 - * trace data coming from the PTI source line discipline driver 11 - * to a user-desired tty port, like USB. 12 - * This is to provide a way to extract modem trace data on 13 - * devices that do not have a PTI HW module, or just need modem 14 - * trace data to come out of a different HW output port. 15 - * This is part of a solution for the P1149.7, compact JTAG, standard. 16 - */ 17 - 18 - #include <linux/init.h> 19 - #include <linux/kernel.h> 20 - #include <linux/module.h> 21 - #include <linux/types.h> 22 - #include <linux/ioctl.h> 23 - #include <linux/tty.h> 24 - #include <linux/tty_ldisc.h> 25 - #include <linux/errno.h> 26 - #include <linux/string.h> 27 - #include <linux/bug.h> 28 - #include "n_tracesink.h" 29 - 30 - /* 31 - * Other ldisc drivers use 65536 which basically means, 32 - * 'I can always accept 64k' and flow control is off. 33 - * This number is deemed appropriate for this driver. 34 - */ 35 - #define RECEIVE_ROOM 65536 36 - #define DRIVERNAME "n_tracesink" 37 - 38 - /* 39 - * there is a quirk with this ldisc is he can write data 40 - * to a tty from anyone calling his kernel API, which 41 - * meets customer requirements in the drivers/misc/pti.c 42 - * project. So he needs to know when he can and cannot write when 43 - * the API is called. In theory, the API can be called 44 - * after an init() but before a successful open() which 45 - * would crash the system if tty is not checked. 46 - */ 47 - static struct tty_struct *this_tty; 48 - static DEFINE_MUTEX(writelock); 49 - 50 - /** 51 - * n_tracesink_open() - Called when a tty is opened by a SW entity. 52 - * @tty: terminal device to the ldisc. 53 - * 54 - * Return: 55 - * 0 for success, 56 - * -EFAULT = couldn't get a tty kref n_tracesink will sit 57 - * on top of 58 - * -EEXIST = open() called successfully once and it cannot 59 - * be called again. 60 - * 61 - * Caveats: open() should only be successful the first time a 62 - * SW entity calls it. 63 - */ 64 - static int n_tracesink_open(struct tty_struct *tty) 65 - { 66 - int retval = -EEXIST; 67 - 68 - mutex_lock(&writelock); 69 - if (this_tty == NULL) { 70 - this_tty = tty_kref_get(tty); 71 - if (this_tty == NULL) { 72 - retval = -EFAULT; 73 - } else { 74 - tty->disc_data = this_tty; 75 - tty_driver_flush_buffer(tty); 76 - retval = 0; 77 - } 78 - } 79 - mutex_unlock(&writelock); 80 - 81 - return retval; 82 - } 83 - 84 - /** 85 - * n_tracesink_close() - close connection 86 - * @tty: terminal device to the ldisc. 87 - * 88 - * Called when a software entity wants to close a connection. 89 - */ 90 - static void n_tracesink_close(struct tty_struct *tty) 91 - { 92 - mutex_lock(&writelock); 93 - tty_driver_flush_buffer(tty); 94 - tty_kref_put(this_tty); 95 - this_tty = NULL; 96 - tty->disc_data = NULL; 97 - mutex_unlock(&writelock); 98 - } 99 - 100 - /** 101 - * n_tracesink_read() - read request from user space 102 - * @tty: terminal device passed into the ldisc. 103 - * @file: pointer to open file object. 104 - * @buf: pointer to the data buffer that gets eventually returned. 105 - * @nr: number of bytes of the data buffer that is returned. 106 - * 107 - * function that allows read() functionality in userspace. By default if this 108 - * is not implemented it returns -EIO. This module is functioning like a 109 - * router via n_tracesink_receivebuf(), and there is no real requirement 110 - * to implement this function. However, an error return value other than 111 - * -EIO should be used just to show that there was an intent not to have 112 - * this function implemented. Return value based on read() man pages. 113 - * 114 - * Return: 115 - * -EINVAL 116 - */ 117 - static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file, 118 - unsigned char __user *buf, size_t nr) { 119 - return -EINVAL; 120 - } 121 - 122 - /** 123 - * n_tracesink_write() - Function that allows write() in userspace. 124 - * @tty: terminal device passed into the ldisc. 125 - * @file: pointer to open file object. 126 - * @buf: pointer to the data buffer that gets eventually returned. 127 - * @nr: number of bytes of the data buffer that is returned. 128 - * 129 - * By default if this is not implemented, it returns -EIO. 130 - * This should not be implemented, ever, because 131 - * 1. this driver is functioning like a router via 132 - * n_tracesink_receivebuf() 133 - * 2. No writes to HW will ever go through this line discpline driver. 134 - * However, an error return value other than -EIO should be used 135 - * just to show that there was an intent not to have this function 136 - * implemented. Return value based on write() man pages. 137 - * 138 - * Return: 139 - * -EINVAL 140 - */ 141 - static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file, 142 - const unsigned char *buf, size_t nr) { 143 - return -EINVAL; 144 - } 145 - 146 - /** 147 - * n_tracesink_datadrain() - Kernel API function used to route 148 - * trace debugging data to user-defined 149 - * port like USB. 150 - * 151 - * @buf: Trace debuging data buffer to write to tty target 152 - * port. Null value will return with no write occurring. 153 - * @count: Size of buf. Value of 0 or a negative number will 154 - * return with no write occuring. 155 - * 156 - * Caveat: If this line discipline does not set the tty it sits 157 - * on top of via an open() call, this API function will not 158 - * call the tty's write() call because it will have no pointer 159 - * to call the write(). 160 - */ 161 - void n_tracesink_datadrain(u8 *buf, int count) 162 - { 163 - mutex_lock(&writelock); 164 - 165 - if ((buf != NULL) && (count > 0) && (this_tty != NULL)) 166 - this_tty->ops->write(this_tty, buf, count); 167 - 168 - mutex_unlock(&writelock); 169 - } 170 - EXPORT_SYMBOL_GPL(n_tracesink_datadrain); 171 - 172 - /* 173 - * Flush buffer is not impelemented as the ldisc has no internal buffering 174 - * so the tty_driver_flush_buffer() is sufficient for this driver's needs. 175 - */ 176 - 177 - /* 178 - * tty_ldisc function operations for this driver. 179 - */ 180 - static struct tty_ldisc_ops tty_n_tracesink = { 181 - .owner = THIS_MODULE, 182 - .magic = TTY_LDISC_MAGIC, 183 - .name = DRIVERNAME, 184 - .open = n_tracesink_open, 185 - .close = n_tracesink_close, 186 - .read = n_tracesink_read, 187 - .write = n_tracesink_write 188 - }; 189 - 190 - /** 191 - * n_tracesink_init- module initialisation 192 - * 193 - * Registers this module as a line discipline driver. 194 - * 195 - * Return: 196 - * 0 for success, any other value error. 197 - */ 198 - static int __init n_tracesink_init(void) 199 - { 200 - /* Note N_TRACESINK is defined in linux/tty.h */ 201 - int retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink); 202 - 203 - if (retval < 0) 204 - pr_err("%s: Registration failed: %d\n", __func__, retval); 205 - 206 - return retval; 207 - } 208 - 209 - /** 210 - * n_tracesink_exit - module unload 211 - * 212 - * Removes this module as a line discipline driver. 213 - */ 214 - static void __exit n_tracesink_exit(void) 215 - { 216 - int retval = tty_unregister_ldisc(N_TRACESINK); 217 - 218 - if (retval < 0) 219 - pr_err("%s: Unregistration failed: %d\n", __func__, retval); 220 - } 221 - 222 - module_init(n_tracesink_init); 223 - module_exit(n_tracesink_exit); 224 - 225 - MODULE_LICENSE("GPL"); 226 - MODULE_AUTHOR("Jay Freyensee"); 227 - MODULE_ALIAS_LDISC(N_TRACESINK); 228 - MODULE_DESCRIPTION("Trace sink ldisc driver");
-26
drivers/tty/n_tracesink.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * n_tracesink.h - Kernel driver API to route trace data in kernel space. 4 - * 5 - * Copyright (C) Intel 2011 6 - * 7 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 - * 9 - * The PTI (Parallel Trace Interface) driver directs trace data routed from 10 - * various parts in the system out through the Intel Penwell PTI port and 11 - * out of the mobile device for analysis with a debugging tool 12 - * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7, 13 - * compact JTAG, standard. 14 - * 15 - * This header file is used by n_tracerouter to be able to send the 16 - * data of it's tty port to the tty port this module sits. This 17 - * mechanism can also be used independent of the PTI module. 18 - * 19 - */ 20 - 21 - #ifndef N_TRACESINK_H_ 22 - #define N_TRACESINK_H_ 23 - 24 - void n_tracesink_datadrain(u8 *buf, int count); 25 - 26 - #endif
-35
include/linux/intel-pti.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) Intel 2011 4 - * 5 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 - * 7 - * The PTI (Parallel Trace Interface) driver directs trace data routed from 8 - * various parts in the system out through the Intel Penwell PTI port and 9 - * out of the mobile device for analysis with a debugging tool 10 - * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7, 11 - * compact JTAG, standard. 12 - * 13 - * This header file will allow other parts of the OS to use the 14 - * interface to write out it's contents for debugging a mobile system. 15 - */ 16 - 17 - #ifndef LINUX_INTEL_PTI_H_ 18 - #define LINUX_INTEL_PTI_H_ 19 - 20 - /* offset for last dword of any PTI message. Part of MIPI P1149.7 */ 21 - #define PTI_LASTDWORD_DTS 0x30 22 - 23 - /* basic structure used as a write address to the PTI HW */ 24 - struct pti_masterchannel { 25 - u8 master; 26 - u8 channel; 27 - }; 28 - 29 - /* the following functions are defined in misc/pti.c */ 30 - void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count); 31 - struct pti_masterchannel *pti_request_masterchannel(u8 type, 32 - const char *thread_name); 33 - void pti_release_masterchannel(struct pti_masterchannel *mc); 34 - 35 - #endif /* LINUX_INTEL_PTI_H_ */