Lines Matching +full:burst +full:- +full:read

3  * Copyright (c) 2009, 2010 Hans-Joerg Hoexer
49 #define IRQUNK -1
83 #define TPM_INTF_INT_LEVEL_LOW 0x0010 /* level-low ints supported */
84 #define TPM_INTF_INT_LEVEL_HIGH 0x0008 /* level-high ints supported */
85 #define TPM_INTF_LOCALITY_CHANGE_INT 0x0004 /* locality-change int (mb 1) */
95 #define TPM_STS_BMASK 0x00ffff00 /* ro io burst size */
128 ((struct tpm_softc *)dev->si_drv1)
206 sc->mem_rid = 0; in tpm_attach()
207 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, in tpm_attach()
209 if (sc->mem_res == NULL) in tpm_attach()
212 sc->sc_bt = rman_get_bustag(sc->mem_res); in tpm_attach()
213 sc->sc_bh = rman_get_bushandle(sc->mem_res); in tpm_attach()
215 sc->irq_rid = 0; in tpm_attach()
216 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, in tpm_attach()
218 if (sc->irq_res != NULL) in tpm_attach()
219 irq = rman_get_start(sc->irq_res); in tpm_attach()
224 tpm_tis12_probe(sc->sc_bt, sc->sc_bh); in tpm_attach()
226 if (tpm_legacy_probe(sc->sc_bt, sc->sc_bh)) { in tpm_attach()
227 sc->sc_init = tpm_legacy_init; in tpm_attach()
228 sc->sc_start = tpm_legacy_start; in tpm_attach()
229 sc->sc_read = tpm_legacy_read; in tpm_attach()
230 sc->sc_write = tpm_legacy_write; in tpm_attach()
231 sc->sc_end = tpm_legacy_end; in tpm_attach()
233 sc->sc_init = tpm_tis12_init; in tpm_attach()
234 sc->sc_start = tpm_tis12_start; in tpm_attach()
235 sc->sc_read = tpm_tis12_read; in tpm_attach()
236 sc->sc_write = tpm_tis12_write; in tpm_attach()
237 sc->sc_end = tpm_tis12_end; in tpm_attach()
241 if ((sc->sc_init)(sc, irq, "tpm")) { in tpm_attach()
246 if (sc->sc_init == tpm_tis12_init && sc->irq_res != NULL && in tpm_attach()
247 bus_setup_intr(dev, sc->irq_res, INTR_TYPE_TTY, NULL, in tpm_attach()
248 tpm_intr, sc, &sc->intr_cookie) != 0) { in tpm_attach()
254 sc->sc_cdev = make_dev(&tpm_cdevsw, device_get_unit(dev), in tpm_attach()
256 sc->sc_cdev->si_drv1 = sc; in tpm_attach()
266 if(sc->intr_cookie){ in tpm_detach()
267 bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie); in tpm_detach()
270 if(sc->mem_res){ in tpm_detach()
272 sc->mem_rid, sc->mem_res); in tpm_detach()
275 if(sc->irq_res){ in tpm_detach()
277 sc->irq_rid, sc->irq_res); in tpm_detach()
279 if(sc->sc_cdev){ in tpm_detach()
280 destroy_dev(sc->sc_cdev); in tpm_detach()
330 sc->sc_vector = IRQUNK; in tpm_tis12_irqinit()
335 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, in tpm_tis12_irqinit()
336 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE) & in tpm_tis12_irqinit()
338 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS, in tpm_tis12_irqinit()
339 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS)); in tpm_tis12_irqinit()
342 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_INT_VECTOR, irq); in tpm_tis12_irqinit()
343 sc->sc_vector = irq; in tpm_tis12_irqinit()
346 if (sc->sc_capabilities & TPM_INTF_INT_EDGE_RISING) in tpm_tis12_irqinit()
348 else if (sc->sc_capabilities & TPM_INTF_INT_LEVEL_HIGH) in tpm_tis12_irqinit()
352 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, r); in tpm_tis12_irqinit()
364 r = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTF_CAPABILITIES); in tpm_tis12_init()
373 sc->sc_capabilities = r; in tpm_tis12_init()
375 sc->sc_devid = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_ID); in tpm_tis12_init()
376 sc->sc_rev = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_REV); in tpm_tis12_init()
379 if (tpm_devs[i].devid == sc->sc_devid) in tpm_tis12_init()
383 printf(": %s rev 0x%x\n", tpm_devs[i].name, sc->sc_rev); in tpm_tis12_init()
385 printf(": device 0x%08x rev 0x%x\n", sc->sc_devid, sc->sc_rev); in tpm_tis12_init()
394 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, TPM_STS_CMD_READY); in tpm_tis12_init()
408 if ((bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS) & in tpm_request_locality()
413 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS, in tpm_request_locality()
418 while ((r = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS) & in tpm_request_locality()
420 (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY) && to--) { in tpm_request_locality()
421 rv = tsleep(sc->sc_init, PRIBIO | PCATCH, "tpm_locality", 1); in tpm_request_locality()
444 int burst, to, rv; in tpm_getburst() local
448 burst = 0; in tpm_getburst()
449 while (burst == 0 && to--) { in tpm_getburst()
451 * Burst count has to be read from bits 8 to 23 without in tpm_getburst()
455 burst = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS + 1); in tpm_getburst()
456 burst |= bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS + 2) in tpm_getburst()
459 printf("tpm_getburst: read %d\n", burst); in tpm_getburst()
461 if (burst) in tpm_getburst()
462 return burst; in tpm_getburst()
478 status = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS) & in tpm_status()
510 sc->sc_write(sc, &command, sizeof(command)); in tpm_suspend()
511 sc->sc_read(sc, &command, sizeof(command), NULL, TPM_HDRSIZE); in tpm_suspend()
513 printf("tpm_suspend: power down: %d -> %d\n", sc->sc_suspend, why); in tpm_suspend()
515 sc->sc_suspend = why; in tpm_suspend()
530 printf("tpm_resume: resume: %d -> %d\n", sc->sc_suspend, why); in tpm_resume()
532 sc->sc_suspend = why; in tpm_resume()
549 while (((sc->sc_stat = tpm_status(sc)) & mask) != mask && tmo--) { in tpm_waitfor_poll()
570 sc->sc_stat = tpm_status(sc); in tpm_waitfor_int()
571 if ((sc->sc_stat & mask) == mask) in tpm_waitfor_int()
576 * level (SPL_TTY) are disabled (see tpm{read,write} et al) and in tpm_waitfor_int()
579 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, in tpm_waitfor_int()
580 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE) | in tpm_waitfor_int()
582 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, in tpm_waitfor_int()
583 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE) | in tpm_waitfor_int()
590 sc->sc_stat = tpm_status(sc); in tpm_waitfor_int()
591 if ((sc->sc_stat & mask) == mask) { in tpm_waitfor_int()
608 sc->sc_stat = tpm_status(sc); in tpm_waitfor_int()
611 sc->sc_stat, TPM_STS_BITS); in tpm_waitfor_int()
613 if ((sc->sc_stat & mask) == mask) in tpm_waitfor_int()
617 out: bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, in tpm_waitfor_int()
618 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE) & in tpm_waitfor_int()
620 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, in tpm_waitfor_int()
621 bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE) & in tpm_waitfor_int()
648 if (sc->sc_vector != IRQUNK) { in tpm_waitfor()
660 if ((b & TPM_STS_DATA_AVAIL) && (sc->sc_capabilities & in tpm_waitfor()
666 if ((b & TPM_STS_VALID) && (sc->sc_capabilities & in tpm_waitfor()
699 if ((b & sc->sc_stat) == TPM_STS_VALID) { in tpm_waitfor()
706 if ((sc->sc_stat & b) != b) { in tpm_waitfor()
709 sc->sc_stat, TPM_STS_BITS, b, TPM_STS_BITS); in tpm_waitfor()
711 if (re-- && (b0 & TPM_STS_VALID)) { in tpm_waitfor()
712 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, in tpm_waitfor()
730 TPM_READ_TMO, sc->sc_read); in tpm_tis12_start()
738 sc->sc_stat = tpm_status(sc); in tpm_tis12_start()
739 if (sc->sc_stat & TPM_STS_CMD_READY) { in tpm_tis12_start()
741 printf("tpm_tis12_start: UIO_WRITE status %b\n", sc->sc_stat, in tpm_tis12_start()
752 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, TPM_STS_CMD_READY); in tpm_tis12_start()
754 sc->sc_write))) { in tpm_tis12_start()
782 TPM_READ_TMO, sc->sc_read))) in tpm_tis12_read()
788 printf("tpm_tis12_read: fetching %d, burst is %d\n", n, bcnt); in tpm_tis12_read()
790 for (; n--; len--) { in tpm_tis12_read()
791 *p++ = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_DATA); in tpm_tis12_read()
799 printf("tpm_tis12_read: read %zd bytes, len %d\n", cnt, len); in tpm_tis12_read()
823 while (cnt < len - 1) { in tpm_tis12_write()
824 for (r = tpm_getburst(sc); r > 0 && cnt < len - 1; r--) { in tpm_tis12_write()
825 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_DATA, *p++); in tpm_tis12_write()
830 printf("tpm_tis12_write: failed burst rv %d\n", rv); in tpm_tis12_write()
834 sc->sc_stat = tpm_status(sc); in tpm_tis12_write()
835 if (!(sc->sc_stat & TPM_STS_DATA_EXPECT)) { in tpm_tis12_write()
838 sc->sc_stat, TPM_STS_BITS); in tpm_tis12_write()
844 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_DATA, *p++); in tpm_tis12_write()
853 if ((sc->sc_stat & TPM_STS_DATA_EXPECT) != 0) { in tpm_tis12_write()
856 sc->sc_stat, TPM_STS_BITS); in tpm_tis12_write()
876 sc->sc_read))) in tpm_tis12_end()
880 sc->sc_stat = tpm_status(sc); in tpm_tis12_end()
881 if (!err && ((sc->sc_stat & TPM_STS_DATA_AVAIL) == TPM_STS_DATA_AVAIL)) { in tpm_tis12_end()
883 printf("tpm_tis12_end: read failed stat=%b\n", in tpm_tis12_end()
884 sc->sc_stat, TPM_STS_BITS); in tpm_tis12_end()
889 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, in tpm_tis12_end()
893 bus_space_write_1(sc->sc_bt, sc->sc_bh,TPM_ACCESS, in tpm_tis12_end()
897 sc->sc_stat = tpm_status(sc); in tpm_tis12_end()
898 if (!err && (sc->sc_stat & TPM_STS_DATA_EXPECT)) { in tpm_tis12_end()
901 sc->sc_stat, TPM_STS_BITS); in tpm_tis12_end()
906 bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, in tpm_tis12_end()
922 r = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS); in tpm_intr()
937 wakeup(sc->sc_write); in tpm_intr()
940 wakeup(sc->sc_read); in tpm_intr()
943 wakeup(sc->sc_init); in tpm_intr()
945 bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS, r); in tpm_intr()
950 /* Read single byte using legacy interface. */
977 if (!tpm_enabled || iobase == -1) in tpm_legacy_probe()
990 for (i = sizeof(id); i--; ) in tpm_legacy_probe()
1020 if ((i = bus_space_map(sc->sc_batm, tpm_enabled, 2, 0, &sc->sc_bahm))) { in tpm_legacy_init()
1026 for (i = sizeof(id); i--; ) in tpm_legacy_init()
1027 id[i] = tpm_legacy_in(sc->sc_bt, sc->sc_bh, TPM_ID + i); in tpm_legacy_init()
1047 while (((r = bus_space_read_1(sc->sc_batm, sc->sc_bahm, 1)) & in tpm_legacy_start()
1048 (TPM_LEGACY_BUSY|bits)) != bits && to--) { in tpm_legacy_start()
1070 for (p = buf; !rv && len > 0; len--) { in tpm_legacy_read()
1072 !(bus_space_read_1(sc->sc_batm, sc->sc_bahm, 1) & in tpm_legacy_read()
1074 if (!to--) in tpm_legacy_read()
1078 *p++ = bus_space_read_1(sc->sc_batm, sc->sc_bahm, 0); in tpm_legacy_read()
1092 for (p = buf, n = len; n--; DELAY(TPM_LEGACY_DELAY)) { in tpm_legacy_write()
1094 bus_space_write_1(sc->sc_batm, sc->sc_bahm, 1, in tpm_legacy_write()
1098 bus_space_write_1(sc->sc_batm, sc->sc_bahm, 0, *p++); in tpm_legacy_write()
1113 bus_space_write_1(sc->sc_batm, sc->sc_bahm, 1, TPM_LEGACY_ABRT); in tpm_legacy_end()
1118 while(((r = bus_space_read_1(sc->sc_batm, sc->sc_bahm, 1)) & in tpm_legacy_end()
1119 TPM_LEGACY_BUSY) && to--) { in tpm_legacy_end()
1144 if (sc->sc_flags & TPM_OPEN) in tpmopen()
1147 sc->sc_flags |= TPM_OPEN; in tpmopen()
1160 if (!(sc->sc_flags & TPM_OPEN)) in tpmclose()
1163 sc->sc_flags &= ~TPM_OPEN; in tpmclose()
1180 if ((rv = (sc->sc_start)(sc, UIO_READ))) { in tpmread()
1188 if ((rv = (sc->sc_read)(sc, buf, TPM_HDRSIZE, &cnt, 0))) { in tpmread()
1189 (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1196 printf("tpmread: len %d, io count %d\n", len, uio->uio_resid); in tpmread()
1198 if (len > uio->uio_resid) { in tpmread()
1200 (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1202 printf("tpmread: bad residual io count 0x%x\n", uio->uio_resid); in tpmread()
1210 (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1216 for (len -= cnt, p = buf, n = sizeof(buf); len > 0; p = buf, len -= n, in tpmread()
1222 if ((rv = (sc->sc_read)(sc, p, n, NULL, TPM_PARAM_SIZE))) { in tpmread()
1223 (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1228 if ((rv = uiomove((caddr_t)buf, p - buf, uio))) { in tpmread()
1229 (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1235 rv = (sc->sc_end)(sc, UIO_READ, rv); in tpmread()
1253 printf("tpmwrite: io count %d\n", uio->uio_resid); in tpmwrite()
1256 n = MIN(sizeof(buf), uio->uio_resid); in tpmwrite()
1262 if ((rv = (sc->sc_start)(sc, UIO_WRITE))) { in tpmwrite()
1267 if ((rv = (sc->sc_write(sc, buf, n)))) { in tpmwrite()
1272 rv = (sc->sc_end)(sc, UIO_WRITE, rv); in tpmwrite()