tpm: Split off tpm_crb_reset function
Split off the tpm_crb_reset function part from tpm_crb_realize that we need to run every time the machine resets. Also register our reset function with the system since TYPE_DEVICE seems to not get a reset otherwise. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
		
							parent
							
								
									e486b52822
								
							
						
					
					
						commit
						b8d44ab8fe
					
				| 
						 | 
				
			
			@ -26,6 +26,7 @@
 | 
			
		|||
#include "hw/acpi/tpm.h"
 | 
			
		||||
#include "migration/vmstate.h"
 | 
			
		||||
#include "sysemu/tpm_backend.h"
 | 
			
		||||
#include "sysemu/reset.h"
 | 
			
		||||
#include "tpm_int.h"
 | 
			
		||||
#include "tpm_util.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -210,29 +211,10 @@ static Property tpm_crb_properties[] = {
 | 
			
		|||
    DEFINE_PROP_END_OF_LIST(),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void tpm_crb_realize(DeviceState *dev, Error **errp)
 | 
			
		||||
static void tpm_crb_reset(void *dev)
 | 
			
		||||
{
 | 
			
		||||
    CRBState *s = CRB(dev);
 | 
			
		||||
 | 
			
		||||
    if (!tpm_find()) {
 | 
			
		||||
        error_setg(errp, "at most one TPM device is permitted");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!s->tpmbe) {
 | 
			
		||||
        error_setg(errp, "'tpmdev' property is required");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s,
 | 
			
		||||
        "tpm-crb-mmio", sizeof(s->regs));
 | 
			
		||||
    memory_region_init_ram(&s->cmdmem, OBJECT(s),
 | 
			
		||||
        "tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp);
 | 
			
		||||
 | 
			
		||||
    memory_region_add_subregion(get_system_memory(),
 | 
			
		||||
        TPM_CRB_ADDR_BASE, &s->mmio);
 | 
			
		||||
    memory_region_add_subregion(get_system_memory(),
 | 
			
		||||
        TPM_CRB_ADDR_BASE + sizeof(s->regs), &s->cmdmem);
 | 
			
		||||
 | 
			
		||||
    tpm_backend_reset(s->tpmbe);
 | 
			
		||||
 | 
			
		||||
    ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
 | 
			
		||||
| 
						 | 
				
			
			@ -267,6 +249,32 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp)
 | 
			
		|||
    tpm_backend_startup_tpm(s->tpmbe, s->be_buffer_size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void tpm_crb_realize(DeviceState *dev, Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    CRBState *s = CRB(dev);
 | 
			
		||||
 | 
			
		||||
    if (!tpm_find()) {
 | 
			
		||||
        error_setg(errp, "at most one TPM device is permitted");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!s->tpmbe) {
 | 
			
		||||
        error_setg(errp, "'tpmdev' property is required");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s,
 | 
			
		||||
        "tpm-crb-mmio", sizeof(s->regs));
 | 
			
		||||
    memory_region_init_ram(&s->cmdmem, OBJECT(s),
 | 
			
		||||
        "tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp);
 | 
			
		||||
 | 
			
		||||
    memory_region_add_subregion(get_system_memory(),
 | 
			
		||||
        TPM_CRB_ADDR_BASE, &s->mmio);
 | 
			
		||||
    memory_region_add_subregion(get_system_memory(),
 | 
			
		||||
        TPM_CRB_ADDR_BASE + sizeof(s->regs), &s->cmdmem);
 | 
			
		||||
 | 
			
		||||
    qemu_register_reset(tpm_crb_reset, dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void tpm_crb_class_init(ObjectClass *klass, void *data)
 | 
			
		||||
{
 | 
			
		||||
    DeviceClass *dc = DEVICE_CLASS(klass);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue