~ubuntu-branches/ubuntu/hardy/kvm/hardy-backports

« back to all changes in this revision

Viewing changes to libkvm/libkvm-x86.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-02-26 13:10:57 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20080226131057-s67x6l89mtjw1x9b
Tags: 1:62+dfsg-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
240
240
        return ptr;
241
241
}
242
242
 
 
243
#define MAX_ALIAS_SLOTS 4
 
244
static struct {
 
245
        uint64_t start;
 
246
        uint64_t len;
 
247
} kvm_aliases[MAX_ALIAS_SLOTS];
 
248
 
 
249
static int get_alias_slot(uint64_t start)
 
250
{
 
251
        int i;
 
252
 
 
253
        for (i=0; i<MAX_ALIAS_SLOTS; i++)
 
254
                if (kvm_aliases[i].start == start)
 
255
                        return i;
 
256
        return -1;
 
257
}
 
258
static int get_free_alias_slot(void)
 
259
{
 
260
        int i;
 
261
 
 
262
        for (i=0; i<MAX_ALIAS_SLOTS; i++)
 
263
                if (kvm_aliases[i].len == 0)
 
264
                        return i;
 
265
        return -1;
 
266
}
 
267
 
 
268
static void register_alias(int slot, uint64_t start, uint64_t len)
 
269
{
 
270
        kvm_aliases[slot].start = start;
 
271
        kvm_aliases[slot].len   = len;
 
272
}
 
273
 
243
274
int kvm_create_memory_alias(kvm_context_t kvm,
244
 
                            uint64_t phys_addr,
245
275
                            uint64_t phys_start,
246
276
                            uint64_t len,
247
277
                            uint64_t target_phys)
254
284
        };
255
285
        int fd = kvm->vm_fd;
256
286
        int r;
 
287
        int slot;
257
288
 
258
 
        alias.slot = get_slot(phys_addr);
 
289
        slot = get_alias_slot(phys_start);
 
290
        if (slot < 0)
 
291
                slot = get_free_alias_slot();
 
292
        if (slot < 0)
 
293
                return -EBUSY;
 
294
        alias.slot = slot;
259
295
 
260
296
        r = ioctl(fd, KVM_SET_MEMORY_ALIAS, &alias);
261
297
        if (r == -1)
262
298
            return -errno;
263
299
 
 
300
        register_alias(slot, phys_start, len);
264
301
        return 0;
265
302
}
266
303
 
267
 
int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr)
 
304
int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_start)
268
305
{
269
 
        return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0);
 
306
        return kvm_create_memory_alias(kvm, phys_start, 0, 0);
270
307
}
271
308
 
272
309
#ifdef KVM_CAP_IRQCHIP