/**************************************************************************** * drivers/devicetree/fdt_virtio_mmio.c * * SPDX-License-Identifier: Apache-2.0 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The * ASF licenses this file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include #include #include #include #include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: fdt_virtio_mmio_devices_register * * Description: * This function is used to register the virtio mmio devices from the * device tree * * Input Parameters: * fdt - Device tree handle * irqbase - Interrupt base number * * Returned Value: * Return 0 if success, nageative if failed * ****************************************************************************/ int fdt_virtio_mmio_devices_register(FAR const void *fdt, int irqbase) { uintptr_t addr; int offset = -1; int irqnum; int ret; for (; ; ) { offset = fdt_node_offset_by_compatible(fdt, offset, "virtio,mmio"); if (offset == -FDT_ERR_NOTFOUND) { break; } addr = fdt_get_reg_base(fdt, offset, 0); irqnum = fdt_get_irq(fdt, offset, 1, irqbase); if (addr <= 0 || irqnum < 0) { return -EINVAL; } ret = virtio_register_mmio_device((FAR void *)addr, irqnum); if (ret < 0 && ret != -ENODEV) { return ret; } } return OK; }