From owner-freebsd-hackers@freebsd.org Sun Dec 17 20:01:04 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 40400E9431E for ; Sun, 17 Dec 2017 20:01:04 +0000 (UTC) (envelope-from embaudarm@gmail.com) Received: from mail-ot0-x244.google.com (mail-ot0-x244.google.com [IPv6:2607:f8b0:4003:c0f::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 06C317C4E9 for ; Sun, 17 Dec 2017 20:01:04 +0000 (UTC) (envelope-from embaudarm@gmail.com) Received: by mail-ot0-x244.google.com with SMTP id v40so1139114ote.13 for ; Sun, 17 Dec 2017 12:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=7HVFWCoOkBXzODFCYq34GOGqLh2YEMWe+rU08Jgfk14=; b=FviwUh0OHIHsGF0inaEfT3rdKnMLktaNunzWnpuG+uQQi0RuSX2Fh9UXZ8JxE4/iwV tVNTIS5jn6z4PxUzXZSMpHaYGWxxmUznUVyUzdtQAfL/HsAptOulByO8RzYEhprlPJa2 agpCiOKOypGui/0b0rTn9dZUGJQiCTi2HeuVGWw67EB0TFGK8OKhJd4WkdBQiSHCcwAT DV+M7I2CrXgJIjzaQYO2uKUvH4NJnc1V7FrKCFga66zRRJMc3rnq6CUcdnSEPw6w6/c2 OWMz4wDSd5ha5VFMZ9hvFSm6XS6Anp8/BRIxhe/0+32cFPf+mLk/3Ws+eMnTWHQYmqDw nQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=7HVFWCoOkBXzODFCYq34GOGqLh2YEMWe+rU08Jgfk14=; b=O1EnUJomT4hhsXfgSxJsstKH8N4q/OAioqwAtNAXgrNVG/WI1GoMmivOrXMsTybc+3 Cg81hyhQWFwj50+06s9Yt/ZL1dfs02razcwcM95PLc4qhcpk7cOGSyMW833slrXgXiVo VCmXXhWP67JwUeeCmN2qmqP1VgE1GjdmRrKrCAfbM10K/fTpATv9Yqi6H1C/XlexNDRb OuoaW03b277IQe7Jfp9d6zTMcAxOyh40tHw5gq5oiJ0PiytmN4ugqXLmiIGpMCOEMF6f CYfat1BDj0hvi4iHKZr5v5Vo7SSDkrgxuVWR8QKx/NAbqwthipOxd59mozJGO2CpgEl2 lXfA== X-Gm-Message-State: AKGB3mLFl9JX+7GlNK8o9Zq22Irry6bUBg5tV3vnhCfl+w9Tw+b/w+T1 6igG6kNwXSK9fWIIv2UOGG1U9r2YvT1I3UFusWNLoQ== X-Google-Smtp-Source: ACJfBovQ6Mf+z1K940QBRkGtgDDVTPvo9LYOFFIVYLMzUGecXwrXDcPPyNDqncnFqnAeBcVg9Bk2/brgNkFXibiXobU= X-Received: by 10.157.33.134 with SMTP id s6mr14090199otb.10.1513540863053; Sun, 17 Dec 2017 12:01:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.39.47 with HTTP; Sun, 17 Dec 2017 12:00:22 -0800 (PST) From: Lee D Date: Sun, 17 Dec 2017 15:00:22 -0500 Message-ID: Subject: How do I alloc multiple memory regions specified in a device tree? To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Dec 2017 20:01:04 -0000 Hi everyone. I have a device driver that must access registers in multiple memory ranges. How do I pull those values out of the device tree? This is for a custom ARM embedded board. bus_alloc_resource_any() works, but only for the first memory range. The second time I call it, it crashes the kernel. If I alloc the same memory resources by hardcoding the values in calls to bus_alloc_resource(), it works. The technique of calling bus_alloc_resource_any() multiple times is used in src/sys/dev/sdhci/sdhci_fdt.c, but I can't get it to work. Here is a snippet from my device tree: ... fabric@40000000 { device_type = "soc"; compatible = "simple-bus"; #address-cells = <0x1>; #size-cells = <0x1>; ranges = <0x0 0x40000000 0x5000000>; my_lcd@3C00000 { status = "okay"; compatible = "xlnx,my_lcd"; reg = <0x3C00000 0x1000 0x400000 0x1000 0x3000000 0x1000>; interrupts = <0x0 0x1d 0x1>; interrupt-parent = <0x1>; }; ... Here is my driver code from my_lcd_attach: rid=0; sc->lcd_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->lcd_mem_res == NULL) { my_lcd_detach(dev); return (ENOMEM); } rid=0; sc->dma_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->dma_mem_res == NULL) { my_lcd_detach(dev); return (ENOMEM); } Thank you.