Lines Matching +full:1 +full:- +full:port

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
11 * 1. Redistributions of source code must retain the above copyright
61 bool p_hasintr:1;
86 while (i < PUC_PCI_BARS && sc->sc_bar[i].b_rid != rid) in puc_get_bar()
89 return (&sc->sc_bar[i]); in puc_get_bar()
92 if (rid == -1) in puc_get_bar()
96 bar = puc_get_bar(sc, -1); in puc_get_bar()
99 bar->b_rid = rid; in puc_get_bar()
100 bar->b_type = SYS_RES_IOPORT; in puc_get_bar()
101 bar->b_res = bus_alloc_resource_any(sc->sc_dev, bar->b_type, in puc_get_bar()
102 &bar->b_rid, RF_ACTIVE); in puc_get_bar()
103 if (bar->b_res == NULL) { in puc_get_bar()
104 bar->b_rid = rid; in puc_get_bar()
105 bar->b_type = SYS_RES_MEMORY; in puc_get_bar()
106 bar->b_res = bus_alloc_resource_any(sc->sc_dev, bar->b_type, in puc_get_bar()
107 &bar->b_rid, RF_ACTIVE); in puc_get_bar()
108 if (bar->b_res == NULL) { in puc_get_bar()
109 bar->b_rid = -1; in puc_get_bar()
115 rm = (bar->b_type == SYS_RES_IOPORT) ? &sc->sc_ioport : &sc->sc_iomem; in puc_get_bar()
116 start = rman_get_start(bar->b_res); in puc_get_bar()
117 end = rman_get_end(bar->b_res); in puc_get_bar()
120 bus_release_resource(sc->sc_dev, bar->b_type, bar->b_rid, in puc_get_bar()
121 bar->b_res); in puc_get_bar()
122 bar->b_res = NULL; in puc_get_bar()
123 bar->b_rid = -1; in puc_get_bar()
133 struct puc_port *port; in puc_intr() local
140 while (1) { in puc_intr()
144 devs = sc->sc_serdevs; in puc_intr()
145 if (sc->sc_ilr == PUC_ILR_DIGI) { in puc_intr()
148 ilr = ~bus_read_1(sc->sc_port[idx].p_rres, 7); in puc_intr()
152 } else if (sc->sc_ilr == PUC_ILR_QUATECH) { in puc_intr()
157 * lead to false positives on 8-port boards. in puc_intr()
159 ilr = bus_read_1(sc->sc_port[0].p_rres, 7); in puc_intr()
160 if (ilr != (sc->sc_cfg_data & 0xff)) in puc_intr()
171 idx = 0, dev = 1UL; in puc_intr()
175 idx++, dev <<= 1; in puc_intr()
177 port = &sc->sc_port[idx]; in puc_intr()
178 port->p_ipend = SERDEV_IPEND(port->p_dev); in puc_intr()
179 ipend |= port->p_ipend; in puc_intr()
187 i++, isrc <<= 1; in puc_intr()
190 idx = 0, dev = 1UL; in puc_intr()
194 idx++, dev <<= 1; in puc_intr()
196 port = &sc->sc_port[idx]; in puc_intr()
197 if (!(port->p_ipend & isrc)) in puc_intr()
199 if (port->p_ihsrc[i] != NULL) in puc_intr()
200 (*port->p_ihsrc[i])(port->p_iharg); in puc_intr()
214 struct puc_port *port; in puc_bfe_attach() local
227 sc->sc_bar[idx].b_rid = -1; in puc_bfe_attach()
230 sc->sc_ioport.rm_type = RMAN_ARRAY; in puc_bfe_attach()
231 error = rman_init(&sc->sc_ioport); in puc_bfe_attach()
233 sc->sc_iomem.rm_type = RMAN_ARRAY; in puc_bfe_attach()
234 error = rman_init(&sc->sc_iomem); in puc_bfe_attach()
236 sc->sc_irq.rm_type = RMAN_ARRAY; in puc_bfe_attach()
237 error = rman_init(&sc->sc_irq); in puc_bfe_attach()
240 rman_fini(&sc->sc_iomem); in puc_bfe_attach()
242 rman_fini(&sc->sc_ioport); in puc_bfe_attach()
247 snprintf(buffer, sizeof(buffer), "%s I/O port mapping", in puc_bfe_attach()
249 sc->sc_ioport.rm_descr = strdup(buffer, M_PUC); in puc_bfe_attach()
252 sc->sc_iomem.rm_descr = strdup(buffer, M_PUC); in puc_bfe_attach()
253 snprintf(buffer, sizeof(buffer), "%s port numbers", in puc_bfe_attach()
255 sc->sc_irq.rm_descr = strdup(buffer, M_PUC); in puc_bfe_attach()
259 sc->sc_nports = (int)res; in puc_bfe_attach()
260 sc->sc_port = malloc(sc->sc_nports * sizeof(struct puc_port), in puc_bfe_attach()
263 error = rman_manage_region(&sc->sc_irq, 1, sc->sc_nports); in puc_bfe_attach()
271 for (idx = 0; idx < sc->sc_nports; idx++) { in puc_bfe_attach()
272 port = &sc->sc_port[idx]; in puc_bfe_attach()
273 port->p_nr = idx + 1; in puc_bfe_attach()
277 port->p_type = res; in puc_bfe_attach()
286 port->p_bar = bar; in puc_bfe_attach()
287 start = rman_get_start(bar->b_res); in puc_bfe_attach()
296 rm = (bar->b_type == SYS_RES_IOPORT) in puc_bfe_attach()
297 ? &sc->sc_ioport: &sc->sc_iomem; in puc_bfe_attach()
298 port->p_rres = rman_reserve_resource(rm, start + ofs, in puc_bfe_attach()
299 start + ofs + size - 1, size, 0, NULL); in puc_bfe_attach()
300 if (port->p_rres != NULL) { in puc_bfe_attach()
301 bsh = rman_get_bushandle(bar->b_res); in puc_bfe_attach()
302 bst = rman_get_bustag(bar->b_res); in puc_bfe_attach()
304 rman_set_bushandle(port->p_rres, bsh); in puc_bfe_attach()
305 rman_set_bustag(port->p_rres, bst); in puc_bfe_attach()
307 port->p_ires = rman_reserve_resource(&sc->sc_irq, port->p_nr, in puc_bfe_attach()
308 port->p_nr, 1, 0, NULL); in puc_bfe_attach()
309 if (port->p_ires == NULL) { in puc_bfe_attach()
316 port->p_rclk = res; in puc_bfe_attach()
318 port->p_dev = device_add_child(dev, NULL, DEVICE_UNIT_ANY); in puc_bfe_attach()
319 if (port->p_dev != NULL) in puc_bfe_attach()
320 device_set_ivars(port->p_dev, (void *)port); in puc_bfe_attach()
326 sc->sc_ilr = res; in puc_bfe_attach()
327 if (bootverbose && sc->sc_ilr != 0) in puc_bfe_attach()
330 sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->sc_irid, in puc_bfe_attach()
332 if (sc->sc_ires != NULL) { in puc_bfe_attach()
333 error = bus_setup_intr(dev, sc->sc_ires, in puc_bfe_attach()
334 INTR_TYPE_TTY, puc_intr, NULL, sc, &sc->sc_icookie); in puc_bfe_attach()
336 error = bus_setup_intr(dev, sc->sc_ires, in puc_bfe_attach()
338 (driver_intr_t *)puc_intr, sc, &sc->sc_icookie); in puc_bfe_attach()
340 sc->sc_fastintr = 1; in puc_bfe_attach()
344 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in puc_bfe_attach()
345 sc->sc_ires); in puc_bfe_attach()
346 sc->sc_ires = NULL; in puc_bfe_attach()
349 if (sc->sc_ires == NULL) { in puc_bfe_attach()
351 sc->sc_polled = 1; in puc_bfe_attach()
355 for (idx = 0; idx < sc->sc_nports; idx++) { in puc_bfe_attach()
356 port = &sc->sc_port[idx]; in puc_bfe_attach()
357 if (port->p_dev == NULL) in puc_bfe_attach()
359 error = device_probe_and_attach(port->p_dev); in puc_bfe_attach()
361 device_delete_child(dev, port->p_dev); in puc_bfe_attach()
362 port->p_dev = NULL; in puc_bfe_attach()
370 if (sc->sc_serdevs == 0UL) in puc_bfe_attach()
371 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in puc_bfe_attach()
377 for (idx = 0; idx < sc->sc_nports; idx++) { in puc_bfe_attach()
378 port = &sc->sc_port[idx]; in puc_bfe_attach()
379 if (port->p_rres != NULL) in puc_bfe_attach()
380 rman_release_resource(port->p_rres); in puc_bfe_attach()
381 if (port->p_ires != NULL) in puc_bfe_attach()
382 rman_release_resource(port->p_ires); in puc_bfe_attach()
385 bar = &sc->sc_bar[idx]; in puc_bfe_attach()
386 if (bar->b_res != NULL) in puc_bfe_attach()
387 bus_release_resource(sc->sc_dev, bar->b_type, in puc_bfe_attach()
388 bar->b_rid, bar->b_res); in puc_bfe_attach()
390 rman_fini(&sc->sc_irq); in puc_bfe_attach()
391 free(__DECONST(void *, sc->sc_irq.rm_descr), M_PUC); in puc_bfe_attach()
392 rman_fini(&sc->sc_iomem); in puc_bfe_attach()
393 free(__DECONST(void *, sc->sc_iomem.rm_descr), M_PUC); in puc_bfe_attach()
394 rman_fini(&sc->sc_ioport); in puc_bfe_attach()
395 free(__DECONST(void *, sc->sc_ioport.rm_descr), M_PUC); in puc_bfe_attach()
396 free(sc->sc_port, M_PUC); in puc_bfe_attach()
404 struct puc_port *port; in puc_bfe_detach() local
415 for (idx = 0; idx < sc->sc_nports; idx++) { in puc_bfe_detach()
416 port = &sc->sc_port[idx]; in puc_bfe_detach()
417 if (port->p_dev == NULL) in puc_bfe_detach()
419 if (port->p_rres != NULL) in puc_bfe_detach()
420 rman_release_resource(port->p_rres); in puc_bfe_detach()
421 if (port->p_ires != NULL) in puc_bfe_detach()
422 rman_release_resource(port->p_ires); in puc_bfe_detach()
425 if (sc->sc_serdevs != 0UL) in puc_bfe_detach()
426 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in puc_bfe_detach()
427 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, sc->sc_ires); in puc_bfe_detach()
430 bar = &sc->sc_bar[idx]; in puc_bfe_detach()
431 if (bar->b_res != NULL) in puc_bfe_detach()
432 bus_release_resource(sc->sc_dev, bar->b_type, in puc_bfe_detach()
433 bar->b_rid, bar->b_res); in puc_bfe_detach()
436 rman_fini(&sc->sc_irq); in puc_bfe_detach()
437 free(__DECONST(void *, sc->sc_irq.rm_descr), M_PUC); in puc_bfe_detach()
438 rman_fini(&sc->sc_iomem); in puc_bfe_detach()
439 free(__DECONST(void *, sc->sc_iomem.rm_descr), M_PUC); in puc_bfe_detach()
440 rman_fini(&sc->sc_ioport); in puc_bfe_detach()
441 free(__DECONST(void *, sc->sc_ioport.rm_descr), M_PUC); in puc_bfe_detach()
442 free(sc->sc_port, M_PUC); in puc_bfe_detach()
454 sc->sc_dev = dev; in puc_bfe_probe()
455 sc->sc_cfg = cfg; in puc_bfe_probe()
457 /* We don't attach to single-port serial cards. */ in puc_bfe_probe()
458 if (cfg->ports == PUC_PORT_1S || cfg->ports == PUC_PORT_1P) in puc_bfe_probe()
475 struct puc_port *port; in puc_bus_alloc_resource() local
487 port = device_get_ivars(child); in puc_bus_alloc_resource()
488 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_alloc_resource()
497 if (type == port->p_bar->b_type) in puc_bus_alloc_resource()
498 res = port->p_rres; in puc_bus_alloc_resource()
500 res = port->p_ires; in puc_bus_alloc_resource()
528 struct puc_port *port; in puc_bus_release_resource() local
538 port = device_get_ivars(child); in puc_bus_release_resource()
539 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_release_resource()
544 if (res == port->p_ires) { in puc_bus_release_resource()
545 if (port->p_hasintr) in puc_bus_release_resource()
547 } else if (res != port->p_rres) in puc_bus_release_resource()
562 struct puc_port *port; in puc_bus_get_resource() local
572 port = device_get_ivars(child); in puc_bus_get_resource()
573 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_get_resource()
575 if (type == port->p_bar->b_type) in puc_bus_get_resource()
576 res = port->p_rres; in puc_bus_get_resource()
578 res = port->p_ires; in puc_bus_get_resource()
589 *countp = rman_get_end(res) - start + 1; in puc_bus_get_resource()
597 struct puc_port *port; in puc_bus_setup_intr() local
611 port = device_get_ivars(child); in puc_bus_setup_intr()
612 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_setup_intr()
614 if (cookiep == NULL || res != port->p_ires) in puc_bus_setup_intr()
617 if (port->p_type == PUC_TYPE_SERIAL && ihand != NULL) in puc_bus_setup_intr()
619 if (rman_get_device(port->p_ires) != originator) in puc_bus_setup_intr()
623 * Have non-serdev ports handled by the bus implementation. It in puc_bus_setup_intr()
628 if (port->p_type == PUC_TYPE_SERIAL) { in puc_bus_setup_intr()
631 port->p_ihsrc[i] = SERDEV_IHAND(originator, isrc); in puc_bus_setup_intr()
632 if (port->p_ihsrc[i] != NULL) in puc_bus_setup_intr()
633 serdev = 1; in puc_bus_setup_intr()
634 i++, isrc <<= 1; in puc_bus_setup_intr()
639 sc->sc_ires, flags, filt, ihand, arg, cookiep)); in puc_bus_setup_intr()
641 sc->sc_serdevs |= 1UL << (port->p_nr - 1); in puc_bus_setup_intr()
643 port->p_hasintr = 1; in puc_bus_setup_intr()
644 port->p_iharg = arg; in puc_bus_setup_intr()
646 *cookiep = port; in puc_bus_setup_intr()
654 struct puc_port *port; in puc_bus_teardown_intr() local
668 port = device_get_ivars(child); in puc_bus_teardown_intr()
669 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_teardown_intr()
671 if (res != port->p_ires) in puc_bus_teardown_intr()
673 if (rman_get_device(port->p_ires) != originator) in puc_bus_teardown_intr()
676 if (!port->p_hasintr) in puc_bus_teardown_intr()
678 sc->sc_ires, cookie)); in puc_bus_teardown_intr()
680 if (cookie != port) in puc_bus_teardown_intr()
683 port->p_hasintr = 0; in puc_bus_teardown_intr()
684 port->p_iharg = NULL; in puc_bus_teardown_intr()
687 port->p_ihsrc[i] = NULL; in puc_bus_teardown_intr()
695 struct puc_port *port; in puc_bus_read_ivar() local
703 port = device_get_ivars(child); in puc_bus_read_ivar()
704 KASSERT(port != NULL, ("%s %d", __func__, __LINE__)); in puc_bus_read_ivar()
711 *result = port->p_rclk; in puc_bus_read_ivar()
714 *result = port->p_type; in puc_bus_read_ivar()
725 struct puc_port *port; in puc_bus_print_child() local
728 port = device_get_ivars(child); in puc_bus_print_child()
732 retval += printf(" at port %d", port->p_nr); in puc_bus_print_child()
741 struct puc_port *port; in puc_bus_child_location() local
743 port = device_get_ivars(child); in puc_bus_child_location()
744 sbuf_printf(sb, "port=%d", port->p_nr); in puc_bus_child_location()
751 struct puc_port *port; in puc_bus_child_pnpinfo() local
753 port = device_get_ivars(child); in puc_bus_child_pnpinfo()
754 sbuf_printf(sb, "type=%d", port->p_type); in puc_bus_child_pnpinfo()