From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=17.151.62.27; helo=mail-in5.apple.com; envelope-from=afish@apple.com; receiver=edk2-devel@lists.01.org Received: from mail-in5.apple.com (mail-out5.apple.com [17.151.62.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D96FB21E2568D for ; Thu, 25 Jan 2018 10:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1516907072; x=2380820672; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-version:Content-type: Content-transfer-encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-reply-to:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lE4WAQzhJjj2JkAUoazK+4/yYk0wA54MSscgiSYQmws=; b=WsIctVIYsyF9+k/9UtJ7pZydShbiuNWCYVFg7fVXDSUDn98pizP+dXGumv0LdZNX qM8xkFMZo0KWdIVOVYGsaO1WS+7TBa9jaYg94kmrCeqkwYiOjrJH29ZZCp5jW+km R0+kVBGc0I8o0uJUd/dPj6L7vMa7OQjcluQc3pWMmTmwucNAeVV7NhRwFu7EJm76 nmOpPglc6nsba6M+RNbiCnWg2vVolJBjd7yFQCZTgV8itZVBaHNA3VnxFmK3CSUP rAamj3KEJBtM/s2QeAVmhNnHNgAkmgBV+tx83SWzsgpmSceaskykQKAsRcfu5OV5 qP7tgJu4TlxM9N81lZyKXA==; Received: from relay8.apple.com (relay8.apple.com [17.128.113.102]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail-in5.apple.com (Apple Secure Mail Relay) with SMTP id 77.43.14264.04A2A6A5; Thu, 25 Jan 2018 11:04:32 -0800 (PST) X-AuditID: 11973e13-066cc9e0000037b8-03-5a6a2a4028e6 Received: from nwk-mmpp-sz10.apple.com (nwk-mmpp-sz10.apple.com [17.128.115.122]) by relay8.apple.com (Apple SCV relay) with SMTP id C3.26.22651.04A2A6A5; Thu, 25 Jan 2018 11:04:32 -0800 (PST) MIME-version: 1.0 Received: from da0601a-dhcp59.apple.com ([17.226.15.59]) by nwk-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.1.20180104 64bit (built Jan 4 2018)) with ESMTPSA id <0P3400LKUKZJTS30@nwk-mmpp-sz10.apple.com>; Thu, 25 Jan 2018 11:04:32 -0800 (PST) Sender: afish@apple.com From: Andrew Fish In-reply-to: Date: Thu, 25 Jan 2018 11:04:31 -0800 Cc: "edk2-devel@lists.01.org" Message-id: References: To: Rafael Machado X-Mailer: Apple Mail (2.3445.5.20) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJLMWRmVeSWpSXmKPExsUi2FCYpuuglRVlcG06j8WeQ0eZLXa+nMHu wOSxc9Zddo/u2f9YApiiuGxSUnMyy1KL9O0SuDIe3brNWLBMreLWs4WMDYx/JbsY2TkkBEwk FsR0MXJxCAmsYZLY+mkjcxcjJ1j427U7TBCJQ4wS+w+dYARJ8AoISvyYfI+li5GDg1lAXWLK lFyImolMEv+mTmAFqREWEJd4d2YTM4RtI7Flzkw2EJtNQFlixfwP7CA2p0CwxL9HZ8BsFgFV iRdfjzKB2MwC5hIzLnyBsrUlnry7wAqx10biwcYGsDlCAgES/ef6WEBsEQEzib2zJrBDHK0k Mf37bTaQgyQEGtkkVrzZzTqBUXgWkrtnIdw9C8mKBYzMqxiFchMzc3Qz80z1EgsKclL1kvNz NzGCwnq6nfAOxtOrrA4xCnAwKvHw3ridGSXEmlhWXJl7iFGag0VJnHetUlaUkEB6Yklqdmpq QWpRfFFpTmrxIUYmDk6pBkbdLfIZ05Tetx2WO9Avk+MTuff4hbMChQatd64LZQUp3MhR3yp0 5WWIgV3L0fSJSVfCt5RPWH79BFNu1NmolRqqy85Ui81Zcnzuvpl3zJubphaveBjy7s9urphZ n3tMvMOOPPvy2iDPwOzYnze9Kr/nbNxVZ8r04einIN8Kp80ijl0fxVrvKjUqsRRnJBpqMRcV JwIASSpLKUwCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHLMWRmVeSWpSXmKPExsUi2FBcpeuglRVlMGkTh8WeQ0eZLXa+nMHu wOSxc9Zddo/u2f9YApiiuGxSUnMyy1KL9O0SuDIe3brNWLBMreLWs4WMDYx/JbsYOTkkBEwk vl27w9TFyMUhJHCIUWL/oROMIAleAUGJH5PvsXQxcnAwC6hLTJmSC1EzkUni39QJrCA1wgLi Eu/ObGKGsG0ktsyZyQZiswkoS6yY/4EdxOYUCJb49+gMmM0ioCrx4utRJhCbWcBcYsaFL1C2 tsSTdxdYIfbaSDzY2AA2R0ggQKL/XB8LiC0iYCaxd9YEdoijlSSmf7/NNoFRYBaSU2chnDoL ydQFjMyrGAWKUnMSKy30EgsKclL1kvNzNzGCQ7EwbQdj03KrQ4wCHIxKPLwNNzOjhFgTy4or c4FhwcGsJMK7UywrSog3JbGyKrUoP76oNCe1+BCjNAeLkjhvwo2UKCGB9MSS1OzU1ILUIpgs EwenVAOjmvtksbbaaIW1j3LfhzxnMr/dq8g4IfL4t1PT1ALePrxVL/joea7KG6Hwie9rOF/d EmwL/TCNc/eksEsPEj7tZJyQf2mH/odOgxvBZR4v3d5xCOkkXX+SvNhk37uPcd/CG9+2vynp 1u7j+hL1ZQ6n/5H7z9RDZ/TYaBswXZOZ8OXOtaJlFdVpSizFGYmGWsxFxYkAIH6hrkECAAA= 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 18:59:03 -0000 Content-type: text/plain; charset=utf-8 Content-transfer-encoding: quoted-printable Rafeal, There are some good summaries in the UEFI Spec that really help.=20 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 = Map(). =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.=20 For ARM it may need to change the cacheability of the region etc.=20 Thanks, Andrew Fish > On Jan 25, 2018, at 10:53 AM, Rafael Machado = wrote: >=20 > Hi everyone. >=20 > 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 = of > how to do that. >=20 > Considering that code and adapting to my scenario I got the following > function (some debug prints are present for clarification): >=20 > 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; >=20 > // > // 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 >=20 > EfiPciIoOperationBusMasterCommonBuffer, // Operation > (VOID *)HostAddress, // = HostAddress > &NumberOfBytes, // NumberOfBytes > &DeviceAddress, //DeviceAddress > &Mapping //Mapping); >=20 > if (EFI_ERROR (Status)) { > return Status; > } >=20 > // > // 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 > ); >=20 > 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); >=20 > if (EFI_ERROR (Status)) { > return Status; > } >=20 > // > // 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); >=20 > if (EFI_ERROR (Status)) { > return Status; > } >=20 > // > // Call Flush() to flush all write transactions to system memory > // > Status =3D PciIo->Flush (PciIo); > Print(L"Status3: %r\r\n", Status); >=20 > if (EFI_ERROR (Status)) { > return Status; > } >=20 > // > // Call Unmap() to complete the bus master write operation > // > Status =3D PciIo->Unmap (PciIo, Mapping); > Print(L"Status4: %r\r\n", Status); >=20 > if (EFI_ERROR (Status)) { > return Status; > } > return Status; > } >=20 > The output of this function is this: > NumberOfBytes: 4 > address: 0xCCCAC000 > Value: 0xAAAAA > Status: Success > Status2: Success > Status3: Success > Status4: Success >=20 > The problem is that when I try to read this memory content using the = dmem > command at the efiShell the value 0xAAAAA cannot be found. Seems = something > is locking the DMA trasaction. > Can someone give me some light? >=20 > Thanks and Regard > Rafael R. Machado > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel