From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31975 invoked from network); 7 Jun 2023 22:58:01 -0000 Received: from tb-ob1.topicbox.com (64.147.108.173) by inbox.vuxu.org with ESMTPUTF8; 7 Jun 2023 22:58:01 -0000 Received: from tb-mx1.topicbox.com (tb-mx1.nyi.icgroup.com [10.90.30.61]) by tb-ob1.topicbox.com (Postfix) with ESMTP id 10FDA19630 for ; Wed, 7 Jun 2023 18:58:00 -0400 (EDT) (envelope-from bounce.mM13bf569fd6da2483ff3c4074.r522be890-2105-11eb-b15e-8d699134e1fa@9fans.bounce.topicbox.com) Received: by tb-mx1.topicbox.com (Postfix, from userid 1132) id 0D21A1C95F48; Wed, 7 Jun 2023 18:58:00 -0400 (EDT) ARC-Authentication-Results: i=2; topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=pbrane.org header.i=@pbrane.org header.b=POrekat7 header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dkim=pass (2048-bit rsa key sha256) header.d=purelymail.com header.i=@purelymail.com header.b=ULSxxDxb header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=pbrane.org; spf=pass smtp.mailfrom=ality@pbrane.org smtp.helo=sendmail.purelymail.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to:list-help:list-id :list-post:list-subscribe:reply-to:content-transfer-encoding :list-unsubscribe; s=sysmsg-1; t=1686178679; bh=1gGruMYQvzaiIaZ4 1PbBr3msFEJrUup2tvAANOIPdIw=; b=ZUblOyxBQ4Q/EdEyEvRDAXEhklrrhPIR ASZGLyAKOO+UFoFm90eWlMcS7NicGQ69AMTzGsoBtuZW3Mg9jEye7ndg/MjDykWO AsjFLzEb5AufO0JRYt19ZUYSV/pBUb1mAP7Prf7BcZ/JxGzTMCkOnR6SrMo0dw55 8jeBnY73SnY= ARC-Seal: i=2; a=rsa-sha256; cv=pass; d=topicbox.com; s=sysmsg-1; t= 1686178679; b=d9Ivng4iEYEoqPBcr6WXrfrXlTfH/JOkQV+JkKOkxgzmjvX147 3ytWGdGaGT06Xcb2pPlwvhV55JghyUpanO6Wi1b1d68Kr0ka0ayAU6luRP+SC8Mx T9RJmlcfRF0qhtWq6gTBm2te5r1+3RDum9w4/IEvU8qRuFrgKP2tndAcU= Authentication-Results: topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=pbrane.org header.i=@pbrane.org header.b=POrekat7 header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dkim=pass (2048-bit rsa key sha256) header.d=purelymail.com header.i=@purelymail.com header.b=ULSxxDxb header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=pbrane.org; spf=pass smtp.mailfrom=ality@pbrane.org smtp.helo=sendmail.purelymail.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) X-Received-Authentication-Results: tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=pbrane.org header.i=@pbrane.org header.b=POrekat7 header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dkim=pass (2048-bit rsa key sha256) header.d=purelymail.com header.i=@purelymail.com header.b=ULSxxDxb header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=pbrane.org; iprev=pass smtp.remote-ip=34.202.193.197 (sendmail.purelymail.com); spf=pass smtp.mailfrom=ality@pbrane.org smtp.helo=sendmail.purelymail.com; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=sendmail.purelymail.com policy.ptr=sendmail.purelymail.com; x-return-mx=pass header.domain=pbrane.org policy.is_org=yes (MX Records found: mailserver.purelymail.com); x-return-mx=pass smtp.domain=pbrane.org policy.is_org=yes (MX Records found: mailserver.purelymail.com); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=9fans.net; h=date:from :to:subject:message-id:references:mime-version:content-type :in-reply-to:list-help:list-id:list-post:list-subscribe:reply-to :content-transfer-encoding:list-unsubscribe; s=dkim-1; t= 1686178679; x=1686265079; bh=67fAVCrX9tmVHv0g2U3EACDlKgX4mEfQSxI 3xU51ngU=; b=KLAlSJIOF+tizLAD4hJ0qnp2308ERaKITgOELzglaAtzhFFOElS faBnEi0UgcITumkgN5n9ei3tCGLIUj00vNAZDFzO0C1Xqd5et6qeYZLNL7isRGoZ sM8NbsXjHzK47DQyK4sL4djNLr4UXcS50RCGCU9/0HLfACT1KwlxtCTs= Received: from tb-mx1.topicbox.com (localhost.local [127.0.0.1]) by tb-mx1.topicbox.com (Postfix) with ESMTP id 739851C95AF8 for <9fans@9fans.net>; Wed, 7 Jun 2023 18:57:47 -0400 (EDT) (envelope-from ality@pbrane.org) Received: from tb-mx1.topicbox.com (localhost [127.0.0.1]) by tb-mx1.topicbox.com (Authentication Milter) with ESMTP id 8B1B3A15E3C; Wed, 7 Jun 2023 18:57:47 -0400 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1686178667; b=QT1mRaxcv/GLQzL8azf6yhQ4xm5cTOrlEaI/c9az5k6INrrX7z u/KRfnOkP2F7h7YIXqSpXMp+u5fDJZszim1l9CKBgEtrBPpwouxq6Me0MeCzl3md dIgrxy/S4CTeFPbZClR1yxJ1a/rPHamNtjvstJNb+fFVDFUwYXMFNiUnSCyPtgdw IKkJgNoSb3pbVruznOc63M4MkTr2un1nx0HaBdcYfRzmAlN7xo2V+5u7vDG6QDkw Dt224YoWwQ6non+EaW3Mma3Xc6M1kTL2OZJ6gQhUmxeWKvqknHxrxk/bkFo0gATQ USTMRv4+THrltk2CWxbFqEexovZE9yjf02tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; s=arcseal; t=1686178667; bh=+fpSNVuYQrQJv66/2/tIPX/2RYG+erB0wq4LdbCt/FU=; b=cc/9IIl3yFlW 6Lc5kd+YykxE84kJKYU/Lr+REKjJJRTubbKW2h5KDsSDFW9IAze0zU/YKc2+mP47 IP2OijQ4N2LZnAklXfblYTF8F6aFgM08hpo2LnE5ZgsFbX3wuOCEhP/6xvRkh5yf 1io61KpHDLu46q9yOFCiQ/jB5NYRVCtlDbF2hltcrGNvnNQVi42KsjAhBWQSBD3T gWLwvXK2KESO5Ny+NS0cqrueNVROrptpMkW8y77PWagSIAAFfsHX0D4j5RPIU3rh DTswygOrEqj7oUfRgygUgQSLQJDw9rB+C2zH6Iy4JY0VgbhriSaVZ+6LkyKRlqmW gQnKrldRTg== ARC-Authentication-Results: i=1; tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=pbrane.org header.i=@pbrane.org header.b=POrekat7 header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dkim=pass (2048-bit rsa key sha256) header.d=purelymail.com header.i=@purelymail.com header.b=ULSxxDxb header.a=rsa-sha256 header.s=purelymail2 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=pbrane.org; iprev=pass smtp.remote-ip=34.202.193.197 (sendmail.purelymail.com); spf=pass smtp.mailfrom=ality@pbrane.org smtp.helo=sendmail.purelymail.com; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=sendmail.purelymail.com policy.ptr=sendmail.purelymail.com; x-return-mx=pass header.domain=pbrane.org policy.is_org=yes (MX Records found: mailserver.purelymail.com); x-return-mx=pass smtp.domain=pbrane.org policy.is_org=yes (MX Records found: mailserver.purelymail.com); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedthedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesmhdtreertddtvdenucfhrhhomheptehnthhhohhnhicuofgrrhhtihhn uceorghlihhthiesphgsrhgrnhgvrdhorhhgqeenucggtffrrghtthgvrhhnpefhleduvd dtfedvhedukedvudefieegkeelvdevffdvhfettdffleekfeefveegtdenucfkphepfeeg rddvtddvrdduleefrdduleejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hinhgvthepfeegrddvtddvrdduleefrdduleejpdhhvghlohepshgvnhgumhgrihhlrdhp uhhrvghlhihmrghilhdrtghomhdpmhgrihhlfhhrohhmpeeorghlihhthiesphgsrhgrnh gvrdhorhhgqe X-ME-VSScore: 0 X-ME-VSCategory: clean Received-SPF: pass (pbrane.org: Sender is authorized to use 'ality@pbrane.org' in 'mfrom' identity (mechanism 'include:_spf.purelymail.com' matched)) receiver=tb-mx1.topicbox.com; identity=mailfrom; envelope-from="ality@pbrane.org"; helo=sendmail.purelymail.com; client-ip=34.202.193.197 Received: from sendmail.purelymail.com (sendmail.purelymail.com [34.202.193.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tb-mx1.topicbox.com (Postfix) with ESMTPS for <9fans@9fans.net>; Wed, 7 Jun 2023 18:57:46 -0400 (EDT) (envelope-from ality@pbrane.org) Feedback-ID: 10987:2443:null:purelymail X-Pm-Original-To: 9fans@9fans.net Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 972798142 for <9fans@9fans.net> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 07 Jun 2023 22:57:35 +0000 (UTC) Date: Wed, 7 Jun 2023 15:57:28 -0700 From: Anthony Martin To: 9fans <9fans@9fans.net> Subject: Re: [9fans] Adjust Thinkpad Screen Brightness Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=qwNFO6n0Lb+HqKxd Content-Disposition: inline In-Reply-To: Topicbox-Policy-Reasoning: allow: sender is a member Topicbox-Message-UUID: bb17f160-0586-11ee-ad6f-f91cc4f70981 Archived-At: =?UTF-8?B?PGh0dHBzOi8vOWZhbnMudG9waWNib3guY29tL2dyb3Vwcy85?= =?UTF-8?B?ZmFucy9UNGM0MjQ3ZWMxYzA0MjlmNi1NMTNiZjU2OWZkNmRhMjQ4M2ZmM2M0?= =?UTF-8?B?MDc0Pg==?= List-Help: List-Id: "9fans" <9fans.9fans.net> List-Post: List-Software: Topicbox v0 List-Subscribe: Precedence: list Reply-To: 9fans <9fans@9fans.net> Content-Transfer-Encoding: 7bit List-Unsubscribe: , Topicbox-Delivery-ID: 2:9fans:437d30aa-c441-11e9-8a57-d036212d11b0:522be890-2105-11eb-b15e-8d699134e1fa:M13bf569fd6da2483ff3c4074:1:oVZBrvx7kQ96FPauwvNWlR9EHjxViJ6Rl0oPXDVcplo --qwNFO6n0Lb+HqKxd Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-ID: <16861786750.1E6c0B.865626@tb-mx1> unobe@cpan.org once said: > I reviewed the data sheet and the scripts should > work, but does not. The above scripts can work for some Intel cards but probably not for all of them. I wrote a program fifteen years ago to adjust the brightness on an Intel MacBook from Linux. There was a bit of experimentation involved to determine register values that wouldn't cause problems. I've attached it below. Notice how I had to use a mask of 0xfffe instead of 0xffff to keep the least significant bit zero and how I had to be strict about maintaining the maximum backlight level field when reading and writing the register. I remember working through a lot of blank and flickering screens before arriving at something that worked. I'm not near a machine with an Intel card at the moment so I can't give you something that works on Plan 9 but reading this old code may give you some hints. Cheers, Anthony ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/T4c4247ec1c0429f6-M13bf5= 69fd6da2483ff3c4074 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription --qwNFO6n0Lb+HqKxd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="lcd.c" Content-ID: <16861786751.eCAcA6E9.865626@tb-mx1> #define _XOPEN_SOURCE 500 #include #include #include #include #include #include #include #include #include #include #include typedef unsigned short ushort; typedef unsigned int uint; // A barebones representation of a PCI device. typedef struct Pcidev Pcidev; struct Pcidev { ushort vid; // PCI vendor ID. ushort did; // PCI device ID. pciaddr_t bar; // Physical address of the first BAR. size_t size; // Size of the first BAR. char* addr; // Mapped virtual address of the first BAR. }; // Macros to read and write 32-bit PCI memory registers. #define reg32r(p, r) (*(uint*)((p)->addr+(r))) #define reg32w(p, r, v) (*(uint*)((p)->addr+(r)) = (v)) enum { // The PCI vendor and device ID for the Intel 945GM graphics chipset. Intel = 0x8086, I945GM = 0x27a2, // The backlight PWM control register offset. Bctl = 0x061254, // The backlight duty cycle mask. The LSB must be zero. Bmask = 0xfffe, // The empirically observed range for valid brightness levels. Boff = 0x0000, Bmin = 0x003e, Bmax = 0x0128, // Without an explicit value, we increase or decrease by this // quantum so that there are only ten brightness levels. Bquant = (Bmax-Bmin)/(10-1), }; // We don't expose the hardware-centric brightness levels to the user // but instead shift the range down so it starts at one. These macros // convert to and fro. #define B(u) (((u) == 0) ? Boff : (u)+Bmin-1) #define U(b) (((b) == Boff) ? 0 : (b)-Bmin+1) // The set of operations that can be performed on the backlight. enum { Onop = 1<<0, Oset = 1<<1, Oadd = 1<<2|Oset, Osub = 1<<3|Oset, }; // The high sixteen bits of the opcode are only used for operations // that require a numeric argument. These macros ease extraction. #define OP(o) ((o)&0xFFFF) #define OPVAL(v) (((v)&0xFFFF)<<16) char* argv0; void fatal(char*, ...); int pcimatch(Pcidev*, int, int); int main(int argc, char *argv[]) { int o, fd, max, cur, new; char *s, *end; Pcidev p; // Determine which operation to perform. argv0 = argv[0]; switch(argc){ default: fprintf(stderr, "usage: %s [+-][val]\n", argv0); exit(EXIT_FAILURE); case 1: o = Onop; break; case 2: s = argv[1]; if(*s == '+' || *s == '-'){ o = (*s == '+') ? Oadd : Osub; s++; } else o = Oset; if(o != Oset && *s == '\0') o |= OPVAL(Bquant); else { o |= OPVAL(strtol(s, &end, 10)); if(errno != 0 || end == s) fatal("invalid number"); } break; } // Map the GPU device into memory so we can access the backlight register. if(pcimatch(&p, Intel, I945GM) < 0) fatal("pcimatch failed"); fd = open("/dev/mem", O_RDWR); if(fd < 0) fatal("open /dev/mem failed"); p.addr = mmap(NULL, p.size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, p.bar); if(p.addr == MAP_FAILED) fatal("map failed"); close(fd); max = reg32r(&p, Bctl) >> 16; if(max != Bmax) fatal("invalid maximum: have %d want %d", max, Bmax); // Load the current brightness level and change it, if applicable. cur = reg32r(&p, Bctl) & Bmask; new = 0; switch(OP(o)){ case Oset: new = B(o>>16); break; case Oadd: new = (cur == Boff) ? Bmin : cur + (o>>16); break; case Osub: new = (cur == Bmin) ? Boff : cur - (o>>16); break; } if(o & Oset){ if(new < 0) new = Boff; if(new > 0){ if(new < Bmin) new = Bmin; if(new > Bmax) new = Bmax; } reg32w(&p, Bctl, (new&Bmask)|(Bmax<<16)); cur = reg32r(&p, Bctl) & Bmask; } // Unmap the device and print the current backlight level. munmap(p.addr, p.size); printf("%d/%d\n", U(cur), U(Bmax)); return 0; } #define nil ((void*)0) static struct pci_access* pciacc; static struct pci_dev* pcilist; int pcimatch(Pcidev* p, int vid, int did) { static int pcicfgmode = -1; struct pci_access *a; struct pci_dev *prev; int req; if(pcicfgmode == -1){ a = pci_alloc(); if(a == nil) fatal("pci_alloc failed"); pci_init(a); pci_scan_bus(a); pcilist = a->devices; pciacc = a; pcicfgmode = 0; } prev = pcilist; req = PCI_FILL_IDENT | PCI_FILL_BASES; pci_fill_info(prev, req); while(prev != nil){ if((vid == 0 || prev->vendor_id == vid) && (did == 0 || prev->device_id == did)) break; prev = prev->next; } if(prev == nil) return -1; p->vid = prev->vendor_id; p->did = prev->device_id; p->bar = prev->base_addr[0] & PCI_ADDR_MEM_MASK; p->size = prev->size[0]; pci_cleanup(pciacc); return 0; } void fatal(char *fmt, ...) { char buf[4096]; va_list arg; int n; n = snprintf(buf, sizeof buf, "%s: ", argv0); va_start(arg, fmt); n += vsnprintf(buf+n, sizeof buf-n, fmt, arg); va_end(arg); if(errno) n += snprintf(buf+n, sizeof buf-n, ": %s", strerror(errno)); n += snprintf(buf+n, sizeof buf-n, "\n"); write(2, buf, n); exit(EXIT_FAILURE); } --qwNFO6n0Lb+HqKxd--