From nobody Tue Feb 10 07:23:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579738805; cv=none; d=zohomail.com; s=zohoarc; b=UNa5njwEhf1tCRBXIpfYrpWitqf7Ub2SJfuCnsVONe9HIlVz6gmMyio/dWlgNmy2JCzxDUURPOMbOuIq1lzHBR9adr+SIgktoY+++OBh6Yyh21TtrBppLWxx050jlnNofdRtbbrU0TpOrICcU/L8groHd9hq54Z9XCfSm0MyWQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579738805; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vs60aoSCxThMWMdjWw9zdb8Uf19MDiz8amIUcr0Cikg=; b=TO8pUTmyCDRryLvn1P4qvlIEM6xDzPowKzSpCJOeuKTCli6vrhJIp82BoZgSLfW0HbzGukybyG7qFCxh8o54PpiGMhBuPk4BLZWlO6R1GujK43uCm8UGIaLUqTVqEmoWhDH/1zzBc+cKr4FbYnnbNbAre3DGcGEBv+itpZuda6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579738805115686.7325093532218; Wed, 22 Jan 2020 16:20:05 -0800 (PST) Received: from localhost ([::1]:48902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuQE6-00029f-I8 for importer@patchew.org; Wed, 22 Jan 2020 19:20:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54770) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuPzZ-0002Ez-3F for qemu-devel@nongnu.org; Wed, 22 Jan 2020 19:05:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuPzQ-0002Fg-Ge for qemu-devel@nongnu.org; Wed, 22 Jan 2020 19:05:00 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:36789) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iuPzP-00029U-Pb for qemu-devel@nongnu.org; Wed, 22 Jan 2020 19:04:52 -0500 Received: by mail-pj1-f65.google.com with SMTP id n59so339785pjb.1 for ; Wed, 22 Jan 2020 16:04:43 -0800 (PST) Received: from localhost.localdomain (rrcs-173-198-77-92.west.biz.rr.com. [173.198.77.92]) by smtp.gmail.com with ESMTPSA id b21sm84521pfp.0.2020.01.22.16.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 16:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vs60aoSCxThMWMdjWw9zdb8Uf19MDiz8amIUcr0Cikg=; b=NS20t6/oHsx4VBMvWWeH09BIXp9W6pqUP0TeqNcyRGC/jegmy5dXwgo6ordxmUy0MA 5USBo+lUkSJBUhRqnS8sWVECckxFsD7FEARYzExHXu2obT0hE3OQzdLxlqHHNTEQ9FgK v6dCe+ErgeQ6Iu4CsYljXEbzg4oNlbi9qTDXAHeceRkFUZYwzCiEQ/OzdMeeUWR+4Dsv iP3aPDtl1hCNrRkXQzB5Epc2OkdMUOszRaBMNa+8VTbkIwe0r5PSV9LdkehUkgUDyu9d fthaN6w8cPqp6QefTVKaJeKY5P/4iJslo3s5Umfhf4iq6VcDTogXtHOl+SArGeLzMdUT wf8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vs60aoSCxThMWMdjWw9zdb8Uf19MDiz8amIUcr0Cikg=; b=UqpqwebjNtXwE8uN6FElw3PRQV3yJUrxSvtr0HzlFQ9qtdKeeiqHmtXFoIf9WH0krT FphytxHuwKbckmwuj3agkqFYcLcEngQ/VkDfHQDOc5P06FBjZjSOm6iQ3Dm/NScrQVtU 4rYl+Y4/i6WpIocsXoiIMbIe0rEdLpXTnOKukd4sXjYNuVjwItOdaw+Qk6rEztWfZuP0 jyx3TxUL5su/nCM0+gtmHCaR1jmYaH3jsIIRuKTmWEW7/uyhZFiEzW2TJQ8YWvvOC2lu bbChLT5SQ2Gj7+H/QktcVbCSM1zqWxat475VB/rovG4DpjgXpw6hMrMR1BXFtBT8l3zL O95g== X-Gm-Message-State: APjAAAW1vMEecRadcMqqopmZ/XMD6yfOeBGHiANK28j8k8gCfa4jDblV hwRvTAuc0EpmysDvyvjmfO41wq5NXE8= X-Google-Smtp-Source: APXvYqwuSpwhAWkU7zQy/V2xnQg7fv3Cff1cXy6ssPiefStiSJ+PX20Tkuz1Z0uITp0g1tJFgDSuvQ== X-Received: by 2002:a17:90a:b009:: with SMTP id x9mr1242899pjq.124.1579737822244; Wed, 22 Jan 2020 16:03:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH rc1 13/24] hw/misc: Add Atmel power device Date: Wed, 22 Jan 2020 14:02:56 -1000 Message-Id: <20200123000307.11541-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123000307.11541-1-richard.henderson@linaro.org> References: <20200123000307.11541-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.216.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, me@xcancerberox.com.ar, S.E.Harris@kent.ac.uk, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , dovgaluk@ispras.ru, imammedo@redhat.com, mrolnik@gmail.com, aleksandar.m.mail@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Michael Rolnik This is a simple device of just one register, whenver this register is written it calls qemu_set_irq function for each of 8 bits/IRQs.. It is used to implement AVR Power Reduction Signed-off-by: Michael Rolnik Message-Id: <20200118191416.19934-14-mrolnik@gmail.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 [rth: Squash include fix and file rename from f4bug, which was:] Suggested-by: Aleksandar Markovic Signed-off-by: Richard Henderson --- include/hw/misc/atmel_power.h | 46 ++++++++++++++ hw/misc/atmel_power.c | 112 ++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + 4 files changed, 163 insertions(+) create mode 100644 include/hw/misc/atmel_power.h create mode 100644 hw/misc/atmel_power.c diff --git a/include/hw/misc/atmel_power.h b/include/hw/misc/atmel_power.h new file mode 100644 index 0000000000..5366e9693f --- /dev/null +++ b/include/hw/misc/atmel_power.h @@ -0,0 +1,46 @@ +/* + * Atmel AVR Power Reduction Management + * + * Copyright (c) 2019 Michael Rolnik + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef HW_MISC_ATMEL_POWER_H +#define HW_MISC_ATMEL_POWER_H + +#include "hw/sysbus.h" +#include "hw/hw.h" + + +#define TYPE_AVR_MASK "atmel-power" +#define AVR_MASK(obj) OBJECT_CHECK(AVRMaskState, (obj), TYPE_AVR_MASK) + +typedef struct { + /* */ + SysBusDevice parent_obj; + + /* */ + MemoryRegion iomem; + + uint8_t val; + qemu_irq irq[8]; +} AVRMaskState; + +#endif /* HW_MISC_ATMEL_POWER_H */ diff --git a/hw/misc/atmel_power.c b/hw/misc/atmel_power.c new file mode 100644 index 0000000000..adab729f66 --- /dev/null +++ b/hw/misc/atmel_power.c @@ -0,0 +1,112 @@ +/* + * Atmel AVR Power Reduction Management + * + * Copyright (c) 2019 Michael Rolnik + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/misc/atmel_power.h" +#include "qemu/log.h" +#include "hw/qdev-properties.h" +#include "hw/irq.h" + +#define DB_PRINT(fmt, args...) /* Nothing */ +/*#define DB_PRINT(fmt, args...) printf("%s: " fmt "\n", __func__, ## args= )*/ + +static void avr_mask_reset(DeviceState *dev) +{ + AVRMaskState *s =3D AVR_MASK(dev); + + s->val =3D 0x00; + + for (int i =3D 0; i < 8; i++) { + qemu_set_irq(s->irq[i], 0); + } +} + +static uint64_t avr_mask_read(void *opaque, hwaddr offset, unsigned size) +{ + assert(size =3D=3D 1); + assert(offset =3D=3D 0); + AVRMaskState *s =3D opaque; + + return (uint64_t)s->val; +} + +static void avr_mask_write(void *opaque, hwaddr offset, + uint64_t val64, unsigned size) +{ + assert(size =3D=3D 1); + assert(offset =3D=3D 0); + AVRMaskState *s =3D opaque; + uint8_t val8 =3D val64; + + DB_PRINT("write %d to offset %d", val8, (uint8_t)offset); + + s->val =3D val8; + for (int i =3D 0; i < 8; i++) { + qemu_set_irq(s->irq[i], (val8 & (1 << i)) !=3D 0); + } +} + +static const MemoryRegionOps avr_mask_ops =3D { + .read =3D avr_mask_read, + .write =3D avr_mask_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D {.max_access_size =3D 1} +}; + +static void avr_mask_init(Object *dev) +{ + AVRMaskState *s =3D AVR_MASK(dev); + SysBusDevice *busdev =3D SYS_BUS_DEVICE(dev); + + memory_region_init_io(&s->iomem, dev, &avr_mask_ops, s, TYPE_AVR_MASK, + 0x01); + sysbus_init_mmio(busdev, &s->iomem); + + for (int i =3D 0; i < 8; i++) { + sysbus_init_irq(busdev, &s->irq[i]); + } + s->val =3D 0x00; +} + +static void avr_mask_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D avr_mask_reset; +} + +static const TypeInfo avr_mask_info =3D { + .name =3D TYPE_AVR_MASK, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AVRMaskState), + .class_init =3D avr_mask_class_init, + .instance_init =3D avr_mask_init, +}; + +static void avr_mask_register_types(void) +{ + type_register_static(&avr_mask_info); +} + +type_init(avr_mask_register_types) diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index bdd77d8020..3a3c32e1b0 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -131,4 +131,7 @@ config MAC_VIA select MOS6522 select ADB =20 +config ATMEL_POWER + bool + source macio/Kconfig diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index da993f45b7..e605964f4b 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -85,3 +85,5 @@ common-obj-$(CONFIG_NRF51_SOC) +=3D nrf51_rng.o obj-$(CONFIG_MAC_VIA) +=3D mac_via.o =20 common-obj-$(CONFIG_GRLIB) +=3D grlib_ahb_apb_pnp.o + +obj-$(CONFIG_ATMEL_POWER) +=3D atmel_power.o --=20 2.20.1