From owner-freebsd-drivers@freebsd.org Thu Jun 4 19:39:38 2020 Return-Path: Delivered-To: freebsd-drivers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 95A8332F28A for ; Thu, 4 Jun 2020 19:39:38 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49dGLx4lDxz4frG for ; Thu, 4 Jun 2020 19:39:37 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x82a.google.com with SMTP id w9so6354994qtv.3 for ; Thu, 04 Jun 2020 12:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4mmpTLBUXlHbgG8nq1J56S8CibDRwEOOA1UUcOKtaec=; b=atqXz9NFzUbGAjr77O60+ZAmypwkilFOVM1+jEpjF4PvaZVBomjToGvcvLQC43P3fS nK8wCtPaYLjxe7tpKFCjV6SaeVNW8Rj6kRUMna8TXczC4xAdxhuHEm+9xZHZTHaNouee WfwXehkFvmTNxqqf17uyB1veLd7tWz7doW5j7wIfX8ivTopjtK5rMbSky3unlIPcoUbM 78oAqFaK+UzWDSXiFiTcD11BBjaz+/ej2PYLMdB2C3IchqFXfyvQI9bY3u0gfQrMIoLL hKmt4iVBpma+O+UL9cReiY30q3ySaf/HPbKvT8IOadHYlBRRzZJg6sbpBT/S8wfVikF0 cIVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4mmpTLBUXlHbgG8nq1J56S8CibDRwEOOA1UUcOKtaec=; b=smmP+5g+TUHMgVyH89PT0JOPQs+i+jEQjRhpYnSTu8oh0kc3Vi4azlv5stX+G4QfJF dxLeS0Vz5mQOHWRlIXCLkNiiNjfYyTNKodydwmOF0fwMAjNzatb4avIL3CeH+TaQwTzk iEnyCCJCBRMgA07bfjHBBAnAaIG5NpUsAdcKdutZbv+OEmqaAaqebBIszjtkxF5J4ZA2 GI0XxwH4YpBCgJaRCzSqcvRWHq91sc2cqHLFMViz61TX2etlLA2dyoiTb68KbWBh2PpM 8MbL8INTnUa4zkgKCcacuenAbxjL6i2L0+Los1x6WOwj16mFrouwaSHhnsgIe/4yun9O wKvg== X-Gm-Message-State: AOAM5327DTpILPRgb/aPATYbBoi5+ZcZC6/LYJA+EWCoWq8qmiFzdkZD zm81p6snUjxJoGrO/qM/wtwTuQIlhnMWkEcmjH6mXg== X-Google-Smtp-Source: ABdhPJwCv9/RW/HTTU+Kp+20mak2zHHsXRHXkLH8PuFvyU4EbXnyCaPZkA9T6Ml6yr8CepKLSlopiLIqiSUJ9+FI7zQ= X-Received: by 2002:ac8:192c:: with SMTP id t41mr5953313qtj.32.1591299576374; Thu, 04 Jun 2020 12:39:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Thu, 4 Jun 2020 13:39:25 -0600 Message-ID: Subject: Re: Can we hook a device as device to two different parent devices? To: Rajesh Kumar Cc: Andriy Gapon , freebsd-drivers@freebsd.org, FreeBSD Hackers X-Rspamd-Queue-Id: 49dGLx4lDxz4frG X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20150623.gappssmtp.com header.s=20150623 header.b=atqXz9NF; dmarc=none; spf=none (mx1.freebsd.org: domain of wlosh@bsdimp.com has no SPF policy when checking 2607:f8b0:4864:20::82a) smtp.mailfrom=wlosh@bsdimp.com X-Spamd-Result: default: False [-0.64 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com:s=20150623]; NEURAL_HAM_MEDIUM(-0.89)[-0.895]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-0.96)[-0.958]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-drivers@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; NEURAL_SPAM_SHORT(0.21)[0.209]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::82a:from]; R_SPF_NA(0.00)[no SPF record]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; SUBJECT_ENDS_QUESTION(1.00)[]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jun 2020 19:39:38 -0000 On Thu, Jun 4, 2020 at 12:31 PM Rajesh Kumar wrote: > Thanks Warner and Andriy for your answers. > > Having said they are two separate instances, if the child driver calls the > interface of two parents as below > device1_interface(child_dev), then device_get_parent(child_dev) in the > device1 interface will return device1 reference > device2_interface(child_dev), then device_get_parent(child_dev) in the > device2 interface will return device2 reference > > Is that right? > Yes. That's correct. For each bus instance, we loop through the possible drivers that attach to that bus looking for each device looking for drivers that will probe successfully. If you have multiple instances, or instances of different kinds of busses, what you say will hold true. Warner > Thanks, > Rajesh. > > > On Wed, Jun 3, 2020 at 8:59 PM Warner Losh wrote: > >> >> >> On Wed, Jun 3, 2020, 8:29 AM Andriy Gapon wrote: >> >>> On 03/06/2020 14:20, Rajesh Kumar wrote: >>> > Hi, >>> > >>> > Is it really possible to declare a module with two parents? Like the >>> > following declarations in the same driver. >>> > >>> > devclass_t test_dev_devclass; >>> > static DEFINE_CLASS_0(test_dev, test_dev_driver, test_dev_methods, >>> > sizeof(struct test_dev_ctx)); >>> > DRIVER_MODULE(test_dev, *device1*, test_dev_driver, test_dev_devclass, >>> > NULL, NULL); >>> > DRIVER_MODULE(test_dev, *device2*, test_dev_driver, test_dev_devclass, >>> > NULL, NULL); >>> > >>> > I see similar references in other drivers attaching to both simpleus >>> and >>> > ofwbus. So, If it's possible, how to get the reference for both the >>> > parents? device_get_parent(test_dev) will give reference of one parent >>> > only right, so how to get the reference of the desired parent? >>> >>> A device can have only one parent. >>> The declaration you quoted describes a _driver_ that can attach to >>> devices >>> hanging off two different buses. They would still be different devices. >>> >> >> Yes. You can have a driver attach to multiple bus types, but each >> instance has a unique parent one exactly on of them. >> >> If you need to talk to other devices, you'll need to find them by name or >> other means. >> >> Warner >> >> >> >>> -- >>> Andriy Gapon >>> _______________________________________________ >>> freebsd-drivers@freebsd.org mailing list >>> https://lists.freebsd.org/mailman/listinfo/freebsd-drivers >>> To unsubscribe, send any mail to " >>> freebsd-drivers-unsubscribe@freebsd.org" >>> >>