From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::22b; helo=mail-qt0-x22b.google.com; envelope-from=rafaelrodrigues.machado@gmail.com; receiver=edk2-devel@lists.01.org Received: from mail-qt0-x22b.google.com (mail-qt0-x22b.google.com [IPv6:2607:f8b0:400d:c0d::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1625D21E25691 for ; Thu, 25 Jan 2018 11:09:43 -0800 (PST) Received: by mail-qt0-x22b.google.com with SMTP id s39so21958920qth.7 for ; Thu, 25 Jan 2018 11:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=f8oOnLyxgm1E4dAmXHi+cLU/lU6Gt0ddlUIs+vzQAEY=; b=oUMHZN6IhwBQobw+42gdMzf/vdpbmvyWRzui8HWZ+ccT7pZVzTPmCVT6V3M+lk9UxY JT6X6mOUihVvFKKvsgcW8kqF+QaGHvRAR95CmLSbtKhZlACXQx0QZcIHwR6B07BV0T2O tEovZtShdIcqchYKjBOtt9/1ZyRE7K/LYLHzofmXjB/Yw8Io8EntJwJM5GNFO1IZeTzB qCiqMpsLzmtEHyc1dZ830/AldM40MJ2UD0kY+v3hY6BYXmjIJr2SyRdwOsn8UEy+q5JV cTZI+OWNPBL5qWY0JjgdHGmH8vyxMeJ8/5mQ3H2LTYjZFrh0rhFYzSKzewlSmPDpIF5d LGUg== 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=f8oOnLyxgm1E4dAmXHi+cLU/lU6Gt0ddlUIs+vzQAEY=; b=XptNiqE/SLh+Gx6VSULkzJI/3wPEb2Ee/cuXqjU8RUaZEqT0ksaTI6oR+kXhzWRFKn ZXCAxLMOUrd7JatKvg3x60ey+vQiEyDeLvp1WrPWovXaLbRuHqC/ToFqML6GE2K5ipJv uAm/olQNOUjwxo6qA0/otYT7/0jEgXpXi0mN/2hI2te36AcSGOZZNa8Wg/Oz0rnfBwyX 0KDK3mSmHz18AobOYyqHRyge+bkQo/vPfVhlawW5cqCdGJdg35eGjF36CcllzorL+8BI VxatFwGBhTSHm9KU+pXXVyzY6L9l0mEAmilheieWL4GUq+2nxoiWxPxcrRsTvNEt04iB 13ww== X-Gm-Message-State: AKwxytf1i+zCuq9leAkqeynmDYQKPRj52h4rAG7SqjHEOBFs0DPLyL/T Yl6MMT87XYu+3GrdLWiDcr2+BwmYtrT5FGzeQWA= X-Google-Smtp-Source: AH8x226JnBE/viPzWGlcnq2zYoP56/uF5daONFPXJ4FGZK/ML0oUXSDyZER3YA2fAZpprG4NNf4pm7dkVlMZS7B6mqo= X-Received: by 10.200.51.225 with SMTP id d30mr18527271qtb.338.1516907712787; Thu, 25 Jan 2018 11:15:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Rafael Machado Date: Thu, 25 Jan 2018 19:15:02 +0000 Message-ID: To: Andrew Fish Cc: "edk2-devel@lists.01.org" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: Re: DMA Buffer write operation not persisted X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jan 2018 19:09:44 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Andrew Thanks for the answer. The allocation was done at other part of the code. But yet, I used the PciI->AllocateBuffer() function. One question, about the topics retrieved from the spec. When the spec says "=E2=80=A2 The common buffer can now be accessed equally= by the processor and the DMA bus master." Does this means that I can write some data using a simple pointer, like for example copying some data using MemCopy? Or should I still use the PciIo->Mem.Write...? I'll really this part of the spec carefully. Thanks and Regards Rafael R. Machado Em qui, 25 de jan de 2018 =C3=A0s 17:04, Andrew Fish escr= eveu: > Rafeal, > > There are some good summaries in the UEFI Spec that really help. > > DMA Bus Master Common Buffer Operation > =E2=80=A2 Call AllocateBuffer() to allocate a common buffer. > =E2=80=A2 Call Map() for EfiPciOperationBusMasterCommonBuffer or > EfiPciOperationBusMasterCommonBuffer64. > =E2=80=A2 Program the DMA Bus Master with the DeviceAddress returned by M= ap(). > =E2=80=A2 The common buffer can now be accessed equally by the processor = and the > DMA bus master. > =E2=80=A2 Call Unmap(). > =E2=80=A2 Call FreeBuffer(). > > Did you miss the PciIo->AllocateBuffer() call? > > For x86 it can abstract things like DMA only supported < 4GB. > For ARM it may need to change the cacheability of the region etc. > > Thanks, > > Andrew Fish > > > On Jan 25, 2018, at 10:53 AM, Rafael Machado < > rafaelrodrigues.machado@gmail.com> wrote: > > > > Hi everyone. > > > > I'm currently work on a task, and I need to write some data at a DMA > buffer. > > At the UEFI Driver Writer's guide, at page 359 there is a sample code o= f > > how to do that. > > > > Considering that code and adapting to my scenario I got the following > > function (some debug prints are present for clarification): > > > > EFI_STATUS > > EFIAPI > > DoBusMasterWrite ( > > IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciIo, > > IN UINT8 *HostAddress, > > IN UINTN *Length, > > IN UINT32 Value > > ) > > { > > EFI_STATUS Status; > > UINTN NumberOfBytes; > > EFI_PHYSICAL_ADDRESS DeviceAddress; > > VOID *Mapping; > > UINT64 ReadValue; > > > > // > > // Call Map() to retrieve the DeviceAddress to use for the bus > > // master write operation. The Map() function may not support > > // performing a DMA operation for the entire length, so it may > > // be broken up into smaller DMA operations. > > // > > NumberOfBytes =3D *Length; > > Status =3D PciIo->Map (PciIo, // This > > > > EfiPciIoOperationBusMasterCommonBuffer, // Operation > > (VOID *)HostAddress, // HostAddress > > &NumberOfBytes, // NumberOfBytes > > &DeviceAddress, //DeviceAddress > > &Mapping //Mapping); > > > > if (EFI_ERROR (Status)) { > > return Status; > > } > > > > // > > // Write the data to the desired address > > // This write operation also starts the DMA transaction > > // > > Status =3D PciIo->Mem.Write (PciIo, // This > > EfiPciIoWidthUint32, // > Width > > *HostAddress, > > 1, // Count > > &Value // Buffer > > ); > > > > Print(L"NumberOfBytes: %d\r\n", NumberOfBytes); > > Print(L"address: 0x%x\r\n", HostAddress); > > Print(L"Value: 0x%x\r\n", Value); > > Print(L"Status: %r\r\n", Status); > > > > if (EFI_ERROR (Status)) { > > return Status; > > } > > > > // > > // The operations performed by PollMem() also flush all posted > > // writes from the PCI bus master and through PCI-to-PCI bridges. > > // > > Status =3D PciIo->PollMem (PciIo, // This > > EfiPciIoWidthUint32, // > Width > > *HostAddress, // Offset > > 0xFFFFFFFF,// Mask > > Value,// Value > > EFI_TIMER_PERIOD_SECONDS > > (1), // Timeout > > &ReadValue // Result > > ); > > Print(L"Status2: %r\r\n", Status); > > > > if (EFI_ERROR (Status)) { > > return Status; > > } > > > > // > > // Call Flush() to flush all write transactions to system memory > > // > > Status =3D PciIo->Flush (PciIo); > > Print(L"Status3: %r\r\n", Status); > > > > if (EFI_ERROR (Status)) { > > return Status; > > } > > > > // > > // Call Unmap() to complete the bus master write operation > > // > > Status =3D PciIo->Unmap (PciIo, Mapping); > > Print(L"Status4: %r\r\n", Status); > > > > if (EFI_ERROR (Status)) { > > return Status; > > } > > return Status; > > } > > > > The output of this function is this: > > NumberOfBytes: 4 > > address: 0xCCCAC000 > > Value: 0xAAAAA > > Status: Success > > Status2: Success > > Status3: Success > > Status4: Success > > > > The problem is that when I try to read this memory content using the dm= em > > command at the efiShell the value 0xAAAAA cannot be found. Seems > something > > is locking the DMA trasaction. > > Can someone give me some light? > > > > Thanks and Regard > > Rafael R. Machado > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > >