/* * Copyright (C) 2003 Sistina Software * Copyright (C) 2006 Red Hat GmbH * * This file is released under the GPL. */ #include "dm.h" #include #include #include #include #include #include #include #define DM_MSG_PREFIX "io" #define DM_IO_MAX_REGIONS BITS_PER_LONG #define MIN_IOS 16 #define MIN_BIOS 16 struct dm_io_client { mempool_t *pool; struct bio_set *bios; }; /* * Aligning 'struct io' reduces the number of bits required to store * its address. Refer to store_io_and_region_in_bio() below. */ struct io { unsigned long error_bits; atomic_t count; struct task_struct *sleeper; struct dm_io_client *client; io_notify_fn callback; void *context; void *vma_invalidate_address; unsigned long vma_invalidate_size; } __attribute__((aligned(DM_IO_MAX_REGIONS))); static struct kmem_cache *_dm_io_cache; /* * Create a client with mempool and bioset. */ struct dm_io_client *dm_io_client_create(void) { struct dm_io_client *client; client = kmalloc(sizeof(*client), GFP_KERNEL); if (!client) return ERR_PTR(-ENOMEM); client->pool = mempool_create_slab_pool(MIN_IOS, _dm_io_cache); if (!client->pool) goto bad; client->bios = bioset_create(MIN_BIOS, 0); if (!client->bios) goto bad; return client; bad: if (client->pool) mempool_destroy(client->pool); kfree(client); return ERR_PTR(-ENOMEM); } EXPORT_SYMBOL(dm_io_client_create); void dm_io_client_destroy(struct dm_io_client *client) { mempool_destroy(client->pool); bioset_free(client->bios); kfree(client); } EXPORT_SYMBOL(dm_io_client_destroy); /*----------------------------------------------------------------- * We need to keep track of which region a bio is doing io for. * To avoid a memory allocation to store just 5 or 6 bits, we * ensure the 'struct io' pointer is aligned so enough low bits are * always zero and then combine it with the region number directly in * bi_private. *---------------------------------------------------------------*/ static void store_io_and_region_in_bio(struct bio *bio, struct io *io, unsigned region) { if (unlikely(!IS_ALIGNED((unsigned long)io, DM_IO_MAX_REGIONS))) { DMCRIT("Unaligned struct io pointer %p", io); BUG(); } bio->bi_private = (void *)((unsigned long)io | region); } static void retrieve_io_and_region_from_bio(struct bio *bio, struct io **io, unsigned *region) { unsigned long val = (unsigned long)bio->bi_private; *io = (void *)(val & -(unsigned long)DM_IO_MAX_REGIONS); *region = val & (DM_IO_MAX_REGIONS - 1); } /*----------------------------------------------------------------- * We need an io object to keep track of the number of bios that * have been dispatched for a particular io. *---------------------------------------------------------------*/ static void dec_count(struct io *io, unsigned int region, int error) { if (error) set_bit(region, &io->error_bits); if (atomic_dec_and_test(&io->count)) { if (io->vma_invalidate_size) invalidate_kernel_vmap_range(io->vma_invalidate_address, io->vma_invalidate_size); if (io->sleeper) wake_up_process(io->sleeper); else { unsigned long r = io->error_bits; io_notify_fn fn = io->callback; void *context = io->context; mempool_free(io, io->client->pool); fn(r, context); } } } static void endio(struct bio *bio, int error) { struct io *io; unsigned region; if (error && bio_data_dir(bio) == READ) zero_fill_bio(bio); /* * The bio destructor in bio_put() may use the io object. */ retrieve_io_and_region_from_bio(bio, &io, ®ion); bio_put(bio); dec_count(io, region, error); } /*----------------------------------------------------------------- * These little objects provide an abstra
module \$pmux (A, B, S, Y);

wire [1023:0] _TECHMAP_DO_ = "proc; clean";

parameter WIDTH = 1;
parameter S_WIDTH = 1;

input [WIDTH-1:0] A;
input [WIDTH*S_WIDTH-1:0] B;
input [S_WIDTH-1:0] S;
output reg [WIDTH-1:0] Y;

integer i;

always @* begin
	Y <= A;
	for (i = 0; i < S_WIDTH; i=i+1)
		if (S[i]) Y <= B[WIDTH*i +: WIDTH];
end

endmodule
ns, where, io_req->bi_rw, &dp, io_req->notify.fn, io_req->notify.context); } EXPORT_SYMBOL(dm_io); int __init dm_io_init(void) { _dm_io_cache = KMEM_CACHE(io, 0); if (!_dm_io_cache) return -ENOMEM; return 0; } void dm_io_exit(void) { kmem_cache_destroy(_dm_io_cache); _dm_io_cache = NULL; }