25 #include <linux/sched.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/tty.h>
32 #include <linux/pci.h>
36 #include <linux/slab.h>
39 #define DRIVERNAME "pti"
40 #define PCINAME "pciPTI"
41 #define TTYNAME "ttyPTI"
42 #define CHARNAME "pti"
43 #define PTITTY_MINOR_START 0
44 #define PTITTY_MINOR_NUM 2
45 #define MAX_APP_IDS 16
47 #define MAX_MODEM_IDS 16
48 #define MODEM_BASE_ID 71
52 #define APP_BASE_ID 80
53 #define CONTROL_FRAME_LEN 32
54 #define USER_COPY_SIZE 8192
55 #define APERTURE_14 0x3800000
56 #define APERTURE_LEN 0x400000
87 static unsigned int pti_console_channel;
88 static unsigned int pti_control_channel;
126 final = len - (dwordcnt << 2);
127 if (
final == 0 && dwordcnt != 0) {
132 for (i = 0; i < dwordcnt; i++) {
141 for (i = 0; i <
final; i++)
142 ptiword |= *p++ << (24-(8*i));
175 const char *thread_name_p;
176 const char *control_format =
"%3d %3d %s";
187 thread_name_p = comm;
192 mccontrol.
channel = pti_control_channel;
193 pti_control_channel = (pti_control_channel + 1) & 0x7f;
197 pti_write_to_aperture(&mccontrol, control_frame,
strlen(control_frame));
215 const unsigned char *buf,
218 pti_control_frame_built_and_sent(mc,
NULL);
219 pti_write_to_aperture(mc, (
u8 *)buf, len);
244 const char *thread_name)
254 for (i = 0; i < max_ids; i++)
255 if (id_array[i] != 0xff)
263 for (j = 0; j < 8; j++) {
264 if ((id_array[i] & mask) == 0)
274 pti_control_frame_built_and_sent(mc, thread_name);
305 const char *thread_name)
356 drv_data->
ia_app[
i] &= ~(0x80>>(channel & 0x7));
359 drv_data->
ia_os[
i] &= ~(0x80>>(channel & 0x7));
362 drv_data->
ia_modem[
i] &= ~(0x80>>(channel & 0x7));
390 if ((mc !=
NULL) && (buf !=
NULL) && (count > 0))
391 pti_write_to_aperture(mc, buf, count);
421 static int pti_tty_driver_open(
struct tty_struct *tty,
struct file *filp)
444 static void pti_tty_driver_close(
struct tty_struct *tty,
struct file *filp)
469 if (pti_tty_data ==
NULL)
477 if (pti_tty_data->
mc ==
NULL) {
493 static void pti_tty_cleanup(
struct tty_struct *tty)
496 if (pti_tty_data ==
NULL)
516 static int pti_tty_driver_write(
struct tty_struct *tty,
517 const unsigned char *buf,
int len)
520 if ((pti_tty_data !=
NULL) && (pti_tty_data->
mc !=
NULL)) {
521 pti_write_to_aperture(pti_tty_data->
mc, (
u8 *)buf, len);
537 static int pti_tty_write_room(
struct tty_struct *tty)
582 static int pti_char_release(
struct inode *inode,
struct file *filp)
609 static ssize_t pti_char_write(
struct file *filp,
const char __user *
data,
610 size_t len, loff_t *ppose)
623 pr_err(
"%s(%d): buf allocation failed\n",
639 pti_write_to_aperture(mc, kbuf, size);
650 .open = pti_tty_driver_open,
651 .close = pti_tty_driver_close,
652 .write = pti_tty_driver_write,
653 .write_room = pti_tty_write_room,
654 .install = pti_tty_install,
655 .cleanup = pti_tty_cleanup
660 .write = pti_char_write,
661 .open = pti_char_open,
662 .release = pti_char_release,
668 .fops = &pti_char_driver_ops
678 static void pti_console_write(
struct console *
c,
const char *buf,
unsigned len)
683 mc.
channel = pti_console_channel;
684 pti_console_channel = (pti_console_channel + 1) & 0x7f;
686 pti_write_full_frame_to_aperture(&mc, buf, len);
703 return pti_tty_driver;
715 static int pti_console_setup(
struct console *
c,
char *
opts)
717 pti_console_channel = 0;
718 pti_control_channel = 0;
732 static struct console pti_console = {
734 .write = pti_console_write,
735 .device = pti_console_device,
736 .setup = pti_console_setup,
772 static void pti_port_shutdown(
struct tty_port *port)
779 .activate = pti_port_activate,
780 .shutdown = pti_port_shutdown,
806 dev_dbg(&pdev->
dev,
"%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
811 pr_err(
"%s(%d): CHAR registration failed of pti driver\n",
813 pr_err(
"%s(%d): Error value returned: %d\n",
814 __func__, __LINE__, retval);
821 "%s: pci_enable_device() returned error %d\n",
826 drv_data = kzalloc(
sizeof(*drv_data),
GFP_KERNEL);
827 if (drv_data ==
NULL) {
830 "%s(%d): kmalloc() returned NULL memory.\n",
832 goto err_disable_pci;
839 "%s(%d): pci_request_region() returned error %d\n",
840 __func__, __LINE__, retval);
852 pci_set_drvdata(pdev, drv_data);
857 port->
ops = &tty_port_ops;
884 struct pti_dev *drv_data = pci_get_drvdata(pdev);
892 pci_set_drvdata(pdev,
NULL);
903 .probe = pti_pci_probe,
917 static int __init pti_init(
void)
924 if (pti_tty_driver ==
NULL) {
925 pr_err(
"%s(%d): Memory allocation failed for ptiTTY driver\n",
932 pti_tty_driver->
major = 0;
944 pr_err(
"%s(%d): TTY registration failed of pti driver\n",
946 pr_err(
"%s(%d): Error value returned: %d\n",
947 __func__, __LINE__, retval);
952 retval = pci_register_driver(&pti_pci_driver);
954 pr_err(
"%s(%d): PCI registration failed of pti driver\n",
956 pr_err(
"%s(%d): Error value returned: %d\n",
957 __func__, __LINE__, retval);
966 pti_tty_driver =
NULL;
973 static void __exit pti_exit(
void)