예제 #1
0
파일: bcma_nexus.c 프로젝트: tomtor/freebsd
static int
bcma_nexus_attach(device_t dev)
{
	int 		 erom_rid;
	int 		 error;
	struct resource	*erom_res;
	const struct bhnd_chipid *cid = BHND_BUS_GET_CHIPID(device_get_parent(dev), dev);

  	erom_rid = BCMA_NEXUS_EROM_RID;
 	error = bus_set_resource(dev, SYS_RES_MEMORY, erom_rid, cid->enum_addr, BCMA_EROM_TABLE_SIZE);
 	if (error != 0) {
 		BHND_ERROR_DEV(dev, "failed to set EROM resource");
 		return (error);
 	}

 	/* Map the EROM resource and enumerate our children. */
 	BHND_DEBUG_DEV(dev, "erom enum address: %jx", cid->enum_addr);
 	erom_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &erom_rid, RF_ACTIVE);
 	if (erom_res == NULL) {
 		BHND_ERROR_DEV(dev, "failed to allocate EROM resource");
 		return (ENXIO);
 	}

 	BHND_DEBUG_DEV(dev, "erom scanning start address: %p", rman_get_virtual(erom_res));
 	error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START);

 	/* Clean up */
 	bus_release_resource(dev, SYS_RES_MEMORY, erom_rid, erom_res);
 	if (error)
 		return (error);

 	/* Call our superclass' implementation */
 	return (bcma_attach(dev));
}
예제 #2
0
파일: chipc.c 프로젝트: wulf7/freebsd
/* Allocate region records for the given port, and add the port's memory
 * range to the mem_rman */
static int
chipc_rman_init_regions (struct chipc_softc *sc, bhnd_port_type type,
    u_int port)
{
	struct	chipc_region	*cr;
	rman_res_t		 start, end;
	u_int			 num_regions;
	int			 error;

	num_regions = bhnd_get_region_count(sc->dev, type, port);
	for (u_int region = 0; region < num_regions; region++) {
		/* Allocate new region record */
		cr = chipc_alloc_region(sc, type, port, region);
		if (cr == NULL)
			return (ENODEV);

		/* Can't manage regions that cannot be allocated */
		if (cr->cr_rid < 0) {
			BHND_DEBUG_DEV(sc->dev, "no rid for chipc region "
			    "%s%u.%u", bhnd_port_type_name(type), port, region);
			chipc_free_region(sc, cr);
			continue;
		}

		/* Add to rman's managed range */
		start = cr->cr_addr;
		end = cr->cr_end;
		if ((error = rman_manage_region(&sc->mem_rman, start, end))) {
			chipc_free_region(sc, cr);
			return (error);
		}

		/* Add to region list */
		STAILQ_INSERT_TAIL(&sc->mem_regions, cr, cr_link);
	}

	return (0);
}