From owner-freebsd-drivers@freebsd.org Mon Jul 24 21:51:31 2017 Return-Path: Delivered-To: freebsd-drivers@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 0FD0ADA936C for ; Mon, 24 Jul 2017 21:51:31 +0000 (UTC) (envelope-from kyenduri@brkt.com) Received: from mail-pg0-x231.google.com (mail-pg0-x231.google.com [IPv6:2607:f8b0:400e:c05::231]) (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 E03FC7E276 for ; Mon, 24 Jul 2017 21:51:30 +0000 (UTC) (envelope-from kyenduri@brkt.com) Received: by mail-pg0-x231.google.com with SMTP id v190so62459499pgv.2 for ; Mon, 24 Jul 2017 14:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brkt.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=RIwSkBEvbJ3LI06hspuSpqWgVxblpkZg24uvMvicA2o=; b=cxIHW/Okx4sl27cOYxenuRKAAdaKNL59L0imdXb6Hkyrx8VUj93frNF3f3xDfsROS+ ECX25ZhtIPnljk6/HDeyjb7SBXAtfD3jlfmCPTbPK5MD9/Fstg/rvtfbkvC7U2sv7Ctz JVIfzmknBIY/ZRXAAhTZ0rWLqIqoAUWFBsq8I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=RIwSkBEvbJ3LI06hspuSpqWgVxblpkZg24uvMvicA2o=; b=VF+BIlB3J6HIZe4yS0v+W557ywB2Yk+/7t/NTvQoRCkPDcfZy6zg2W4AhporPUq96h 0JgnjIE1cUZr5g2fTFKt5HbnbbJD9VGKRvzZBBdpZWbyOqD5h4XD4TPKslSwkpmaHF55 mz7UaIXDEe3ibdpSUlJ7k2kFMaeV3B6fm8h3GhooZ5zCna9dK1s8F4Dlq8gtWtTIzk4I 9KHSzOFjqFYH2hQePychsN830EryY+1cs8If1YnIqHXe2qO3Hu8NFqdWCIfgmbP/zhz4 t7pxLo9R9dC9YrAKymeqjxX4GqvT99uvrBTPnufor6PXzwssi29uycm3maa4Uz5H0fn9 MLZQ== X-Gm-Message-State: AIVw112le/Mq0MgKfSDkCJcNTAo7oHnqFH7JOF17urpMe8UAOOvooQ9A WpB2J/SP81x8+1Cf X-Received: by 10.98.106.6 with SMTP id f6mr17543646pfc.53.1500933090303; Mon, 24 Jul 2017 14:51:30 -0700 (PDT) Received: from krishnas-mbp.int.brkt.com (cerberus.brkt.com. [208.185.168.138]) by smtp.gmail.com with ESMTPSA id t78sm25151353pfa.48.2017.07.24.14.51.29 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Jul 2017 14:51:29 -0700 (PDT) Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: ACPI mediated Hotplug? From: Krishna Yenduri In-Reply-To: <3585281.TQq0CdjIrL@ralph.baldwin.cx> Date: Mon, 24 Jul 2017 14:51:28 -0700 Cc: freebsd-drivers@freebsd.org Message-Id: References: <3DDBEFB3-AB51-4AD2-845D-A8B81ECB417A@brkt.com> <3585281.TQq0CdjIrL@ralph.baldwin.cx> To: John Baldwin X-Mailer: Apple Mail (2.3124) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jul 2017 21:51:31 -0000 > On Jul 20, 2017, at 10:19 AM, John Baldwin wrote: >=20 > On Monday, May 22, 2017 11:12:43 AM Krishna Yenduri wrote: >> ... >> Is there a way to use the ACPI framework in FreeBSD so >> that the Hotplug happens automatically? >>=20 >> DTracing shows that adding a new interface triggers calls to >> AcpiEvSciXruptHandler and AcpiEvAsynchExecuteGpeMethod. >> Is it safe to add a hook in to pci_rescan_method() from these >> routines? Any pointers to the ACPI<->FreeBSD kernel interface >> are much appreciated. >=20 > It is possible to support HotPlug via ACPI, however it is a bit more = involved > than that. Agreed. Specifically, Hotplug detach is not triggering any ACPI calls. So, even if I modify AcpiEvSciXruptHandler () to get auto attach to work, auto detach will not work. > There are ACPI methods for handling hotplug that are generic to > ACPI (not PCI specific) which on some systems handle PCI hotplug. I = believe > there is a section discussing it in the ACPI spec. More details are = present in > the "Device Insertion, Removal, and Status Objects" section of the = "Device > Configuration" section of the ACPI spec (at least as of 6.1). Thanks! I assume Intel folks wrote the ACPI code in FreeBSD and Linux. It looks the Linux ACPI code is enhanced to support this ACPI mediated = HotPlug (*). > You might be > able to make this work by installing a notify handler in the ACPI PCI = bus > driver (sys/dev/acpica/acpi_pci.c) and triggering a rescan in response = to > notifications with a value of 0. Something like this perhaps = (untested): Thanks! Much appreciated. I tried this patch (after fixing a few nits). But, it did not work. DTracing shows that acpi_pcib_notify_handler does not get called. Regards, -Krishna * I traced the ACPI calls on Linux using ebpf and it supports the above = theory - # ./trace -K pci_enable_device PID TID COMM FUNC 5 5 kworker/u30:0 pci_enable_device pci_enable_device+0x1 [kernel] local_pci_probe+0x45 [kernel] pci_device_probe+0x103 [kernel] driver_probe_device+0x2bb [kernel] __device_attach_driver+0x8c [kernel] bus_for_each_drv+0x67 [kernel] __device_attach+0xdd [kernel] device_attach+0x10 [kernel] pci_bus_add_device+0x4f [kernel] pci_bus_add_devices+0x39 [kernel] enable_slot+0x26f [kernel] acpiphp_hotplug_notify+0x14f [kernel] acpi_device_hotplug+0x388 [kernel] acpi_hotplug_work_fn+0x1e [kernel] process_one_work+0x1fc [kernel] worker_thread+0x4b [kernel] kthread+0x101 [kernel] ret_from_fork+0x2c [kernel] # ./trace -K pci_enable_device pci_disable_device PID TID COMM FUNC 41 41 kworker/u30:1 pci_disable_device pci_disable_device+0x1 [kernel] pci_device_remove+0x39 [kernel] device_release_driver_internal+0x155 [kernel] device_release_driver+0x12 [kernel] pci_stop_bus_device+0x8a [kernel] pci_stop_and_remove_bus_device+0x12 [kernel] disable_slot+0x4f [kernel] acpiphp_disable_and_eject_slot+0x1d [kernel] acpiphp_hotplug_notify+0x9c [kernel] acpi_device_hotplug+0x388 [kernel] acpi_hotplug_work_fn+0x1e [kernel] process_one_work+0x1fc [kernel] worker_thread+0x4b [kernel] kthread+0x101 [kernel] ret_from_fork+0x2c [kernel]