qemu/include/hw/timer/cmsdk-apb-timer.h
<<
>>
Prefs
   1/*
   2 * ARM CMSDK APB timer emulation
   3 *
   4 * Copyright (c) 2017 Linaro Limited
   5 * Written by Peter Maydell
   6 *
   7 *  This program is free software; you can redistribute it and/or modify
   8 *  it under the terms of the GNU General Public License version 2 or
   9 *  (at your option) any later version.
  10 */
  11
  12#ifndef CMSDK_APB_TIMER_H
  13#define CMSDK_APB_TIMER_H
  14
  15#include "hw/sysbus.h"
  16#include "hw/ptimer.h"
  17
  18#define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer"
  19#define CMSDK_APB_TIMER(obj) OBJECT_CHECK(CMSDKAPBTIMER, (obj), \
  20                                         TYPE_CMSDK_APB_TIMER)
  21
  22typedef struct {
  23    /*< private >*/
  24    SysBusDevice parent_obj;
  25
  26    /*< public >*/
  27    MemoryRegion iomem;
  28    qemu_irq timerint;
  29    uint32_t pclk_frq;
  30    struct ptimer_state *timer;
  31
  32    uint32_t ctrl;
  33    uint32_t value;
  34    uint32_t reload;
  35    uint32_t intstatus;
  36} CMSDKAPBTIMER;
  37
  38/**
  39 * cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER
  40 * @addr: location in system memory to map registers
  41 * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate)
  42 */
  43static inline DeviceState *cmsdk_apb_timer_create(hwaddr addr,
  44                                                 qemu_irq timerint,
  45                                                 uint32_t pclk_frq)
  46{
  47    DeviceState *dev;
  48    SysBusDevice *s;
  49
  50    dev = qdev_create(NULL, TYPE_CMSDK_APB_TIMER);
  51    s = SYS_BUS_DEVICE(dev);
  52    qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq);
  53    qdev_init_nofail(dev);
  54    sysbus_mmio_map(s, 0, addr);
  55    sysbus_connect_irq(s, 0, timerint);
  56    return dev;
  57}
  58
  59#endif
  60