void tpm_attach(struct device *parent, struct device *self, void *aux) { struct tpm_softc *sc = (struct tpm_softc *)self; struct isa_attach_args *ia = aux; bus_addr_t iobase; bus_size_t size; int rv; if (tpm_legacy_probe(ia->ia_iot, ia->ia_iobase)) { sc->sc_bt = ia->ia_iot; iobase = ia->ia_iobase; size = ia->ia_iosize; sc->sc_batm = ia->ia_iot; sc->sc_init = tpm_legacy_init; sc->sc_start = tpm_legacy_start; sc->sc_read = tpm_legacy_read; sc->sc_write = tpm_legacy_write; sc->sc_end = tpm_legacy_end; } else { sc->sc_bt = ia->ia_memt; iobase = ia->ia_maddr; size = TPM_SIZE; sc->sc_init = tpm_tis12_init; sc->sc_start = tpm_tis12_start; sc->sc_read = tpm_tis12_read; sc->sc_write = tpm_tis12_write; sc->sc_end = tpm_tis12_end; } if (bus_space_map(sc->sc_bt, iobase, size, 0, &sc->sc_bh)) { printf(": cannot map registers\n"); return; } if ((rv = (sc->sc_init)(sc, ia->ia_irq, sc->sc_dev.dv_xname))) { bus_space_unmap(sc->sc_bt, sc->sc_bh, size); return; } /* * Only setup interrupt handler when we have a vector and the * chip is TIS 1.2 compliant. */ if (sc->sc_init == tpm_tis12_init && ia->ia_irq != IRQUNK && (sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, IPL_TTY, tpm_intr, sc, sc->sc_dev.dv_xname)) == NULL) { bus_space_unmap(sc->sc_bt, sc->sc_bh, TPM_SIZE); printf("%s: cannot establish interrupt\n", sc->sc_dev.dv_xname); return; } #ifdef __FreeBSD__ sc->sc_suspend = 0; #else sc->sc_suspend = PWR_RESUME; sc->sc_powerhook = powerhook_establish(tpm_powerhook, sc); #endif }
/* * OpenBSD specific code for probing and attaching TPM to device tree. */ int tpm_match(struct device *parent, void *match, void *aux) { struct isa_attach_args *ia = aux; struct cfdata *cf = match; bus_space_tag_t bt = ia->ia_memt; bus_space_handle_t bh; int rv; /* There can be only one. */ if (cf->cf_unit) return 0; if (tpm_legacy_probe(ia->ia_iot, ia->ia_iobase)) { ia->ia_iosize = 2; return 1; } if (ia->ia_maddr == -1) return 0; if (bus_space_map(bt, ia->ia_maddr, TPM_SIZE, 0, &bh)) return 0; if ((rv = tpm_tis12_probe(bt, bh))) { ia->ia_iosize = 0; ia->ia_msize = TPM_SIZE; } bus_space_unmap(bt, bh, TPM_SIZE); return rv; }
int tpm_attach(device_t dev) { struct tpm_softc *sc = device_get_softc(dev); int irq; sc->mem_rid = 0; sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE); if (sc->mem_res == NULL) return ENXIO; sc->sc_bt = rman_get_bustag(sc->mem_res); sc->sc_bh = rman_get_bushandle(sc->mem_res); sc->irq_rid = 0; sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE | RF_SHAREABLE); if (sc->irq_res != NULL) irq = rman_get_start(sc->irq_res); else irq = IRQUNK; /* In case PnP probe this may contain some initialization. */ tpm_tis12_probe(sc->sc_bt, sc->sc_bh); if (tpm_legacy_probe(sc->sc_bt, sc->sc_bh)) { sc->sc_init = tpm_legacy_init; sc->sc_start = tpm_legacy_start; sc->sc_read = tpm_legacy_read; sc->sc_write = tpm_legacy_write; sc->sc_end = tpm_legacy_end; } else { sc->sc_init = tpm_tis12_init; sc->sc_start = tpm_tis12_start; sc->sc_read = tpm_tis12_read; sc->sc_write = tpm_tis12_write; sc->sc_end = tpm_tis12_end; } printf("%s", device_get_name(dev)); if ((sc->sc_init)(sc, irq, "tpm")) { tpm_detach(dev); return ENXIO; } if (sc->sc_init == tpm_tis12_init && sc->irq_res != NULL && bus_setup_intr(dev, sc->irq_res, INTR_TYPE_TTY, NULL, tpm_intr, sc, &sc->intr_cookie) != 0) { tpm_detach(dev); printf(": cannot establish interrupt\n"); return 1; } sc->sc_cdev = make_dev(&tpm_cdevsw, device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "tpm"); sc->sc_cdev->si_drv1 = sc; return 0; }
static int tpm_isa_match(device_t parent, cfdata_t match, void *aux) { struct isa_attach_args *ia = aux; bus_space_tag_t bt = ia->ia_memt; bus_space_handle_t bh; int rv; /* There can be only one. */ if (tpm_cd.cd_devs && tpm_cd.cd_devs[0]) return 0; if (tpm_legacy_probe(ia->ia_iot, ia->ia_io[0].ir_addr)) { ia->ia_io[0].ir_size = 2; return 1; } if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM) return 0; /* XXX: integer locator sign extension */ if (bus_space_map(bt, (unsigned int)ia->ia_iomem[0].ir_addr, TPM_SIZE, 0, &bh)) return 0; if ((rv = tpm_tis12_probe(bt, bh))) { ia->ia_nio = 0; ia->ia_io[0].ir_size = 0; ia->ia_iomem[0].ir_size = TPM_SIZE; } ia->ia_ndrq = 0; bus_space_unmap(bt, bh, TPM_SIZE); return rv; }
static void tpm_isa_attach(device_t parent, device_t self, void *aux) { struct tpm_softc *sc = device_private(self); struct isa_attach_args *ia = aux; bus_addr_t iobase; bus_size_t size; int rv; sc->sc_dev = self; if (tpm_legacy_probe(ia->ia_iot, ia->ia_io[0].ir_addr)) { sc->sc_bt = ia->ia_iot; iobase = (unsigned int)ia->ia_io[0].ir_addr; size = ia->ia_io[0].ir_size; sc->sc_batm = ia->ia_iot; sc->sc_init = tpm_legacy_init; sc->sc_start = tpm_legacy_start; sc->sc_read = tpm_legacy_read; sc->sc_write = tpm_legacy_write; sc->sc_end = tpm_legacy_end; } else { sc->sc_bt = ia->ia_memt; iobase = (unsigned int)ia->ia_iomem[0].ir_addr; size = TPM_SIZE; sc->sc_init = tpm_tis12_init; sc->sc_start = tpm_tis12_start; sc->sc_read = tpm_tis12_read; sc->sc_write = tpm_tis12_write; sc->sc_end = tpm_tis12_end; } if (bus_space_map(sc->sc_bt, iobase, size, 0, &sc->sc_bh)) { aprint_error_dev(sc->sc_dev, "cannot map registers\n"); return; } if ((rv = (*sc->sc_init)(sc, ia->ia_irq[0].ir_irq, device_xname(sc->sc_dev))) != 0) { bus_space_unmap(sc->sc_bt, sc->sc_bh, size); return; } /* * Only setup interrupt handler when we have a vector and the * chip is TIS 1.2 compliant. */ if (sc->sc_init == tpm_tis12_init && ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ && (sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE, IPL_TTY, tpm_intr, sc)) == NULL) { bus_space_unmap(sc->sc_bt, sc->sc_bh, TPM_SIZE); aprint_error_dev(sc->sc_dev, "cannot establish interrupt\n"); return; } if (!pmf_device_register(sc->sc_dev, tpm_suspend, tpm_resume)) aprint_error_dev(sc->sc_dev, "Cannot set power mgmt handler\n"); }
static void tpm_acpi_attach(device_t parent, device_t self, void *aux) { struct tpm_softc *sc = device_private(self); struct acpi_attach_args *aa = aux; struct acpi_resources res; struct acpi_io *io; struct acpi_mem *mem; struct acpi_irq *irq; bus_addr_t base; bus_addr_t size; int rv, inum; sc->sc_dev = self; /* Parse our resources */ rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, &acpi_resource_parse_ops_default); if (ACPI_FAILURE(rv)) { aprint_error_dev(sc->sc_dev, "cannot parse resources %d\n", rv); return; } io = acpi_res_io(&res, 0); if (io && tpm_legacy_probe(aa->aa_iot, io->ar_base)) { sc->sc_bt = aa->aa_iot; base = io->ar_base; size = io->ar_length; sc->sc_batm = aa->aa_iot; sc->sc_init = tpm_legacy_init; sc->sc_start = tpm_legacy_start; sc->sc_read = tpm_legacy_read; sc->sc_write = tpm_legacy_write; sc->sc_end = tpm_legacy_end; mem = NULL; } else { mem = acpi_res_mem(&res, 0); if (mem == NULL) { aprint_error_dev(sc->sc_dev, "cannot find mem\n"); goto out; } if (mem->ar_length != TPM_SIZE) { aprint_error_dev(sc->sc_dev, "wrong size mem %u != %u\n", mem->ar_length, TPM_SIZE); goto out; } base = mem->ar_base; size = mem->ar_length; sc->sc_bt = aa->aa_memt; sc->sc_init = tpm_tis12_init; sc->sc_start = tpm_tis12_start; sc->sc_read = tpm_tis12_read; sc->sc_write = tpm_tis12_write; sc->sc_end = tpm_tis12_end; } if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) { aprint_error_dev(sc->sc_dev, "cannot map registers\n"); goto out; } if (mem && !tpm_tis12_probe(sc->sc_bt, sc->sc_bh)) { aprint_error_dev(sc->sc_dev, "1.2 probe failed\n"); goto out1; } irq = acpi_res_irq(&res, 0); if (irq == NULL) inum = -1; else inum = irq->ar_irq; if ((rv = (*sc->sc_init)(sc, inum, device_xname(sc->sc_dev))) != 0) aprint_error_dev(sc->sc_dev, "cannot init device %d\n", rv); goto out1; if (inum != -1 && (sc->sc_ih = isa_intr_establish(aa->aa_ic, irq->ar_irq, IST_EDGE, IPL_TTY, tpm_intr, sc)) == NULL) { aprint_error_dev(sc->sc_dev, "cannot establish interrupt\n"); goto out1; } if (!pmf_device_register(sc->sc_dev, tpm_suspend, tpm_resume)) aprint_error_dev(sc->sc_dev, "Cannot set power mgmt handler\n"); return; out1: bus_space_unmap(sc->sc_bt, sc->sc_bh, size); out: acpi_resource_cleanup(&res); }