From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>,
Sreedhar Telukuntla <sreedhar.telukuntla@intel.com>,
igt-dev@lists.freedesktop.org
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 1/2] lib/i915/gem_mman: Add coherent mmap api support with set domain
Date: Fri, 28 Feb 2020 11:06:24 +0000 [thread overview]
Message-ID: <3f8e375c-dc04-f5d6-5364-a025f8167720@linux.intel.com> (raw)
In-Reply-To: <158195696525.19707.9349580960052193744@skylake-alporthouse-com>
On 17/02/2020 16:29, Chris Wilson wrote:
> Quoting Sreedhar Telukuntla (2020-02-18 00:17:09)
>> gem_mmap__device_coherent_domain api maps buffer object and returns
>> the memory domain to be used by the caller for subsequent set_domain
>> call for cpu access.
>>
>> gem_mmap__device_coherent_sync api maps buffer object and also does
>> set_domain to make the memory ready for cpu access.
>>
>> Signed-off-by: Sreedhar Telukuntla <sreedhar.telukuntla@intel.com>
>> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>> ---
>> lib/i915/gem_mman.c | 76 ++++++++++++++++++++++++++++++++++++++++++---
>> lib/i915/gem_mman.h | 6 +++-
>> 2 files changed, 77 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
>> index 08ae6769..b8d20c07 100644
>> --- a/lib/i915/gem_mman.c
>> +++ b/lib/i915/gem_mman.c
>> @@ -345,21 +345,25 @@ void *gem_mmap_offset__wc(int fd, uint32_t handle, uint64_t offset,
>> * @offset: offset in the gem buffer of the mmap arena
>> * @size: size of the mmap arena
>> * @prot: memory protection bits as used by mmap()
>> + * @domain: cache domain used for mmap
>> *
>> * Returns: A pointer to a block of linear device memory mapped into the
>> * process with WC semantics. When no WC is available try to mmap using GGTT.
>> */
>> void *__gem_mmap__device_coherent(int fd, uint32_t handle, uint64_t offset,
>> - uint64_t size, unsigned prot)
>> + uint64_t size, unsigned prot, uint32_t *domain)
>> {
>> void *ptr = __gem_mmap_offset(fd, handle, offset, size, prot,
>> I915_MMAP_OFFSET_WC);
>> if (!ptr)
>> ptr = __gem_mmap__wc(fd, handle, offset, size, prot);
>>
>> - if (!ptr)
>> - ptr = __gem_mmap__gtt(fd, handle, size, prot);
>> + *domain = I915_GEM_DOMAIN_WC;
>>
>> + if (!ptr) {
>> + ptr = __gem_mmap__gtt(fd, handle, size, prot);
>> + *domain = I915_GEM_DOMAIN_GTT;
>> + }
>> return ptr;
>> }
>>
>> @@ -382,15 +386,79 @@ void *gem_mmap__device_coherent(int fd, uint32_t handle, uint64_t offset,
>> uint64_t size, unsigned prot)
>> {
>> void *ptr;
>> + uint32_t domain;
>>
>> igt_assert(offset == 0);
>>
>> - ptr = __gem_mmap__device_coherent(fd, handle, offset, size, prot);
>> + ptr = __gem_mmap__device_coherent(fd, handle, offset, size, prot, &domain);
>> igt_assert(ptr);
>>
>> return ptr;
>> }
>>
>> +/**
>> + * gem_mmap__device_coherent_domain:
>> + * @fd: open i915 drm file descriptor
>> + * @handle: gem buffer object handle
>> + * @offset: offset in the gem buffer of the mmap arena
>> + * @size: size of the mmap arena
>> + * @prot: memory protection bits as used by mmap()
>> + * @domain: memory domain to be used by the caller for set_domain after mmap
>> + *
>> + * Call __gem_mmap__device__coherent_domain(), asserts on fail.
>> + * Offset argument passed in function call must be 0. In the future
>> + * when driver will allow slice mapping of buffer object this restriction
>> + * will be removed.
>> + *
>> + * Returns: A pointer to the created memory mapping.
>> + */
>> +void *gem_mmap__device_coherent_domain(int fd, uint32_t handle, uint64_t offset,
>> + uint64_t size, unsigned prot, uint32_t *domain)
>> +{
>> + void *ptr;
>> +
>> + igt_assert(offset == 0);
>> +
>> + ptr = __gem_mmap__device_coherent(fd, handle, offset, size, prot, domain);
>> + igt_assert(ptr);
>> +
>> + return ptr;
>> +}
>> +
>> +/**
>> + * gem_mmap__device_coherent_sync:
>> + * @fd: open i915 drm file descriptor
>> + * @handle: gem buffer object handle
>> + * @offset: offset in the gem buffer of the mmap arena
>> + * @size: size of the mmap arena
>> + * @prot: memory protection bits as used by mmap()
>> + *
>> + * Call __gem_mmap__device__coherent_sync(), asserts on fail.
>> + * Offset argument passed in function call must be 0. In the future
>> + * when driver will allow slice mapping of buffer object this restriction
>> + * will be removed.
>> + *
>> + * This function sets appropriate memory domain as well once the mapping is
>> + * complete and makes the memory ready for cpu access
>> + *
>> + * Returns: A pointer to the created memory mapping.
>> + */
>> +void *gem_mmap__device_coherent_sync(int fd, uint32_t handle, uint64_t offset,
>> + uint64_t size, unsigned prot)
>> +{
>> + void *ptr;
>> + uint32_t domain;
>> +
>> + igt_assert(offset == 0);
>> +
>> + ptr = gem_mmap__device_coherent_domain(fd, handle, offset, size, prot, &domain);
>> + igt_assert(ptr);
>> +
>> + gem_set_domain(fd, handle, domain, domain);
>
> No. Read/write is important, especially when there are comments
> indicating that the api is being subverted and abused.
Are you suggesting looking at prot & PROT_READ / PROT_WRITE to decide on
read/write domains?
Regards,
Tvrtko
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-02-28 11:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-18 0:17 [igt-dev] [PATCH i-g-t 0/2] Introduce new apis for coherent mmap Sreedhar Telukuntla
2020-02-17 19:56 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2020-02-18 0:17 ` [igt-dev] [PATCH i-g-t 1/2] lib/i915/gem_mman: Add coherent mmap api support with set domain Sreedhar Telukuntla
2020-02-17 16:29 ` Chris Wilson
2020-02-18 3:53 ` Telukuntla, Sreedhar
2020-02-28 11:06 ` Tvrtko Ursulin [this message]
2020-02-18 0:17 ` [igt-dev] [PATCH i-g-t 2/2] tests/i915/gem_ctx_shared: Use gem_mmap__device_coherent_sync api Sreedhar Telukuntla
2020-02-19 11:02 ` [igt-dev] ✗ Fi.CI.IGT: failure for Introduce new apis for coherent mmap Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3f8e375c-dc04-f5d6-5364-a025f8167720@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=igt-dev@lists.freedesktop.org \
--cc=sreedhar.telukuntla@intel.com \
--cc=tvrtko.ursulin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox