Lines Matching +full:bus +full:- +full:addr

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
37 #include <sys/bus.h>
40 #include <machine/bus.h>
52 static int bhnd_erom_iores_map(struct bhnd_erom_io *eio, bhnd_addr_t addr,
55 bhnd_addr_t *addr, bhnd_size_t *size);
60 static int bhnd_erom_iobus_map(struct bhnd_erom_io *eio, bhnd_addr_t addr,
63 bhnd_addr_t *addr, bhnd_size_t *size);
76 int mapped_rid; /**< resource ID of current mapping, or -1 */
80 * Fetch the device enumeration parser class from all bhnd(4)-compatible drivers
84 * @param bus_devclass The bus device class to be queried for
85 * bhnd(4)-compatible drivers.
86 * @param eio An erom bus I/O instance, configured with a
87 * mapping of the first bus core.
94 * @retval non-NULL on success, the best available EROM class.
133 /* Probe the bus */ in bhnd_erom_probe_driver_classes()
162 * @param eio The bus I/O callbacks to use when reading the device
166 * @retval non-NULL success
181 printf("error initializing %s parser at %#jx: %d\n", cls->name, in bhnd_erom_alloc()
182 (uintmax_t)cid->enum_addr, error); in bhnd_erom_alloc()
194 * This may be used to initialize a caller-allocated erom instance state
204 * @param eio The bus I/O callbacks to use when reading the device
209 * @retval non-zero if an error occurs initializing the EROM parser,
221 if (kcls->size > esize) in bhnd_erom_init_static()
260 * @param eio A bus I/O instance, configured with a mapping
286 cid->chip_id = CHIPC_GET_BITS(idreg, CHIPC_ID_CHIP); in bhnd_erom_read_chipid()
287 cid->chip_pkg = CHIPC_GET_BITS(idreg, CHIPC_ID_PKG); in bhnd_erom_read_chipid()
288 cid->chip_rev = CHIPC_GET_BITS(idreg, CHIPC_ID_REV); in bhnd_erom_read_chipid()
289 cid->chip_type = CHIPC_GET_BITS(idreg, CHIPC_ID_BUS); in bhnd_erom_read_chipid()
290 cid->ncores = CHIPC_GET_BITS(idreg, CHIPC_ID_NUMCORE); in bhnd_erom_read_chipid()
293 if (BHND_CHIPTYPE_HAS_EROM(cid->chip_type)) { in bhnd_erom_read_chipid()
294 cid->enum_addr = bhnd_erom_io_read(eio, CHIPC_EROMPTR, 4); in bhnd_erom_read_chipid()
296 cid->enum_addr = cc_addr; in bhnd_erom_read_chipid()
301 cid->chip_caps = 0x0; in bhnd_erom_read_chipid()
304 cid->chip_caps |= BHND_CAP_BP64; in bhnd_erom_read_chipid()
307 cid->chip_caps |= BHND_CAP_PMU; in bhnd_erom_read_chipid()
313 * Attempt to map @p size bytes at @p addr, replacing any existing
317 * @param addr The address to be mapped.
318 * @param size The number of bytes to be mapped at @p addr.
321 * @retval non-zero if mapping @p addr otherwise fails, a regular
325 bhnd_erom_io_map(struct bhnd_erom_io *eio, bhnd_addr_t addr, bhnd_size_t size) in bhnd_erom_io_map() argument
327 return (eio->map(eio, addr, size)); in bhnd_erom_io_map()
334 * @param[out] addr The address mapped by @p eio.
335 * @param[out] size The number of bytes mapped at @p addr.
341 bhnd_erom_io_tell(struct bhnd_erom_io *eio, bhnd_addr_t *addr, in bhnd_erom_io_tell() argument
344 return (eio->tell(eio, addr, size)); in bhnd_erom_io_tell()
358 return (eio->read(eio, offset, width)); in bhnd_erom_io_read()
367 if (eio->fini != NULL) in bhnd_erom_io_fini()
368 return (eio->fini(eio)); in bhnd_erom_io_fini()
385 iores->eio.map = bhnd_erom_iores_map; in bhnd_erom_iores_new()
386 iores->eio.tell = bhnd_erom_iores_tell; in bhnd_erom_iores_new()
387 iores->eio.read = bhnd_erom_iores_read; in bhnd_erom_iores_new()
388 iores->eio.fini = bhnd_erom_iores_fini; in bhnd_erom_iores_new()
390 iores->owner = dev; in bhnd_erom_iores_new()
391 iores->owner_rid = rid; in bhnd_erom_iores_new()
392 iores->mapped = NULL; in bhnd_erom_iores_new()
393 iores->mapped_rid = -1; in bhnd_erom_iores_new()
395 return (&iores->eio); in bhnd_erom_iores_new()
399 bhnd_erom_iores_map(struct bhnd_erom_io *eio, bhnd_addr_t addr, in bhnd_erom_iores_map() argument
406 /* Sanity check the addr/size */ in bhnd_erom_iores_map()
410 if (BHND_ADDR_MAX - size < addr) in bhnd_erom_iores_map()
414 if (iores->mapped) { in bhnd_erom_iores_map()
416 if (rman_get_start(iores->mapped->res) == addr && in bhnd_erom_iores_map()
417 rman_get_size(iores->mapped->res) == size) in bhnd_erom_iores_map()
423 bhnd_release_resource(iores->owner, SYS_RES_MEMORY, in bhnd_erom_iores_map()
424 iores->mapped_rid, iores->mapped); in bhnd_erom_iores_map()
425 iores->mapped = NULL; in bhnd_erom_iores_map()
426 iores->mapped_rid = -1; in bhnd_erom_iores_map()
430 iores->mapped_rid = iores->owner_rid; in bhnd_erom_iores_map()
431 iores->mapped = bhnd_alloc_resource(iores->owner, SYS_RES_MEMORY, in bhnd_erom_iores_map()
432 &iores->mapped_rid, addr, addr+size-1, size, in bhnd_erom_iores_map()
434 if (iores->mapped == NULL) { in bhnd_erom_iores_map()
435 iores->mapped_rid = -1; in bhnd_erom_iores_map()
443 bhnd_erom_iores_tell(struct bhnd_erom_io *eio, bhnd_addr_t *addr, in bhnd_erom_iores_tell() argument
448 if (iores->mapped == NULL) in bhnd_erom_iores_tell()
451 *addr = rman_get_start(iores->mapped->res); in bhnd_erom_iores_tell()
452 *size = rman_get_size(iores->mapped->res); in bhnd_erom_iores_tell()
462 if (iores->mapped == NULL) in bhnd_erom_iores_read()
467 return (bhnd_bus_read_1(iores->mapped, offset)); in bhnd_erom_iores_read()
469 return (bhnd_bus_read_2(iores->mapped, offset)); in bhnd_erom_iores_read()
471 return (bhnd_bus_read_4(iores->mapped, offset)); in bhnd_erom_iores_read()
483 if (iores->mapped) { in bhnd_erom_iores_fini()
484 bhnd_release_resource(iores->owner, SYS_RES_MEMORY, in bhnd_erom_iores_fini()
485 iores->mapped_rid, iores->mapped); in bhnd_erom_iores_fini()
486 iores->mapped = NULL; in bhnd_erom_iores_fini()
487 iores->mapped_rid = -1; in bhnd_erom_iores_fini()
495 * given bus space tag and handle.
498 * @param addr The base address mapped by @p bsh.
500 * @param bst Bus space tag for @p bsh.
501 * @param bsh Bus space handle mapping the full bus enumeration space.
504 * @retval non-zero if initializing @p iobus otherwise fails, a regular
508 bhnd_erom_iobus_init(struct bhnd_erom_iobus *iobus, bhnd_addr_t addr, in bhnd_erom_iobus_init() argument
511 iobus->eio.map = bhnd_erom_iobus_map; in bhnd_erom_iobus_init()
512 iobus->eio.tell = bhnd_erom_iobus_tell; in bhnd_erom_iobus_init()
513 iobus->eio.read = bhnd_erom_iobus_read; in bhnd_erom_iobus_init()
514 iobus->eio.fini = NULL; in bhnd_erom_iobus_init()
516 iobus->addr = addr; in bhnd_erom_iobus_init()
517 iobus->size = size; in bhnd_erom_iobus_init()
518 iobus->bst = bst; in bhnd_erom_iobus_init()
519 iobus->bsh = bsh; in bhnd_erom_iobus_init()
520 iobus->mapped = false; in bhnd_erom_iobus_init()
526 bhnd_erom_iobus_map(struct bhnd_erom_io *eio, bhnd_addr_t addr, in bhnd_erom_iobus_map() argument
531 /* Sanity check the addr/size */ in bhnd_erom_iobus_map()
535 /* addr+size must not overflow */ in bhnd_erom_iobus_map()
536 if (BHND_ADDR_MAX - size < addr) in bhnd_erom_iobus_map()
539 /* addr/size must fit within our bus tag's mapping */ in bhnd_erom_iobus_map()
540 if (addr < iobus->addr || size > iobus->size) in bhnd_erom_iobus_map()
543 if (iobus->size - (addr - iobus->addr) < size) in bhnd_erom_iobus_map()
546 /* The new addr offset and size must be representible as a bus_size_t */ in bhnd_erom_iobus_map()
547 if ((addr - iobus->addr) > BUS_SPACE_MAXSIZE) in bhnd_erom_iobus_map()
553 iobus->offset = addr - iobus->addr; in bhnd_erom_iobus_map()
554 iobus->limit = size; in bhnd_erom_iobus_map()
555 iobus->mapped = true; in bhnd_erom_iobus_map()
561 bhnd_erom_iobus_tell(struct bhnd_erom_io *eio, bhnd_addr_t *addr, in bhnd_erom_iobus_tell() argument
566 if (!iobus->mapped) in bhnd_erom_iobus_tell()
569 *addr = iobus->addr + iobus->offset; in bhnd_erom_iobus_tell()
570 *size = iobus->limit; in bhnd_erom_iobus_tell()
580 if (!iobus->mapped) in bhnd_erom_iobus_read()
583 if (iobus->limit < width || iobus->limit - width < offset) in bhnd_erom_iobus_read()
588 return (bus_space_read_1(iobus->bst, iobus->bsh, in bhnd_erom_iobus_read()
589 iobus->offset + offset)); in bhnd_erom_iobus_read()
591 return (bus_space_read_2(iobus->bst, iobus->bsh, in bhnd_erom_iobus_read()
592 iobus->offset + offset)); in bhnd_erom_iobus_read()
594 return (bus_space_read_4(iobus->bst, iobus->bsh, in bhnd_erom_iobus_read()
595 iobus->offset + offset)); in bhnd_erom_iobus_read()