Skip to content

Commit

Permalink
Merge tag 'hw-misc-20240312' of https://github.com/philmd/qemu into s…
Browse files Browse the repository at this point in the history
…taging

Misc HW patch queue

- Rename hw/ide/ahci-internal.h for consistency (Zoltan)
- More convenient PCI hotplug trace events (Vladimir)
- Short CLI option to add drives for sam460ex machine (Zoltan)
- More missing ERRP_GUARD() macros (Zhao)
- Avoid faulting when unmapped I/O BAR is accessed on SPARC EBUS (Mark)
- Remove unused includes in hw/core/ (Zhao)
- New PCF8574 GPIO over I2C model (Dmitriy)
- Require ObjC on Darwin macOS by default (Peter)
- Corrected "-smp parameter=1" placement in docs/ (Zhao)

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmXwEJkACgkQ4+MsLN6t
# wN4A3hAAngVu7VmyrfqYF6jfDMUuRGYaKf4D73/KF6R1PsU+nJdN7UAkECLj8o7g
# mkcAQu1U3fKCUssF6MJ2a3kU+rD1OkkA/ZcitzgWwEjCK8KVjtMt2HzEqX+B/X+e
# RUVjXMOMkyV48MF0+yLhJz+lQiDpEBFVxIgssPBNUz1Pw9IfoXp29Bfz+bYBThS4
# ywAdvCefNzSira0Nt6RWTnvgBHB/1+aLy1uMSt0Xu926zcqoxQJ0b//0flYL8vAf
# JuSSZuiXPw+oAc3qG3d6aPl3g8DrFn3pvPD471KlFQAnB0dlhEZZqNBPvraySpHl
# h04Y8teHYj9XfxPtaWfaEdgQCazdkKFR/q7E5c9GU00Rf469BJeuo9Pzkm4kWfbU
# sbCl8em5biVZ5DpBIOMT3/D0JOyGf7/CM8y5c3Jc92hapx2NdSszkvCicrDE1+i0
# zEr4N0P/F2x5KFVFkQ3Xzv2Jtzw+iXj6kSE5a5/64GMK29Mqu/EPaSkvwGDQOs3N
# QJ9mpa4gg47g310a0/nH0i5eVbvGVuzcCMP6VXOBVr18cJ7JFQFFiYcvoTDXNQ2m
# sq5xUelRimnWfKpawomJXkS+/j0usH61/aQBuDKfj45i8/XFRejCIk0gMWQ9hjyD
# no1HqDN8CVXtiPNSinC7ctNHU5ClS0xO/BRl0h3PGC7Bl+A2eVY=
# =JQg1
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 12 Mar 2024 08:21:45 GMT
# gpg:                using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE
# gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full]
# Primary key fingerprint: FAAB E75E 1291 7221 DCFD  6BB2 E3E3 2C2C DEAD C0DE

* tag 'hw-misc-20240312' of https://github.com/philmd/qemu:
  docs/about/deprecated.rst: Move SMP configurations item to system emulator section
  meson.build: Always require an objc compiler on macos hosts
  hw/gpio: introduce pcf8574 driver
  hw/core: Cleanup unused included headers in numa.c
  hw/core: Cleanup unused included header in machine-qmp-cmds.c
  hw/core: Cleanup unused included headers in cpu-common.c
  sun4u: remap ebus BAR0 to use unassigned_io_ops instead of alias to PCI IO space
  hw/misc/ivshmem: Fix missing ERRP_GUARD() for error_prepend()
  hw/core/qdev-properties-system: Fix missing ERRP_GUARD() for error_prepend()
  hw/core/loader-fit: Fix missing ERRP_GUARD() for error_prepend()
  hw/ppc/sam460ex: Support short options for adding drives
  hw/pci: add some convenient trace-events for pcie and shpc hotplug
  hw/ide/ahci: Rename ahci_internal.h to ahci-internal.h

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Mar 12, 2024
2 parents 8f3f329 + afc8b05 commit fe6d443
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 27 deletions.
6 changes: 6 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,12 @@ S: Maintained
F: hw/i2c/i2c_mux_pca954x.c
F: include/hw/i2c/i2c_mux_pca954x.h

pcf8574
M: Dmitrii Sharikhin <d.sharikhin@yadro.com>
S: Maintained
F: hw/gpio/pcf8574.c
F: include/gpio/pcf8574.h

Generic Loader
M: Alistair Francis <alistair@alistair23.me>
S: Maintained
Expand Down
20 changes: 10 additions & 10 deletions docs/about/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ as short-form boolean values, and passed to plugins as ``arg_name=on``.
However, short-form booleans are deprecated and full explicit ``arg_name=on``
form is preferred.

User-mode emulator command line arguments
-----------------------------------------

``-p`` (since 9.0)
''''''''''''''''''

The ``-p`` option pretends to control the host page size. However,
it is not possible to change the host page size, and using the
option only causes failures.

``-smp`` (Unsupported "parameter=1" SMP configurations) (since 9.0)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Expand All @@ -71,6 +61,16 @@ configurations (e.g. -smp drawers=1,books=1,clusters=1 for x86 PC machine) is
marked deprecated since 9.0, users have to ensure that all the topology members
described with -smp are supported by the target machine.

User-mode emulator command line arguments
-----------------------------------------

``-p`` (since 9.0)
''''''''''''''''''

The ``-p`` option pretends to control the host page size. However,
it is not possible to change the host page size, and using the
option only causes failures.

QEMU Machine Protocol (QMP) commands
------------------------------------

Expand Down
4 changes: 0 additions & 4 deletions hw/core/cpu-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
#include "qapi/error.h"
#include "hw/core/cpu.h"
#include "sysemu/hw_accel.h"
#include "qemu/notify.h"
#include "qemu/log.h"
#include "qemu/main-loop.h"
#include "exec/log.h"
#include "exec/cpu-common.h"
#include "exec/gdbstub.h"
#include "qemu/error-report.h"
#include "qemu/qemu-print.h"
#include "sysemu/tcg.h"
#include "hw/boards.h"
#include "hw/qdev-properties.h"
Expand Down
2 changes: 2 additions & 0 deletions hw/core/loader-fit.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static int fit_load_kernel(const struct fit_loader *ldr, const void *itb,
int cfg, void *opaque, hwaddr *pend,
Error **errp)
{
ERRP_GUARD();
const char *name;
const void *data;
const void *load_data;
Expand Down Expand Up @@ -178,6 +179,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
int cfg, void *opaque, const void *match_data,
hwaddr kernel_end, Error **errp)
{
ERRP_GUARD();
Error *err = NULL;
const char *name;
const void *data;
Expand Down
1 change: 0 additions & 1 deletion hw/core/machine-qmp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "qapi/qmp/qobject.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/type-helpers.h"
#include "qemu/main-loop.h"
#include "qemu/uuid.h"
#include "qom/qom-qobject.h"
#include "sysemu/hostmem.h"
Expand Down
2 changes: 0 additions & 2 deletions hw/core/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
#include "sysemu/numa.h"
#include "exec/cpu-common.h"
#include "exec/ramlist.h"
#include "qemu/bitmap.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi/opts-visitor.h"
#include "qapi/qapi-visit-machine.h"
#include "sysemu/qtest.h"
#include "hw/core/cpu.h"
#include "hw/mem/pc-dimm.h"
#include "migration/vmstate.h"
#include "hw/boards.h"
#include "hw/mem/memory-device.h"
#include "qemu/option.h"
Expand Down
1 change: 1 addition & 0 deletions hw/core/qdev-properties-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
ERRP_GUARD();
Property *prop = opaque;
CharBackend *be = object_field_prop_ptr(obj, prop);
Chardev *s;
Expand Down
4 changes: 4 additions & 0 deletions hw/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ config SIFIVE_GPIO

config STM32L4X5_GPIO
bool

config PCF8574
bool
depends on I2C
1 change: 1 addition & 0 deletions hw/gpio/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files(
system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c'))
system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c'))
system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c'))
system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c'))
162 changes: 162 additions & 0 deletions hw/gpio/pcf8574.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* SPDX-License-Identifier: GPL-2.0-only */

/*
* NXP PCF8574 8-port I2C GPIO expansion chip.
* Copyright (c) 2024 KNS Group (YADRO).
* Written by Dmitrii Sharikhin <d.sharikhin@yadro.com>
*/

#include "qemu/osdep.h"
#include "hw/i2c/i2c.h"
#include "hw/gpio/pcf8574.h"
#include "hw/irq.h"
#include "migration/vmstate.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qom/object.h"

/*
* PCF8574 and compatible chips incorporate quasi-bidirectional
* IO. Electrically it means that device sustain pull-up to line
* unless IO port is configured as output _and_ driven low.
*
* IO access is implemented as simple I2C single-byte read
* or write operation. So, to configure line to input user write 1
* to corresponding bit. To configure line to output and drive it low
* user write 0 to corresponding bit.
*
* In essence, user can think of quasi-bidirectional IO as
* open-drain line, except presence of builtin rising edge acceleration
* embedded in PCF8574 IC
*
* PCF8574 has interrupt request line, which is being pulled down when
* port line state differs from last read. Port read operation clears
* state and INT line returns to high state via pullup.
*/

OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)

#define PORTS_COUNT (8)

struct PCF8574State {
I2CSlave parent_obj;
uint8_t lastrq; /* Last requested state. If changed - assert irq */
uint8_t input; /* external electrical line state */
uint8_t output; /* Pull-up (1) or drive low (0) on bit */
qemu_irq handler[PORTS_COUNT];
qemu_irq intrq; /* External irq request */
};

static void pcf8574_reset(DeviceState *dev)
{
PCF8574State *s = PCF8574(dev);
s->lastrq = MAKE_64BIT_MASK(0, PORTS_COUNT);
s->input = MAKE_64BIT_MASK(0, PORTS_COUNT);
s->output = MAKE_64BIT_MASK(0, PORTS_COUNT);
}

static inline uint8_t pcf8574_line_state(PCF8574State *s)
{
/* we driving line low or external circuit does that */
return s->input & s->output;
}

static uint8_t pcf8574_rx(I2CSlave *i2c)
{
PCF8574State *s = PCF8574(i2c);
uint8_t linestate = pcf8574_line_state(s);
if (s->lastrq != linestate) {
s->lastrq = linestate;
if (s->intrq) {
qemu_set_irq(s->intrq, 1);
}
}
return linestate;
}

static int pcf8574_tx(I2CSlave *i2c, uint8_t data)
{
PCF8574State *s = PCF8574(i2c);
uint8_t prev;
uint8_t diff;
uint8_t actual;
int line = 0;

prev = pcf8574_line_state(s);
s->output = data;
actual = pcf8574_line_state(s);

for (diff = (actual ^ prev); diff; diff &= ~(1 << line)) {
line = ctz32(diff);
if (s->handler[line]) {
qemu_set_irq(s->handler[line], (actual >> line) & 1);
}
}

if (s->intrq) {
qemu_set_irq(s->intrq, actual == s->lastrq);
}

return 0;
}

static const VMStateDescription vmstate_pcf8574 = {
.name = "pcf8574",
.version_id = 0,
.minimum_version_id = 0,
.fields = (VMStateField[]) {
VMSTATE_I2C_SLAVE(parent_obj, PCF8574State),
VMSTATE_UINT8(lastrq, PCF8574State),
VMSTATE_UINT8(input, PCF8574State),
VMSTATE_UINT8(output, PCF8574State),
VMSTATE_END_OF_LIST()
}
};

static void pcf8574_gpio_set(void *opaque, int line, int level)
{
PCF8574State *s = (PCF8574State *) opaque;
assert(line >= 0 && line < ARRAY_SIZE(s->handler));

if (level) {
s->input |= (1 << line);
} else {
s->input &= ~(1 << line);
}

if (pcf8574_line_state(s) != s->lastrq && s->intrq) {
qemu_set_irq(s->intrq, 0);
}
}

static void pcf8574_realize(DeviceState *dev, Error **errp)
{
PCF8574State *s = PCF8574(dev);

qdev_init_gpio_in(dev, pcf8574_gpio_set, ARRAY_SIZE(s->handler));
qdev_init_gpio_out(dev, s->handler, ARRAY_SIZE(s->handler));
qdev_init_gpio_out_named(dev, &s->intrq, "nINT", 1);
}

static void pcf8574_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);

k->recv = pcf8574_rx;
k->send = pcf8574_tx;
dc->realize = pcf8574_realize;
dc->reset = pcf8574_reset;
dc->vmsd = &vmstate_pcf8574;
}

static const TypeInfo pcf8574_infos[] = {
{
.name = TYPE_PCF8574,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(PCF8574State),
.class_init = pcf8574_class_init,
}
};

DEFINE_TYPES(pcf8574_infos);
File renamed without changes.
2 changes: 1 addition & 1 deletion hw/ide/ahci.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "hw/ide/pci.h"
#include "hw/ide/ahci-pci.h"
#include "hw/ide/ahci-sysbus.h"
#include "ahci_internal.h"
#include "ahci-internal.h"
#include "ide-internal.h"

#include "trace.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/ide/ich.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#include "sysemu/dma.h"
#include "hw/ide/pci.h"
#include "hw/ide/ahci-pci.h"
#include "ahci_internal.h"
#include "ahci-internal.h"

#define ICH9_MSI_CAP_OFFSET 0x80
#define ICH9_SATA_CAP_OFFSET 0xA8
Expand Down
1 change: 1 addition & 0 deletions hw/misc/ivshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,

static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
{
ERRP_GUARD();
IVShmemState *s = IVSHMEM_COMMON(dev);
Error *err = NULL;
uint8_t *pci_conf;
Expand Down
56 changes: 56 additions & 0 deletions hw/pci/pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "hw/pci/pcie_regs.h"
#include "hw/pci/pcie_port.h"
#include "qemu/range.h"
#include "trace.h"

//#define DEBUG_PCIE
#ifdef DEBUG_PCIE
Expand All @@ -45,6 +46,23 @@ static bool pcie_sltctl_powered_off(uint16_t sltctl)
&& (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF;
}

static const char *pcie_led_state_to_str(uint16_t value)
{
switch (value) {
case PCI_EXP_SLTCTL_PWR_IND_ON:
case PCI_EXP_SLTCTL_ATTN_IND_ON:
return "on";
case PCI_EXP_SLTCTL_PWR_IND_BLINK:
case PCI_EXP_SLTCTL_ATTN_IND_BLINK:
return "blink";
case PCI_EXP_SLTCTL_PWR_IND_OFF:
case PCI_EXP_SLTCTL_ATTN_IND_OFF:
return "off";
default:
return "invalid";
}
}

/***************************************************************************
* pci express capability helper functions
*/
Expand Down Expand Up @@ -735,6 +753,28 @@ void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta)
*slt_sta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
}

static void find_child_fn(PCIBus *bus, PCIDevice *dev, void *opaque)
{
PCIDevice **child = opaque;

if (!*child) {
*child = dev;
}
}

/*
* Returns the plugged device or first function of multifunction plugged device
*/
static PCIDevice *pcie_cap_slot_find_child(PCIDevice *dev)
{
PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev));
PCIDevice *child = NULL;

pci_for_each_device(sec_bus, pci_bus_num(sec_bus), find_child_fn, &child);

return child;
}

void pcie_cap_slot_write_config(PCIDevice *dev,
uint16_t old_slt_ctl, uint16_t old_slt_sta,
uint32_t addr, uint32_t val, int len)
Expand Down Expand Up @@ -779,6 +819,22 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
sltsta);
}

if (trace_event_get_state_backends(TRACE_PCIE_CAP_SLOT_WRITE_CONFIG)) {
DeviceState *parent = DEVICE(dev);
DeviceState *child = DEVICE(pcie_cap_slot_find_child(dev));

trace_pcie_cap_slot_write_config(
parent->canonical_path,
child ? child->canonical_path : "no-child",
(sltsta & PCI_EXP_SLTSTA_PDS) ? "present" : "not present",
pcie_led_state_to_str(old_slt_ctl & PCI_EXP_SLTCTL_PIC),
pcie_led_state_to_str(val & PCI_EXP_SLTCTL_PIC),
pcie_led_state_to_str(old_slt_ctl & PCI_EXP_SLTCTL_AIC),
pcie_led_state_to_str(val & PCI_EXP_SLTCTL_AIC),
(old_slt_ctl & PCI_EXP_SLTCTL_PWR_OFF) ? "off" : "on",
(val & PCI_EXP_SLTCTL_PWR_OFF) ? "off" : "on");
}

/*
* If the slot is populated, power indicator is off and power
* controller is off, it is safe to detach the devices.
Expand Down

0 comments on commit fe6d443

Please sign in to comment.