From owner-freebsd-drivers@FreeBSD.ORG Mon Sep 16 02:04:38 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E8078811 for ; Mon, 16 Sep 2013 02:04:37 +0000 (UTC) (envelope-from lnrdpss@gmail.com) Received: from mail-vb0-x230.google.com (mail-vb0-x230.google.com [IPv6:2607:f8b0:400c:c02::230]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A81112347 for ; Mon, 16 Sep 2013 02:04:37 +0000 (UTC) Received: by mail-vb0-f48.google.com with SMTP id w16so2377956vbf.21 for ; Sun, 15 Sep 2013 19:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=lN2yuo/a2aG9QfTshnU0m41yiqUd8zPyyWyhUrrVnM8=; b=wrxH5oAaAQ4TLQxTP2CpeDmZnN2Nm+EPOLStAohdomW9T8jSUVZbQnpPdyyBVY8Ydq yP4dmhDiM1dm8N//l6xpiMgZH73Zs+KYzzevfB0AVesD4qRr4WxsFdq731bPTuesR8qN s/XTMKBELfU1RKnniz9QuKCPy0/MQ1enuCwSHQUFnWZRgPWcoFXrKuZsvtXWMGN8i0rH hYFHEqKCwmhPFUcn/XF5cCXF0Ra9Oo8j4PmoS8e78+WZUFinv3VzOtakZfa8YvvL6dVX C/ACbybDFfX7bPyzSuYjcuDXzASZ5PsJoYfVSyO50zSbqKpMm351jV84A2V0qSOVBYAN tejQ== MIME-Version: 1.0 X-Received: by 10.52.110.98 with SMTP id hz2mr19916175vdb.1.1379297076657; Sun, 15 Sep 2013 19:04:36 -0700 (PDT) Received: by 10.221.17.130 with HTTP; Sun, 15 Sep 2013 19:04:36 -0700 (PDT) Date: Sun, 15 Sep 2013 22:04:36 -0400 Message-ID: Subject: ATA drivers From: Leonardo Passos To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Sep 2013 02:04:38 -0000 Hi there, I am currently investigating drivers in FreeBSD, with a particular focus on ATA. However some doubts came up, and since I could not find my answers in existing documentation, I would like to clarify some points. In particular, I would like to verify whether my current understanding is correct. Suppose I want to implement a "foo" driver in two specific scenarios: Scenario 1) Support for an ATA bus "To support an ATA-based device, I needed a proper driver. The driver, in this case, is a driver for an ATA bus. My driver has to work with specific controllers, which must be checked in the probe function of the driver. Upon successful probe, the attach function is called, in which case my driver sets specific configurations that are dependent on the previously checked controller. In the end of the probe, method, I register the the new device (e.g., a hardisk) by calling ata_attach". Example driver: sys/powerpc/powermac/ata_macio.c Scenario2) Support for ATA on top of PCI "In this case, my driver stands for an ATA-controller that is plugged into the PCI bus. In such a case, my driver must use ATA_DECLARE_DRIVER(foo), instead of the DRIVER_MODULE macro (as it occurred in scenario 1). Further, I must declare a function foo_probe, as required by the ATA_DECLARE_DRIVER (see ata-pci.h). In the probe function, I verify whether the device (an ATA controller, not a disk) is supported, and if so, set its chipinit function pointer (this field is part of ata_pci_controller instance, gotten by calling device_get_softc on the newly identified controller). In the chipinit function, I set an attach function for that ATA controller (this is performed by setting the ch_attach field over the ata_pci_controller instance). The registered attach function will be called whenever new disks are attached to the bus of the added ATA controller. That function in turn, will set any configuration parameters and add a new disk into the system, by calling ata_pci_ch_attach". Example drivers: sys/dev/ata/chipsets/ata-amd.c sys/dev/ata/chipsets/ata-intel.c Is the workflow just described correct? Stated otherwise, when supporting ATA devices, should I only be concerned with implementing proper bus support, that in turn, will register its managed disks? In that sense, I, as a driver developer, do not need to concern about how IO is actually performed, as the driver infrastructure of the kernel will handle any attached disk once it is configured by a bus driver? Thanks, Leo.