From: Steven Newbury Subject: Re: drm_device from another device driver? (was: Re: block device backed by DRM buffer object) Date: Wed, 23 Sep 2015 23:52:50 +0100 Message-ID: <1443048770.1731.33.camel@snewbury.org.uk> References: <1442835186.12687.26.camel@snewbury.org.uk> <5600009B.6060909@vodafone.de> <1442954650.14110.24.camel@snewbury.org.uk> <47j707.nv5dbe.2u4lbf-qmf@mail.snewbury.org.uk> <20150923214138.GA8680@wunner.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0359203062==" Return-path: Received: from know-smtprelay-omc-7.server.virginmedia.net (know-smtprelay-omc-7.server.virginmedia.net [80.0.253.71]) by gabe.freedesktop.org (Postfix) with ESMTP id E6B336E102 for ; Wed, 23 Sep 2015 15:52:46 -0700 (PDT) In-Reply-To: <20150923214138.GA8680@wunner.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Lukas Wunner Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0359203062== Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-qW/O6Z8K3Y/LuJBsgABm" --=-qW/O6Z8K3Y/LuJBsgABm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 2015-09-23 at 23:41 +0200, Lukas Wunner wrote: > Hi, >=20 > On Wed, Sep 23, 2015 at 08:37:48PM +0000, Steven Newbury wrote: > > I can't figure out how to get a pointer to the radeon_device struct > > for a specific card, or the parent drm_device from an external > > device > > driver. >=20 > struct device -> struct drm_device: dev_get_drvdata() > struct pci_dev -> struct drm_device: pci_get_drvdata() > struct drm_device -> struct radeon_device: drm_device->dev_private >=20 Thanks, that's useful. >=20 > > I imagine I somehow need to take a reference to the drm class > > kobject > > for the card in question, and in so doing presumably I should then > > be > > able to discover the pointer to device. >=20 > It sounds like you want to discover the available radeon cards in the > system? If so you could iterate over all pci devices and look for > pci->vendor =3D=3D PCI_VENDOR_ID_ATI ||=C2=A0pci->vendor =3D=3D PCI_VENDO= R_ID_AMD, > then get to the radeon_device as shown above. >=20 Yes, my plan was to eventually discover all the drm devices on the system and make available a sysfs entry to allocate a volume from VRAM for each capable card selecting an appropriate backend for driver. =C2=A0I was initially just going to implement it for radoen using a static allocation from module params. > However as Christian K=C3=B6nig pointed out, memory allocation is driver > dependent. For an initial proof of concept it may be simplest to hack > the radeon driver. Then you'll get an idea which parts are generic > and > which are driver specific and you can move the generic stuff to a > central broker. >=20 Hacking the radeon driver was very much something I'd considered; I'd only decided not to because I was thinking too far ahead really. =C2=A0I need to keep it simple, as you say, and only add complexity once I have something working, and hopefully able to demonstrate its utility. > Rather than discovering the VRAM it probably makes more sense to have > drm devices register a set of callbacks with the central broker > (e.g. return amount of currently free VRAM, allocate VRAM for use as > block device, deallocate VRAM, read vector of blocks, write vector > of blocks). The broker could then be controlled from user space via > sysfs or ioctls or whatever. For now I think I'll just take the approach bcache does with "thinly provisioned volumes", and have an entry in the radeon sysfs: /sys/class/drm/card0/device/vram_volume_create which will attempt to allocate a given sized volume and register a vrambd[0]. (or some better name?) Unregistering/deallocation can be triggered from /sys/block/vramd[0]/vrambd/unregister --=-qW/O6Z8K3Y/LuJBsgABm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEABECAAYFAlYDLUMACgkQGcb56gMuC628iACgshHAOOmJA9vKjUNQGtx5rkaL Np0AoJQEBFUluKe1LGXQg3uw2j2QHZ3/ =MLg8 -----END PGP SIGNATURE----- --=-qW/O6Z8K3Y/LuJBsgABm-- --===============0359203062== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHA6Ly9saXN0 cy5mcmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9kcmktZGV2ZWwK --===============0359203062==--