sio.c (85426) | sio.c (86912) |
---|---|
1/*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * | 1/*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sys/pc98/cbus/sio.c 85426 2001-10-24 18:30:05Z jlemon $ | 33 * $FreeBSD: head/sys/pc98/cbus/sio.c 86912 2001-11-26 12:29:53Z nyan $ |
34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91 35 * from: i386/isa sio.c,v 1.234 36 */ 37 38#include "opt_comconsole.h" 39#include "opt_compat.h" 40#include "opt_ddb.h" 41#include "opt_sio.h" | 34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91 35 * from: i386/isa sio.c,v 1.234 36 */ 37 38#include "opt_comconsole.h" 39#include "opt_compat.h" 40#include "opt_ddb.h" 41#include "opt_sio.h" |
42#include "card.h" 43#include "pci.h" | |
44 45/* 46 * Serial driver, based on 386BSD-0.1 com driver. 47 * Mostly rewritten to use pseudo-DMA. 48 * Works for National Semiconductor NS8250-NS16550AF UARTs. 49 * COM driver, based on HP dca driver. 50 * 51 * Changes for PC-Card integration: --- 57 unchanged lines hidden (view full) --- 109 */ 110/* 111 * Modified by Y.Takahashi of Kogakuin University. 112 */ 113/* 114 * modified for 8251(FIFO) by Seigo TANIMURA <tanimura@FreeBSD.org> 115 */ 116 | 42 43/* 44 * Serial driver, based on 386BSD-0.1 com driver. 45 * Mostly rewritten to use pseudo-DMA. 46 * Works for National Semiconductor NS8250-NS16550AF UARTs. 47 * COM driver, based on HP dca driver. 48 * 49 * Changes for PC-Card integration: --- 57 unchanged lines hidden (view full) --- 107 */ 108/* 109 * Modified by Y.Takahashi of Kogakuin University. 110 */ 111/* 112 * modified for 8251(FIFO) by Seigo TANIMURA <tanimura@FreeBSD.org> 113 */ 114 |
117#ifdef PC98 118#define COM_IF_INTERNAL 0x00 119#define COM_IF_PC9861K_1 0x01 120#define COM_IF_PC9861K_2 0x02 121#define COM_IF_IND_SS_1 0x03 122#define COM_IF_IND_SS_2 0x04 123#define COM_IF_PIO9032B_1 0x05 124#define COM_IF_PIO9032B_2 0x06 125#define COM_IF_B98_01_1 0x07 126#define COM_IF_B98_01_2 0x08 127#define COM_IF_END1 COM_IF_B98_01_2 128#define COM_IF_RSA98 0x10 /* same as COM_IF_NS16550 */ 129#define COM_IF_NS16550 0x11 130#define COM_IF_SECOND_CCU 0x12 /* same as COM_IF_NS16550 */ 131#define COM_IF_MC16550II 0x13 132#define COM_IF_MCRS98 0x14 /* same as COM_IF_MC16550II */ 133#define COM_IF_RSB3000 0x15 134#define COM_IF_RSB384 0x16 135#define COM_IF_MODEM_CARD 0x17 136#define COM_IF_RSA98III 0x18 137#define COM_IF_ESP98 0x19 138#define COM_IF_END2 COM_IF_ESP98 139#endif /* PC98 */ 140 | |
141#include <sys/param.h> 142#include <sys/systm.h> 143#include <sys/bus.h> 144#include <sys/conf.h> 145#include <sys/dkstat.h> 146#include <sys/fcntl.h> 147#include <sys/interrupt.h> 148#include <sys/kernel.h> --- 6 unchanged lines hidden (view full) --- 155#include <sys/sysctl.h> 156#include <sys/syslog.h> 157#include <sys/tty.h> 158#include <machine/bus.h> 159#include <sys/rman.h> 160#include <sys/timetc.h> 161#include <sys/timepps.h> 162 | 115#include <sys/param.h> 116#include <sys/systm.h> 117#include <sys/bus.h> 118#include <sys/conf.h> 119#include <sys/dkstat.h> 120#include <sys/fcntl.h> 121#include <sys/interrupt.h> 122#include <sys/kernel.h> --- 6 unchanged lines hidden (view full) --- 129#include <sys/sysctl.h> 130#include <sys/syslog.h> 131#include <sys/tty.h> 132#include <machine/bus.h> 133#include <sys/rman.h> 134#include <sys/timetc.h> 135#include <sys/timepps.h> 136 |
163#ifdef PC98 164#include <pc98/pc98/pc98.h> 165#include <pc98/pc98/pc98_machdep.h> 166#else 167#include <isa/isareg.h> 168#endif | |
169#include <isa/isavar.h> | 137#include <isa/isavar.h> |
170#if NPCI > 0 171#include <pci/pcireg.h> 172#include <pci/pcivar.h> 173#endif | |
174 175#include <machine/resource.h> 176 177#include <dev/sio/sioreg.h> | 138 139#include <machine/resource.h> 140 141#include <dev/sio/sioreg.h> |
142#include <dev/sio/siovar.h> |
|
178 | 143 |
144#ifdef PC98 145#include <pc98/pc98/pc98.h> 146#include <pc98/pc98/pc98_machdep.h> 147#endif 148 |
|
179#ifdef COM_ESP 180#include <dev/ic/esp.h> 181#endif 182#include <dev/ic/ns16550.h> 183#ifdef PC98 184#include <dev/ic/i8251.h> 185#include <dev/ic/rsa.h> 186#endif --- 207 unchanged lines hidden (view full) --- 394 u_char obuf1[256]; 395 u_char obuf2[256]; 396#endif 397}; 398 399#ifdef COM_ESP 400static int espattach __P((struct com_s *com, Port_t esp_port)); 401#endif | 149#ifdef COM_ESP 150#include <dev/ic/esp.h> 151#endif 152#include <dev/ic/ns16550.h> 153#ifdef PC98 154#include <dev/ic/i8251.h> 155#include <dev/ic/rsa.h> 156#endif --- 207 unchanged lines hidden (view full) --- 364 u_char obuf1[256]; 365 u_char obuf2[256]; 366#endif 367}; 368 369#ifdef COM_ESP 370static int espattach __P((struct com_s *com, Port_t esp_port)); 371#endif |
402static int sioattach __P((device_t dev, int rid)); 403static int sio_isa_attach __P((device_t dev)); | |
404 405static timeout_t siobusycheck; 406static timeout_t siodtrwakeup; 407static void comhardclose __P((struct com_s *com)); 408static void sioinput __P((struct com_s *com)); 409static void siointr1 __P((struct com_s *com)); 410static void siointr __P((void *arg)); 411static int commctl __P((struct com_s *com, int bits, int how)); 412static int comparam __P((struct tty *tp, struct termios *t)); 413static void siopoll __P((void *)); | 372 373static timeout_t siobusycheck; 374static timeout_t siodtrwakeup; 375static void comhardclose __P((struct com_s *com)); 376static void sioinput __P((struct com_s *com)); 377static void siointr1 __P((struct com_s *com)); 378static void siointr __P((void *arg)); 379static int commctl __P((struct com_s *com, int bits, int how)); 380static int comparam __P((struct tty *tp, struct termios *t)); 381static void siopoll __P((void *)); |
414static int sioprobe __P((device_t dev, int xrid)); 415static int sio_isa_probe __P((device_t dev)); | |
416static void siosettimeout __P((void)); 417static int siosetwater __P((struct com_s *com, speed_t speed)); 418static void comstart __P((struct tty *tp)); 419static void comstop __P((struct tty *tp, int rw)); 420static timeout_t comwakeup; 421static void disc_optim __P((struct tty *tp, struct termios *t, 422 struct com_s *com)); 423 | 382static void siosettimeout __P((void)); 383static int siosetwater __P((struct com_s *com, speed_t speed)); 384static void comstart __P((struct tty *tp)); 385static void comstop __P((struct tty *tp, int rw)); 386static timeout_t comwakeup; 387static void disc_optim __P((struct tty *tp, struct termios *t, 388 struct com_s *com)); 389 |
424#if NCARD > 0 425static int sio_pccard_attach __P((device_t dev)); 426static int sio_pccard_detach __P((device_t dev)); 427static int sio_pccard_probe __P((device_t dev)); 428#endif /* NCARD > 0 */ 429 430#if NPCI > 0 431static int sio_pci_attach __P((device_t dev)); 432static void sio_pci_kludge_unit __P((device_t dev)); 433static int sio_pci_probe __P((device_t dev)); 434#endif /* NPCI > 0 */ 435 436static char driver_name[] = "sio"; | 390char sio_driver_name[] = "sio"; |
437static struct mtx sio_lock; 438static int sio_inited; 439 440/* table and macro for fast conversion from a unit number to its com struct */ | 391static struct mtx sio_lock; 392static int sio_inited; 393 394/* table and macro for fast conversion from a unit number to its com struct */ |
441static devclass_t sio_devclass; | 395devclass_t sio_devclass; |
442#define com_addr(unit) ((struct com_s *) \ | 396#define com_addr(unit) ((struct com_s *) \ |
443 devclass_get_softc(sio_devclass, unit)) | 397 devclass_get_softc(sio_devclass, unit)) /* XXX */ |
444 | 398 |
445static device_method_t sio_isa_methods[] = { 446 /* Device interface */ 447 DEVMETHOD(device_probe, sio_isa_probe), 448 DEVMETHOD(device_attach, sio_isa_attach), 449 450 { 0, 0 } 451}; 452 453static driver_t sio_isa_driver = { 454 driver_name, 455 sio_isa_methods, 456 sizeof(struct com_s), 457}; 458 459#if NCARD > 0 460static device_method_t sio_pccard_methods[] = { 461 /* Device interface */ 462 DEVMETHOD(device_probe, sio_pccard_probe), 463 DEVMETHOD(device_attach, sio_pccard_attach), 464 DEVMETHOD(device_detach, sio_pccard_detach), 465 466 { 0, 0 } 467}; 468 469static driver_t sio_pccard_driver = { 470 driver_name, 471 sio_pccard_methods, 472 sizeof(struct com_s), 473}; 474#endif /* NCARD > 0 */ 475 476#if NPCI > 0 477static device_method_t sio_pci_methods[] = { 478 /* Device interface */ 479 DEVMETHOD(device_probe, sio_pci_probe), 480 DEVMETHOD(device_attach, sio_pci_attach), 481 482 { 0, 0 } 483}; 484 485static driver_t sio_pci_driver = { 486 driver_name, 487 sio_pci_methods, 488 sizeof(struct com_s), 489}; 490#endif /* NPCI > 0 */ 491 | |
492static d_open_t sioopen; 493static d_close_t sioclose; 494static d_read_t sioread; 495static d_write_t siowrite; 496static d_ioctl_t sioioctl; 497 498#define CDEV_MAJOR 28 499static struct cdevsw sio_cdevsw = { 500 /* open */ sioopen, 501 /* close */ sioclose, 502 /* read */ sioread, 503 /* write */ siowrite, 504 /* ioctl */ sioioctl, 505 /* poll */ ttypoll, 506 /* mmap */ nommap, 507 /* strategy */ nostrategy, | 399static d_open_t sioopen; 400static d_close_t sioclose; 401static d_read_t sioread; 402static d_write_t siowrite; 403static d_ioctl_t sioioctl; 404 405#define CDEV_MAJOR 28 406static struct cdevsw sio_cdevsw = { 407 /* open */ sioopen, 408 /* close */ sioclose, 409 /* read */ sioread, 410 /* write */ siowrite, 411 /* ioctl */ sioioctl, 412 /* poll */ ttypoll, 413 /* mmap */ nommap, 414 /* strategy */ nostrategy, |
508 /* name */ driver_name, | 415 /* name */ sio_driver_name, |
509 /* maj */ CDEV_MAJOR, 510 /* dump */ nodump, 511 /* psize */ nopsize, 512 /* flags */ D_TTY | D_KQFILTER, 513 /* kqfilter */ ttykqfilter, 514}; 515 516int comconsole = -1; --- 27 unchanged lines hidden (view full) --- 544#define COM_INT_DISABLE {int previpri; previpri=spltty(); 545#define COM_INT_ENABLE splx(previpri);} 546#define IEN_TxFLAG IEN_Tx 547 548#define COM_CARRIER_DETECT_EMULATE 0 549#define PC98_CHECK_MODEM_INTERVAL (hz/10) 550#define DCD_OFF_TOLERANCE 2 551#define DCD_ON_RECOGNITION 2 | 416 /* maj */ CDEV_MAJOR, 417 /* dump */ nodump, 418 /* psize */ nopsize, 419 /* flags */ D_TTY | D_KQFILTER, 420 /* kqfilter */ ttykqfilter, 421}; 422 423int comconsole = -1; --- 27 unchanged lines hidden (view full) --- 451#define COM_INT_DISABLE {int previpri; previpri=spltty(); 452#define COM_INT_ENABLE splx(previpri);} 453#define IEN_TxFLAG IEN_Tx 454 455#define COM_CARRIER_DETECT_EMULATE 0 456#define PC98_CHECK_MODEM_INTERVAL (hz/10) 457#define DCD_OFF_TOLERANCE 2 458#define DCD_ON_RECOGNITION 2 |
552#define GET_IFTYPE(flags) ((flags >> 24) & 0x1f) 553#define SET_IFTYPE(type) (type << 24) | |
554#define IS_8251(if_type) (!(if_type & 0x10)) 555#define COM1_EXT_CLOCK 0x40000 556 557static void commint __P((dev_t dev)); 558static void com_tiocm_set __P((struct com_s *com, int msr)); 559static void com_tiocm_bis __P((struct com_s *com, int msr)); 560static void com_tiocm_bic __P((struct com_s *com, int msr)); 561static int com_tiocm_get __P((struct com_s *com)); --- 275 unchanged lines hidden (view full) --- 837 {" (ESP98)", -1, -1, port_table_1, IO_COMSIZE, comspeedtab_mc16550}, 838}; 839#endif /* PC98 */ 840 841#ifdef COM_ESP 842#ifdef PC98 843 844/* XXX configure this properly. */ | 459#define IS_8251(if_type) (!(if_type & 0x10)) 460#define COM1_EXT_CLOCK 0x40000 461 462static void commint __P((dev_t dev)); 463static void com_tiocm_set __P((struct com_s *com, int msr)); 464static void com_tiocm_bis __P((struct com_s *com, int msr)); 465static void com_tiocm_bic __P((struct com_s *com, int msr)); 466static int com_tiocm_get __P((struct com_s *com)); --- 275 unchanged lines hidden (view full) --- 742 {" (ESP98)", -1, -1, port_table_1, IO_COMSIZE, comspeedtab_mc16550}, 743}; 744#endif /* PC98 */ 745 746#ifdef COM_ESP 747#ifdef PC98 748 749/* XXX configure this properly. */ |
750/* XXX quite broken for new-bus. */ |
|
845static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 }; 846static Port_t likely_esp_ports[] = { 0xc0d0, 0 }; 847 848#define ESP98_CMD1 (ESP_CMD1 * 0x100) 849#define ESP98_CMD2 (ESP_CMD2 * 0x100) 850#define ESP98_STATUS1 (ESP_STATUS1 * 0x100) 851#define ESP98_STATUS2 (ESP_STATUS2 * 0x100) 852 --- 61 unchanged lines hidden (view full) --- 914 splx(s); 915 } 916 return error; 917} 918 919SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW, 920 0, 0, sysctl_machdep_comdefaultrate, "I", ""); 921 | 751static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 }; 752static Port_t likely_esp_ports[] = { 0xc0d0, 0 }; 753 754#define ESP98_CMD1 (ESP_CMD1 * 0x100) 755#define ESP98_CMD2 (ESP_CMD2 * 0x100) 756#define ESP98_STATUS1 (ESP_STATUS1 * 0x100) 757#define ESP98_STATUS2 (ESP_STATUS2 * 0x100) 758 --- 61 unchanged lines hidden (view full) --- 820 splx(s); 821 } 822 return error; 823} 824 825SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW, 826 0, 0, sysctl_machdep_comdefaultrate, "I", ""); 827 |
922#define SET_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) | (bit)) 923#define CLR_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) & ~(bit)) 924 925#if NCARD > 0 926static int 927sio_pccard_probe(dev) 928 device_t dev; 929{ 930 /* Do not probe IRQ - pccard doesn't turn on the interrupt line */ 931 /* until bus_setup_intr */ 932#ifdef PC98 933 SET_FLAG(dev, COM_C_NOPROBE | SET_IFTYPE(COM_IF_MODEM_CARD)); 934#else 935 SET_FLAG(dev, COM_C_NOPROBE); 936#endif 937 938 return (sioprobe(dev, 0)); 939} 940 941static int 942sio_pccard_attach(dev) 943 device_t dev; 944{ 945 return (sioattach(dev, 0)); 946} 947 | |
948/* | 828/* |
949 * sio_detach - unload the driver and clear the table. | 829 * Unload the driver and clear the table. 830 * XXX this is mostly wrong. |
950 * XXX TODO: 951 * This is usually called when the card is ejected, but 952 * can be caused by a modunload of a controller driver. 953 * The idea is to reset the driver's view of the device 954 * and ensure that any driver entry points such as 955 * read and write do not hang. 956 */ | 831 * XXX TODO: 832 * This is usually called when the card is ejected, but 833 * can be caused by a modunload of a controller driver. 834 * The idea is to reset the driver's view of the device 835 * and ensure that any driver entry points such as 836 * read and write do not hang. 837 */ |
957static int 958sio_pccard_detach(dev) | 838int 839siodetach(dev) |
959 device_t dev; 960{ 961 struct com_s *com; 962 int i; 963 964 com = (struct com_s *) device_get_softc(dev); 965 if (com == NULL) { 966 device_printf(dev, "NULL com in siounload\n"); --- 13 unchanged lines hidden (view full) --- 980 (*linesw[com->tp->t_line].l_close)(com->tp, 0); 981 com->tp->t_gen++; 982 ttyclose(com->tp); 983 ttwakeup(com->tp); 984 ttwwakeup(com->tp); 985 } else { 986 if (com->ibuf != NULL) 987 free(com->ibuf, M_DEVBUF); | 840 device_t dev; 841{ 842 struct com_s *com; 843 int i; 844 845 com = (struct com_s *) device_get_softc(dev); 846 if (com == NULL) { 847 device_printf(dev, "NULL com in siounload\n"); --- 13 unchanged lines hidden (view full) --- 861 (*linesw[com->tp->t_line].l_close)(com->tp, 0); 862 com->tp->t_gen++; 863 ttyclose(com->tp); 864 ttwakeup(com->tp); 865 ttwwakeup(com->tp); 866 } else { 867 if (com->ibuf != NULL) 868 free(com->ibuf, M_DEVBUF); |
869 device_set_softc(dev, NULL); 870 free(com, M_DEVBUF); |
|
988 } | 871 } |
989 device_printf(dev, "unloaded\n"); | |
990 return (0); 991} | 872 return (0); 873} |
992#endif /* NCARD > 0 */ | |
993 | 874 |
994#if NPCI > 0 995struct pci_ids { 996 u_int32_t type; 997 const char *desc; 998 int rid; 999}; 1000 1001static struct pci_ids pci_ids[] = { 1002 { 0x100812b9, "3COM PCI FaxModem", 0x10 }, 1003 { 0x2000131f, "CyberSerial (1-port) 16550", 0x10 }, 1004 { 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 }, 1005 { 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 }, 1006 { 0x048011c1, "Lucent kermit based PCI Modem", 0x14 }, 1007 { 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 }, 1008 { 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 }, 1009 /* { 0xXXXXXXXX, "Xircom Cardbus modem", 0x10 }, */ 1010 { 0x00000000, NULL, 0 } 1011}; 1012 1013static int 1014sio_pci_attach(dev) | 875int 876sioprobe(dev, xrid, noprobe) |
1015 device_t dev; | 877 device_t dev; |
1016{ 1017 u_int32_t type; 1018 struct pci_ids *id; 1019 1020 type = pci_get_devid(dev); 1021 id = pci_ids; 1022 while (id->type && id->type != type) 1023 id++; 1024 if (id->desc == NULL) 1025 return (ENXIO); 1026 sio_pci_kludge_unit(dev); 1027 return (sioattach(dev, id->rid)); 1028} 1029 1030/* 1031 * Don't cut and paste this to other drivers. It is a horrible kludge 1032 * which will fail to work and also be unnecessary in future versions. 1033 */ 1034static void 1035sio_pci_kludge_unit(dev) 1036 device_t dev; 1037{ 1038 devclass_t dc; 1039 int err; 1040 int start; 1041 int unit; 1042 1043 unit = 0; 1044 start = 0; 1045 while (resource_int_value("sio", unit, "port", &start) == 0 && 1046 start > 0) 1047 unit++; 1048 if (device_get_unit(dev) < unit) { 1049 dc = device_get_devclass(dev); 1050 while (devclass_get_device(dc, unit)) 1051 unit++; 1052 device_printf(dev, "moving to sio%d\n", unit); 1053 err = device_set_unit(dev, unit); /* EVIL DO NOT COPY */ 1054 if (err) 1055 device_printf(dev, "error moving device %d\n", err); 1056 } 1057} 1058 1059static int 1060sio_pci_probe(dev) 1061 device_t dev; 1062{ 1063 u_int32_t type; 1064 struct pci_ids *id; 1065 1066 type = pci_get_devid(dev); 1067 id = pci_ids; 1068 while (id->type && id->type != type) 1069 id++; 1070 if (id->desc == NULL) 1071 return (ENXIO); 1072 device_set_desc(dev, id->desc); 1073 return (sioprobe(dev, id->rid)); 1074} 1075#endif /* NPCI > 0 */ 1076 1077static struct isa_pnp_id sio_ids[] = { 1078#ifdef PC98 1079 {0x0100e4a5, "RSA-98III"}, 1080#endif 1081 {0} 1082}; 1083 1084 1085 1086static int 1087sio_isa_probe(dev) 1088 device_t dev; 1089{ 1090#ifdef PC98 1091 int logical_id; 1092#endif 1093 /* Check isapnp ids */ 1094 if (ISA_PNP_PROBE(device_get_parent(dev), dev, sio_ids) == ENXIO) 1095 return (ENXIO); 1096#ifdef PC98 1097 logical_id = isa_get_logicalid(dev); 1098 if (logical_id == 0x0100e4a5) /* RSA-98III */ 1099 SET_FLAG(dev, SET_IFTYPE(COM_IF_RSA98III)); 1100#endif 1101 return (sioprobe(dev, 0)); 1102} 1103 1104static int 1105sioprobe(dev, xrid) 1106 device_t dev; | |
1107 int xrid; | 878 int xrid; |
879 int noprobe; |
|
1108{ 1109#if 0 1110 static bool_t already_init; 1111 device_t xdev; 1112#endif 1113 struct com_s *com; 1114 bool_t failures[10]; 1115 int fn; --- 46 unchanged lines hidden (view full) --- 1162 if_16550a_type[iod.if_type & 0x0f].iat, 1163 if_16550a_type[iod.if_type & 0x0f].iatsz) != 0) { 1164 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); 1165 return ENXIO; 1166 } 1167 } 1168#endif 1169 | 880{ 881#if 0 882 static bool_t already_init; 883 device_t xdev; 884#endif 885 struct com_s *com; 886 bool_t failures[10]; 887 int fn; --- 46 unchanged lines hidden (view full) --- 934 if_16550a_type[iod.if_type & 0x0f].iat, 935 if_16550a_type[iod.if_type & 0x0f].iatsz) != 0) { 936 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); 937 return ENXIO; 938 } 939 } 940#endif 941 |
1170 com = device_get_softc(dev); | 942 com = malloc(sizeof(*com), M_DEVBUF, M_NOWAIT | M_ZERO); 943 if (com == NULL) 944 return (ENOMEM); 945 device_set_softc(dev, com); |
1171 com->bst = rman_get_bustag(port); 1172 com->bsh = rman_get_bushandle(port); 1173 | 946 com->bst = rman_get_bustag(port); 947 com->bsh = rman_get_bushandle(port); 948 |
1174 if (atomic_cmpset_int(&sio_inited, 0, 1)) 1175 mtx_init(&sio_lock, driver_name, MTX_SPIN); | 949 while (sio_inited != 2) 950 if (atomic_cmpset_int(&sio_inited, 0, 1)) { 951 mtx_init(&sio_lock, sio_driver_name, (comconsole != -1) ? 952 MTX_SPIN | MTX_QUIET : MTX_SPIN); 953 atomic_store_rel_int(&sio_inited, 2); 954 } |
1176 1177#if 0 1178 /* 1179 * XXX this is broken - when we are first called, there are no 1180 * previously configured IO ports. We could hard code 1181 * 0x3f8, 0x2f8, 0x3e8, 0x2e8 etc but that's probably worse. 1182 * This code has been doing nothing since the conversion since 1183 * "count" is zero the first time around. --- 37 unchanged lines hidden (view full) --- 1221 already_init = TRUE; 1222 } 1223#endif 1224 1225 if (COM_LLCONSOLE(flags)) { 1226 printf("sio%d: reserved for low-level i/o\n", 1227 device_get_unit(dev)); 1228 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 955 956#if 0 957 /* 958 * XXX this is broken - when we are first called, there are no 959 * previously configured IO ports. We could hard code 960 * 0x3f8, 0x2f8, 0x3e8, 0x2e8 etc but that's probably worse. 961 * This code has been doing nothing since the conversion since 962 * "count" is zero the first time around. --- 37 unchanged lines hidden (view full) --- 1000 already_init = TRUE; 1001 } 1002#endif 1003 1004 if (COM_LLCONSOLE(flags)) { 1005 printf("sio%d: reserved for low-level i/o\n", 1006 device_get_unit(dev)); 1007 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1008 device_set_softc(dev, NULL); 1009 free(com, M_DEVBUF); |
|
1229 return (ENXIO); 1230 } 1231 1232#ifdef PC98 1233 DELAY(10); 1234 1235 /* 1236 * If the port is i8251 UART (internal, B98_01) 1237 */ 1238 if (pc98_check_if_type(dev, &iod) == -1) { 1239 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1010 return (ENXIO); 1011 } 1012 1013#ifdef PC98 1014 DELAY(10); 1015 1016 /* 1017 * If the port is i8251 UART (internal, B98_01) 1018 */ 1019 if (pc98_check_if_type(dev, &iod) == -1) { 1020 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1021 device_set_softc(dev, NULL); 1022 free(com, M_DEVBUF); |
|
1240 return (ENXIO); 1241 } 1242 if (iod.irq > 0) 1243 bus_set_resource(dev, SYS_RES_IRQ, 0, iod.irq, 1); 1244 if (IS_8251(iod.if_type)) { 1245 outb(iod.cmd, 0); 1246 DELAY(10); 1247 outb(iod.cmd, 0); --- 23 unchanged lines hidden (view full) --- 1271 * when being reset, so we can't check irq pending. 1272 */ 1273 result = 0; 1274 } 1275 if (epson_machine_id==0x20) { /* XXX */ 1276 result = 0; 1277 } 1278 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1023 return (ENXIO); 1024 } 1025 if (iod.irq > 0) 1026 bus_set_resource(dev, SYS_RES_IRQ, 0, iod.irq, 1); 1027 if (IS_8251(iod.if_type)) { 1028 outb(iod.cmd, 0); 1029 DELAY(10); 1030 outb(iod.cmd, 0); --- 23 unchanged lines hidden (view full) --- 1054 * when being reset, so we can't check irq pending. 1055 */ 1056 result = 0; 1057 } 1058 if (epson_machine_id==0x20) { /* XXX */ 1059 result = 0; 1060 } 1061 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1062 if (result) { 1063 device_set_softc(dev, NULL); 1064 free(com, M_DEVBUF); 1065 } |
|
1279 return result; 1280 } 1281#endif /* PC98 */ 1282 /* 1283 * If the device is on a multiport card and has an AST/4 1284 * compatible interrupt control register, initialize this 1285 * register and prepare to leave MCR_IENABLE clear in the mcr. 1286 * Otherwise, prepare to set MCR_IENABLE in the mcr. --- 40 unchanged lines hidden (view full) --- 1327#ifdef PC98 1328 if (iod.if_type == COM_IF_RSA98III) { 1329 mcr_image = 0; 1330 1331 outb(iobase + rsa_msr, 0x04); 1332 outb(iobase + rsa_frr, 0x00); 1333 if ((inb(iobase + rsa_srr) & 0x36) != 0x36) { 1334 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1066 return result; 1067 } 1068#endif /* PC98 */ 1069 /* 1070 * If the device is on a multiport card and has an AST/4 1071 * compatible interrupt control register, initialize this 1072 * register and prepare to leave MCR_IENABLE clear in the mcr. 1073 * Otherwise, prepare to set MCR_IENABLE in the mcr. --- 40 unchanged lines hidden (view full) --- 1114#ifdef PC98 1115 if (iod.if_type == COM_IF_RSA98III) { 1116 mcr_image = 0; 1117 1118 outb(iobase + rsa_msr, 0x04); 1119 outb(iobase + rsa_frr, 0x00); 1120 if ((inb(iobase + rsa_srr) & 0x36) != 0x36) { 1121 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1122 device_set_softc(dev, NULL); 1123 free(com, M_DEVBUF); |
|
1335 return (ENXIO); 1336 } 1337 outb(iobase + rsa_ier, 0x00); 1338 outb(iobase + rsa_frr, 0x00); 1339 outb(iobase + rsa_tivsr, 0x00); 1340 outb(iobase + rsa_tcr, 0x00); 1341 } 1342 --- 5 unchanged lines hidden (view full) --- 1348 case 3: irqout = 4; break; 1349 case 5: irqout = 5; break; 1350 case 6: irqout = 6; break; 1351 case 12: irqout = 7; break; 1352 default: 1353 printf("sio%d: irq configuration error\n", 1354 device_get_unit(dev)); 1355 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1124 return (ENXIO); 1125 } 1126 outb(iobase + rsa_ier, 0x00); 1127 outb(iobase + rsa_frr, 0x00); 1128 outb(iobase + rsa_tivsr, 0x00); 1129 outb(iobase + rsa_tcr, 0x00); 1130 } 1131 --- 5 unchanged lines hidden (view full) --- 1137 case 3: irqout = 4; break; 1138 case 5: irqout = 5; break; 1139 case 6: irqout = 6; break; 1140 case 12: irqout = 7; break; 1141 default: 1142 printf("sio%d: irq configuration error\n", 1143 device_get_unit(dev)); 1144 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1145 device_set_softc(dev, NULL); 1146 free(com, M_DEVBUF); |
|
1356 return (ENXIO); 1357 } 1358 outb((iobase & 0x00ff) | tmp, irqout); 1359 } 1360#endif 1361 1362 /* 1363 * We don't want to get actual interrupts, just masked ones. --- 83 unchanged lines hidden (view full) --- 1447 */ 1448/* EXTRA DELAY? */ 1449 sio_setreg(com, com_mcr, mcr_image); 1450 1451 /* 1452 * Some pcmcia cards have the "TXRDY bug", so we check everyone 1453 * for IIR_TXRDY implementation ( Palido 321s, DC-1S... ) 1454 */ | 1147 return (ENXIO); 1148 } 1149 outb((iobase & 0x00ff) | tmp, irqout); 1150 } 1151#endif 1152 1153 /* 1154 * We don't want to get actual interrupts, just masked ones. --- 83 unchanged lines hidden (view full) --- 1238 */ 1239/* EXTRA DELAY? */ 1240 sio_setreg(com, com_mcr, mcr_image); 1241 1242 /* 1243 * Some pcmcia cards have the "TXRDY bug", so we check everyone 1244 * for IIR_TXRDY implementation ( Palido 321s, DC-1S... ) 1245 */ |
1455 if (COM_NOPROBE(flags)) { | 1246 if (noprobe) { |
1456 /* Reading IIR register twice */ 1457 for (fn = 0; fn < 2; fn ++) { 1458 DELAY(10000); 1459 failures[6] = sio_getreg(com, com_iir); 1460 } 1461 /* Check IIR_TXRDY clear ? */ 1462 result = 0; 1463 if (failures[6] & IIR_TXRDY) { --- 10 unchanged lines hidden (view full) --- 1474 } else { 1475 /* OK. this is well-known guys */ 1476 CLR_FLAG(dev, COM_C_IIR_TXRDYBUG); 1477 } 1478 sio_setreg(com, com_ier, 0); 1479 sio_setreg(com, com_cfcr, CFCR_8BITS); 1480 mtx_unlock_spin(&sio_lock); 1481 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1247 /* Reading IIR register twice */ 1248 for (fn = 0; fn < 2; fn ++) { 1249 DELAY(10000); 1250 failures[6] = sio_getreg(com, com_iir); 1251 } 1252 /* Check IIR_TXRDY clear ? */ 1253 result = 0; 1254 if (failures[6] & IIR_TXRDY) { --- 10 unchanged lines hidden (view full) --- 1265 } else { 1266 /* OK. this is well-known guys */ 1267 CLR_FLAG(dev, COM_C_IIR_TXRDYBUG); 1268 } 1269 sio_setreg(com, com_ier, 0); 1270 sio_setreg(com, com_cfcr, CFCR_8BITS); 1271 mtx_unlock_spin(&sio_lock); 1272 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1482 return (iobase == siocniobase ? 0 : result); | 1273 if (iobase == siocniobase) 1274 result = 0; 1275 if (result != 0) { 1276 device_set_softc(dev, NULL); 1277 free(com, M_DEVBUF); 1278 } 1279 return (result); |
1483 } 1484 1485 /* 1486 * Check that 1487 * o the CFCR, IER and MCR in UART hold the values written to them 1488 * (the values happen to be all distinct - this is good for 1489 * avoiding false positive tests from bus echoes). 1490 * o an output interrupt is generated and its vector is correct. --- 68 unchanged lines hidden (view full) --- 1559 for (fn = 0; fn < sizeof failures; ++fn) 1560 if (failures[fn]) 1561 printf(" %d", fn); 1562 printf("\n"); 1563 } 1564 break; 1565 } 1566 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); | 1280 } 1281 1282 /* 1283 * Check that 1284 * o the CFCR, IER and MCR in UART hold the values written to them 1285 * (the values happen to be all distinct - this is good for 1286 * avoiding false positive tests from bus echoes). 1287 * o an output interrupt is generated and its vector is correct. --- 68 unchanged lines hidden (view full) --- 1356 for (fn = 0; fn < sizeof failures; ++fn) 1357 if (failures[fn]) 1358 printf(" %d", fn); 1359 printf("\n"); 1360 } 1361 break; 1362 } 1363 bus_release_resource(dev, SYS_RES_IOPORT, rid, port); |
1567 return (iobase == siocniobase ? 0 : result); | 1364 if (iobase == siocniobase) 1365 result = 0; 1366 if (result != 0) { 1367 device_set_softc(dev, NULL); 1368 free(com, M_DEVBUF); 1369 } 1370 return (result); |
1568} 1569 1570#ifdef COM_ESP 1571static int 1572espattach(com, esp_port) 1573 struct com_s *com; 1574 Port_t esp_port; 1575{ --- 67 unchanged lines hidden (view full) --- 1643 * Okay, we seem to be a Hayes ESP card. Whee. 1644 */ 1645 com->esp = TRUE; 1646 com->esp_port = esp_port; 1647 return (1); 1648} 1649#endif /* COM_ESP */ 1650 | 1371} 1372 1373#ifdef COM_ESP 1374static int 1375espattach(com, esp_port) 1376 struct com_s *com; 1377 Port_t esp_port; 1378{ --- 67 unchanged lines hidden (view full) --- 1446 * Okay, we seem to be a Hayes ESP card. Whee. 1447 */ 1448 com->esp = TRUE; 1449 com->esp_port = esp_port; 1450 return (1); 1451} 1452#endif /* COM_ESP */ 1453 |
1651static int 1652sio_isa_attach(dev) 1653 device_t dev; 1654{ 1655 return (sioattach(dev, 0)); 1656} 1657 1658static int | 1454int |
1659sioattach(dev, xrid) 1660 device_t dev; 1661 int xrid; 1662{ 1663 struct com_s *com; 1664#ifdef COM_ESP 1665 Port_t *espp; 1666#endif --- 2494 unchanged lines hidden (view full) --- 4161#ifdef __alpha__ 4162int siocnattach __P((int port, int speed)); 4163int siogdbattach __P((int port, int speed)); 4164int siogdbgetc __P((void)); 4165void siogdbputc __P((int c)); 4166#else 4167static cn_probe_t siocnprobe; 4168static cn_init_t siocninit; | 1455sioattach(dev, xrid) 1456 device_t dev; 1457 int xrid; 1458{ 1459 struct com_s *com; 1460#ifdef COM_ESP 1461 Port_t *espp; 1462#endif --- 2494 unchanged lines hidden (view full) --- 3957#ifdef __alpha__ 3958int siocnattach __P((int port, int speed)); 3959int siogdbattach __P((int port, int speed)); 3960int siogdbgetc __P((void)); 3961void siogdbputc __P((int c)); 3962#else 3963static cn_probe_t siocnprobe; 3964static cn_init_t siocninit; |
3965static cn_term_t siocnterm; |
|
4169#endif 4170static cn_checkc_t siocncheckc; 4171static cn_getc_t siocngetc; 4172static cn_putc_t siocnputc; 4173 4174#ifndef __alpha__ | 3966#endif 3967static cn_checkc_t siocncheckc; 3968static cn_getc_t siocngetc; 3969static cn_putc_t siocnputc; 3970 3971#ifndef __alpha__ |
4175CONS_DRIVER(sio, siocnprobe, siocninit, NULL, siocngetc, siocncheckc, | 3972CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc, |
4176 siocnputc, NULL); 4177#endif 4178 4179/* To get the GDB related variables */ 4180#if DDB > 0 4181#include <ddb/ddb.h> 4182#endif 4183 --- 235 unchanged lines hidden (view full) --- 4419 4420static void 4421siocninit(cp) 4422 struct consdev *cp; 4423{ 4424 comconsole = DEV_TO_UNIT(cp->cn_dev); 4425} 4426 | 3973 siocnputc, NULL); 3974#endif 3975 3976/* To get the GDB related variables */ 3977#if DDB > 0 3978#include <ddb/ddb.h> 3979#endif 3980 --- 235 unchanged lines hidden (view full) --- 4216 4217static void 4218siocninit(cp) 4219 struct consdev *cp; 4220{ 4221 comconsole = DEV_TO_UNIT(cp->cn_dev); 4222} 4223 |
4224static void 4225siocnterm(cp) 4226 struct consdev *cp; 4227{ 4228 comconsole = -1; 4229} 4230 |
|
4427#endif 4428 4429#ifdef __alpha__ 4430 4431CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL); 4432 4433int 4434siocnattach(port, speed) --- 187 unchanged lines hidden (view full) --- 4622 siocnopen(&sp, siogdbiobase, gdbdefaultrate); 4623 siocntxwait(siogdbiobase); 4624 outb(siogdbiobase + com_data, c); 4625 siocnclose(&sp, siogdbiobase); 4626 splx(s); 4627} 4628#endif 4629 | 4231#endif 4232 4233#ifdef __alpha__ 4234 4235CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL); 4236 4237int 4238siocnattach(port, speed) --- 187 unchanged lines hidden (view full) --- 4426 siocnopen(&sp, siogdbiobase, gdbdefaultrate); 4427 siocntxwait(siogdbiobase); 4428 outb(siogdbiobase + com_data, c); 4429 siocnclose(&sp, siogdbiobase); 4430 splx(s); 4431} 4432#endif 4433 |
4630DRIVER_MODULE(sio, isa, sio_isa_driver, sio_devclass, 0, 0); 4631#ifndef PC98 4632DRIVER_MODULE(sio, acpi, sio_isa_driver, sio_devclass, 0, 0); 4633#endif 4634#if NCARD > 0 4635DRIVER_MODULE(sio, pccard, sio_pccard_driver, sio_devclass, 0, 0); 4636#endif 4637#if NPCI > 0 4638DRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0); 4639DRIVER_MODULE(sio, cardbus, sio_pci_driver, sio_devclass, 0, 0); 4640#endif 4641 | |
4642#ifdef PC98 4643/* 4644 * pc98 local function 4645 */ 4646 4647static void 4648com_tiocm_set(struct com_s *com, int msr) 4649{ --- 598 unchanged lines hidden --- | 4434#ifdef PC98 4435/* 4436 * pc98 local function 4437 */ 4438 4439static void 4440com_tiocm_set(struct com_s *com, int msr) 4441{ --- 598 unchanged lines hidden --- |