DM: support mmio dev gpa resource allocation

The ACPI MMIO devices, like TPM, has a fixed base GPA. Sould support
GPA resource allocating for MMIO devices. GPA region
0xF0000000~0xFE000000 is not used, can allocate GPA from it.

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Tao Yuhong 2021-04-19 07:37:16 -04:00 committed by wenlingz
parent 606704eff6
commit f1c2eca1dc
2 changed files with 23 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include <strings.h>
#include <assert.h>
#include <stdbool.h>
#include <sys/user.h>
#include "dm.h"
#include "vmmapi.h"
@ -19,6 +20,7 @@
#include "inout.h"
#include "mem.h"
#include "log.h"
#include "mmio_dev.h"
struct mmio_dev {
@ -44,6 +46,23 @@ SET_DECLARE(mmio_dev_ops_set, struct mmio_dev_ops);
struct mmio_dev_ops pt_mmiodev;
static uint32_t mmio_dev_base = MMIO_DEV_BASE;
int mmio_dev_alloc_gpa_resource32(uint32_t *addr, uint32_t size_in)
{
uint32_t base, size;
size = roundup2(size_in, PAGE_SIZE);
base = roundup2(mmio_dev_base, size);
if (base + size <= MMIO_DEV_LIMIT) {
*addr = base;
mmio_dev_base = base + size;
return 0;
} else {
return -1;
}
}
int parse_pt_acpidev(char *opt)
{
int err = -EINVAL;

View File

@ -14,4 +14,8 @@ int parse_pt_mmiodev(char *arg);
int init_mmio_devs(struct vmctx *ctx);
void deinit_mmio_devs(struct vmctx *ctx);
int mmio_dev_alloc_gpa_resource32(uint32_t *addr, uint32_t size_in);
#define MMIO_DEV_BASE 0xF0000000U
#define MMIO_DEV_LIMIT 0xFE000000U
#endif /* _MMIO_DEV_H_ */