From: =?ISO-8859-1?Q?Erik_Andr=E9n?= Subject: Re: [PATCH 3/6] libkms: Add nouveau support. Date: Sat, 27 Feb 2010 20:16:22 +0100 Message-ID: <62e5edd41002271116q10befa62j8af630951524fc03@mail.gmail.com> References: <1267283082-21586-1-git-send-email-koriakin@0x04.net> <1267283082-21586-2-git-send-email-koriakin@0x04.net> <1267283082-21586-3-git-send-email-koriakin@0x04.net> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1267283082-21586-3-git-send-email-koriakin@0x04.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.sourceforge.net To: =?ISO-8859-2?Q?Marcin_Ko=B6cielnicki?= Cc: dri-devel@lists.sourceforge.net List-Id: dri-devel@lists.freedesktop.org Hi Marcin, I have some minor comments inlined below. Best regards, Erik > +static int > +nouveau_bo_create(struct kms_driver *kms, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const unsigned width, const unsigned hei= ght, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const enum kms_bo_type type, const unsig= ned *attr, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct kms_bo **out) > +{ > + =A0 =A0 =A0 struct drm_nouveau_gem_new arg; > + =A0 =A0 =A0 unsigned size, pitch; > + =A0 =A0 =A0 struct nouveau_bo *bo; > + =A0 =A0 =A0 int i, ret; > + > + =A0 =A0 =A0 for (i =3D 0; attr[i]; i +=3D 2) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 switch (attr[i]) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case KMS_WIDTH: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case KMS_HEIGHT: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case KMS_BO_TYPE: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 default: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 bo =3D calloc(1, sizeof(*bo)); > + =A0 =A0 =A0 if (!bo) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM; > + > + =A0 =A0 =A0 if (type =3D=3D KMS_BO_TYPE_CURSOR_64X64_ARGB) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pitch =3D 64 * 4; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 size =3D 64 * 64 * 4; > + =A0 =A0 =A0 } else if (type =3D=3D KMS_BO_TYPE_SCANOUT) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pitch =3D width * 4; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pitch =3D (pitch + 512 - 1) & ~(512 - 1); What is 512 derived from? Would a #define explain this better? > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 size =3D pitch * height; > + =A0 =A0 =A0 } else { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 memset(&arg, 0, sizeof(arg)); > + =A0 =A0 =A0 arg.info.size =3D size; > + =A0 =A0 =A0 arg.info.domain =3D NOUVEAU_GEM_DOMAIN_MAPPABLE | NOUVEAU_G= EM_DOMAIN_VRAM; > + =A0 =A0 =A0 arg.info.tile_mode =3D 0; > + =A0 =A0 =A0 arg.info.tile_flags =3D 0; > + =A0 =A0 =A0 arg.align =3D 512; > + =A0 =A0 =A0 arg.channel_hint =3D 0; > + > + =A0 =A0 =A0 ret =3D drmCommandWriteRead(kms->fd, DRM_NOUVEAU_GEM_NEW, &= arg, sizeof(arg)); > + =A0 =A0 =A0 if (ret) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err_free; > + > + =A0 =A0 =A0 bo->base.kms =3D kms; > + =A0 =A0 =A0 bo->base.handle =3D arg.info.handle; > + =A0 =A0 =A0 bo->base.size =3D size; > + =A0 =A0 =A0 bo->base.pitch =3D pitch; > + =A0 =A0 =A0 bo->map_handle =3D arg.info.map_handle; > + > + =A0 =A0 =A0 *out =3D &bo->base; > + > + =A0 =A0 =A0 return 0; > + > +err_free: > + =A0 =A0 =A0 free(bo); > + =A0 =A0 =A0 return ret; > +} > + > +static int > +nouveau_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) > +{ > + =A0 =A0 =A0 switch (key) { > + =A0 =A0 =A0 default: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL; > + =A0 =A0 =A0 } > +} > + > +static int > +nouveau_bo_map(struct kms_bo *_bo, void **out) > +{ > + =A0 =A0 =A0 struct nouveau_bo *bo =3D (struct nouveau_bo *)_bo; > + =A0 =A0 =A0 void *map =3D NULL; > + =A0 =A0 =A0 int ret; > + ret is unused. > + =A0 =A0 =A0 if (bo->base.ptr) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bo->map_count++; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *out =3D bo->base.ptr; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 map =3D mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_= SHARED, bo->base.kms->fd, bo->map_handle); > + =A0 =A0 =A0 if (map =3D=3D MAP_FAILED) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -errno; > + > + =A0 =A0 =A0 bo->base.ptr =3D map; > + =A0 =A0 =A0 bo->map_count++; > + =A0 =A0 =A0 *out =3D bo->base.ptr; > + > + =A0 =A0 =A0 return 0; > +} > + > +static int > +nouveau_bo_unmap(struct kms_bo *_bo) > +{ > + =A0 =A0 =A0 struct nouveau_bo *bo =3D (struct nouveau_bo *)_bo; > + =A0 =A0 =A0 bo->map_count--; > + =A0 =A0 =A0 return 0; > +} > + > +static int > +nouveau_bo_destroy(struct kms_bo *_bo) > +{ > + =A0 =A0 =A0 struct nouveau_bo *bo =3D (struct nouveau_bo *)_bo; > + =A0 =A0 =A0 struct drm_gem_close arg; > + =A0 =A0 =A0 int ret; > + > + =A0 =A0 =A0 if (bo->base.ptr) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* XXX Sanity check map_count */ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 munmap(bo->base.ptr, bo->base.size); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bo->base.ptr =3D NULL; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 memset(&arg, 0, sizeof(arg)); > + =A0 =A0 =A0 arg.handle =3D bo->base.handle; > + > + =A0 =A0 =A0 ret =3D drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &ar= g); > + =A0 =A0 =A0 if (ret) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -errno; > + > + =A0 =A0 =A0 free(bo); > + =A0 =A0 =A0 return 0; > +} > + > +int > +nouveau_create(int fd, struct kms_driver **out) > +{ > + =A0 =A0 =A0 struct kms_driver *kms; > + > + =A0 =A0 =A0 kms =3D calloc(1, sizeof(*kms)); > + =A0 =A0 =A0 if (!kms) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM; > + > + =A0 =A0 =A0 kms->fd =3D fd; > + > + =A0 =A0 =A0 kms->bo_create =3D nouveau_bo_create; > + =A0 =A0 =A0 kms->bo_map =3D nouveau_bo_map; > + =A0 =A0 =A0 kms->bo_unmap =3D nouveau_bo_unmap; > + =A0 =A0 =A0 kms->bo_get_prop =3D nouveau_bo_get_prop; > + =A0 =A0 =A0 kms->bo_destroy =3D nouveau_bo_destroy; > +// =A0 =A0 kms->get_prop =3D nouveau_get_prop; > + =A0 =A0 =A0 kms->destroy =3D nouveau_destroy; > + =A0 =A0 =A0 *out =3D kms; > + > + =A0 =A0 =A0 return 0; > +} > -- > 1.6.4.4 > > > > -------------------------------------------------------------------------= ----- > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > -- > _______________________________________________ > Dri-devel mailing list > Dri-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/dri-devel > > ---------------------------------------------------------------------------= --- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev --