Пример #1
0
void bcom_sram_cleanup(void)
{
	
	if (bcom_sram) {
		rh_destroy(bcom_sram->rh);
		iounmap((void __iomem *)bcom_sram->base_virt);
		release_mem_region(bcom_sram->base_phys, bcom_sram->size);
		kfree(bcom_sram);
		bcom_sram = NULL;
	}
}
void remove_cache_sram(struct of_device *dev)
{
	BUG_ON(!cache_sram);

	rh_detach_region(cache_sram->rh, 0, cache_sram->size);
	rh_destroy(cache_sram->rh);

	iounmap(cache_sram->base_virt);
	release_mem_region(cache_sram->base_phys, cache_sram->size);

	kfree(cache_sram);
	cache_sram = NULL;

	dev_info(&dev->dev, "MPC85xx Cache-SRAM driver unloaded\n");
}
static int starlet_ioh_init(struct starlet_ioh *ioh, struct resource *mem)
{
	size_t size = mem->end - mem->start + 1;
	rh_info_t *rheap;
	int error = -ENOMEM;

	ioh->base = ioremap_prot(mem->start, size, _PAGE_GUARDED);
	if (!ioh->base) {
		drv_printk(KERN_ERR, "unable to ioremap ioh area\n");
		goto err;
	}
	ioh->base_phys = mem->start;
	ioh->size = size;

	{
		void *first = NULL, *last = NULL;
		u32 *p;

		p = ioh->base + size;
		do {
			p--;
			*p = 0xdeadbabe;
		} while (p != ioh->base);
		__dma_sync(ioh->base, size, DMA_TO_DEVICE);

		p = ioh->base + size;
		do {
			p--;
			if (*p != 0xdeadbabe) {
				if (!last)
					last = p;
				first = p;
			}
		} while (p != ioh->base);

		if (first)
			drv_printk(KERN_INFO, "unreliable writes from"
				   " %p to %p\n", first, last);
	}

	rheap = rh_create(STARLET_IOH_ALIGN+1);
	if (IS_ERR(rheap)) {
		error = PTR_ERR(rheap);
		goto err_rh_create;
	}
	ioh->rheap = rheap;

	error = rh_attach_region(rheap, 0, size);
	if (error)
		goto err_rh_attach_region;

	spin_lock_init(&ioh->lock);

	drv_printk(KERN_INFO, "ioh at 0x%08lx, mapped to 0x%p, size %uk\n",
		   ioh->base_phys, ioh->base, ioh->size / 1024);

	return 0;

err_rh_create:
	iounmap(ioh->base);
err_rh_attach_region:
	rh_destroy(ioh->rheap);
err:
	return error;
}