diff mbox

[3/4] kvm tools: Add a void ptr to be passed to mmio callback

Message ID 1311843715-5464-3-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin July 28, 2011, 9:01 a.m. UTC
This makes MMIO callback similar to it's PIO counterpart by passing
a void* value provided in the registration to the callback function.

This allows to keep context within the MMIO callback function.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/include/kvm/kvm.h |    2 +-
 tools/kvm/mmio.c            |    8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Cyrill Gorcunov July 28, 2011, 9:42 a.m. UTC | #1
On Thu, Jul 28, 2011 at 12:01:54PM +0300, Sasha Levin wrote:
...
>  
>  struct mmio_mapping {
>  	struct rb_int_node	node;
> -	void			(*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write);
> +	void			(*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
> +	void			*ptr;
>  };

I guess no need to name it *that* long, probably simple

struct mmio_mapping {
	struct rb_int_node	node;
	void			(*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
	void			*ptr;
};
...
>  
>  	if (mmio)
> -		mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write);
> +		mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write, mmio->ptr);

So this would be

	if (mmio)
		mmio->mmio_fn(phys_addr, data, len, is_write, mmio->ptr);

no?

	Cyrill
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg July 28, 2011, 9:43 a.m. UTC | #2
On Thu, Jul 28, 2011 at 12:42 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> On Thu, Jul 28, 2011 at 12:01:54PM +0300, Sasha Levin wrote:
> ...
>>
>>  struct mmio_mapping {
>>       struct rb_int_node      node;
>> -     void                    (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write);
>> +     void                    (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
>> +     void                    *ptr;
>>  };
>
> I guess no need to name it *that* long, probably simple
>
> struct mmio_mapping {
>        struct rb_int_node      node;
>        void                    (*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
>        void                    *ptr;
> };
> ...
>>
>>       if (mmio)
>> -             mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write);
>> +             mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write, mmio->ptr);
>
> So this would be
>
>        if (mmio)
>                mmio->mmio_fn(phys_addr, data, len, is_write, mmio->ptr);
>
> no?

Makes sense, yes.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index eeb55b6..5f3cbbf 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -64,7 +64,7 @@  void kvm__irq_line(struct kvm *kvm, int irq, int level);
 bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count);
 bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write);
 void kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr);
-bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write));
+bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr);
 bool kvm__deregister_mmio(struct kvm *kvm, u64 phys_addr);
 void kvm__pause(void);
 void kvm__continue(void);
diff --git a/tools/kvm/mmio.c b/tools/kvm/mmio.c
index 64bef37..9a7f84a 100644
--- a/tools/kvm/mmio.c
+++ b/tools/kvm/mmio.c
@@ -14,7 +14,8 @@ 
 
 struct mmio_mapping {
 	struct rb_int_node	node;
-	void			(*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write);
+	void			(*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
+	void			*ptr;
 };
 
 static struct rb_root mmio_tree = RB_ROOT;
@@ -55,7 +56,7 @@  static const char *to_direction(u8 is_write)
 	return "read";
 }
 
-bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write))
+bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr)
 {
 	struct mmio_mapping *mmio;
 	struct kvm_coalesced_mmio_zone zone;
@@ -68,6 +69,7 @@  bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void
 	*mmio = (struct mmio_mapping) {
 		.node = RB_INT_INIT(phys_addr, phys_addr + phys_addr_len),
 		.kvm_mmio_callback_fn = kvm_mmio_callback_fn,
+		.ptr	= ptr,
 	};
 
 	zone = (struct kvm_coalesced_mmio_zone) {
@@ -120,7 +122,7 @@  bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_
 	mmio = mmio_search(&mmio_tree, phys_addr, len);
 
 	if (mmio)
-		mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write);
+		mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write, mmio->ptr);
 	else
 		fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n",
 			to_direction(is_write), phys_addr, len);