2 * The PCI Library -- Direct Configuration access via PCIe ECAM
4 * Copyright (c) 2023 Pali Rohár <pali@kernel.org>
6 * Can be freely distributed and used under the terms of the GNU GPL.
10 * Tell 32-bit platforms that we are interested in 64-bit variant of off_t type
11 * as 32-bit variant of off_t type is signed and so it cannot represent all
12 * possible 32-bit offsets. It is required because off_t type is used by mmap().
14 #define _FILE_OFFSET_BITS 64
26 #include <sys/types.h>
31 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
32 #include <sys/sysctl.h>
35 #if defined (__FreeBSD__) || defined (__DragonFly__)
40 #define OFF_MAX (off_t)((1ULL << (sizeof(off_t) * CHAR_BIT - 1)) - 1)
67 char asl_compiler_id[4];
68 u32 asl_compiler_revision;
94 get_rsdt_addresses_count(struct acpi_rsdt *rsdt)
96 return (rsdt->sdt.length - ((unsigned char*)&rsdt->sdt_addresses - (unsigned char *)rsdt)) / sizeof(rsdt->sdt_addresses[0]);
100 get_xsdt_addresses_count(struct acpi_xsdt *xsdt)
102 return (xsdt->sdt.length - ((unsigned char*)&xsdt->sdt_addresses - (unsigned char *)xsdt)) / sizeof(xsdt->sdt_addresses[0]);
106 get_mcfg_allocations_count(struct acpi_mcfg *mcfg)
108 return (mcfg->sdt.length - ((unsigned char *)&mcfg->allocations - (unsigned char *)mcfg)) / sizeof(mcfg->allocations[0]);
112 calculate_checksum(const u8 *bytes, int len)
117 checksum -= *(bytes++);
121 static struct acpi_sdt *
122 check_and_map_sdt(int fd, u64 addr, const char *signature, void **map_addr, u32 *map_length)
124 struct acpi_sdt *sdt;
125 char sdt_signature[sizeof(sdt->signature)];
129 if (addr > OFF_MAX - sizeof(*sdt))
132 map = mmap(NULL, sizeof(*sdt) + (addr & (pagesize-1)), PROT_READ, MAP_SHARED, fd, addr & ~(pagesize-1));
133 if (map == MAP_FAILED)
136 sdt = (struct acpi_sdt *)((unsigned char *)map + (addr & (pagesize-1)));
137 length = sdt->length;
138 memcpy(sdt_signature, sdt->signature, sizeof(sdt->signature));
140 munmap(map, sizeof(*sdt) + (addr & (pagesize-1)));
142 if (memcmp(sdt_signature, signature, sizeof(sdt_signature)) != 0)
144 if (length < sizeof(*sdt))
147 map = mmap(NULL, length + (addr & (pagesize-1)), PROT_READ, MAP_SHARED, fd, addr & ~(pagesize-1));
148 if (map == MAP_FAILED)
151 sdt = (struct acpi_sdt *)((unsigned char *)map + (addr & (pagesize-1)));
153 if (calculate_checksum((u8 *)sdt, sdt->length) != 0)
155 munmap(map, length + (addr & (pagesize-1)));
160 *map_length = length + (addr & (pagesize-1));
165 check_rsdp(struct acpi_rsdp *rsdp)
167 if (memcmp(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature)) != 0)
169 if (calculate_checksum((u8 *)rsdp, sizeof(*rsdp)) != 0)
175 check_and_parse_rsdp(int fd, off_t addr, u32 *rsdt_address, u64 *xsdt_address)
177 struct acpi_rsdp *rsdp;
178 unsigned char buf[sizeof(*rsdp) + sizeof(*rsdp->rsdp20)];
181 map = mmap(NULL, sizeof(buf) + (addr & (pagesize-1)), PROT_READ, MAP_SHARED, fd, addr & ~(pagesize-1));
182 if (map == MAP_FAILED)
185 rsdp = (struct acpi_rsdp *)buf;
186 memcpy(rsdp, (unsigned char *)map + (addr & (pagesize-1)), sizeof(buf));
188 munmap(map, sizeof(buf));
190 if (!check_rsdp(rsdp))
193 *rsdt_address = rsdp->rsdt_address;
195 if (rsdp->revision != 0 &&
196 (*rsdp->rsdp20).length == sizeof(*rsdp) + sizeof(*rsdp->rsdp20) &&
197 calculate_checksum((u8 *)rsdp, (*rsdp->rsdp20).length) == 0)
198 *xsdt_address = (*rsdp->rsdp20).xsdt_address;
206 find_rsdp_address(struct pci_access *a, const char *efisystab, int use_bsd UNUSED, int use_x86bios UNUSED)
208 unsigned long long ullnum;
209 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
216 #if defined(__amd64__) || defined(__i386__)
228 a->debug("reading EFI system table: %s...", efisystab);
229 f = fopen(efisystab, "r");
232 while (fgets(buf, sizeof(buf), f))
235 while (len > 0 && buf[len-1] == '\n')
237 if (strncmp(buf, "ACPI20=", 7) == 0 && isxdigit(buf[7]))
240 ullnum = strtoull(buf+7, &endptr, 16);
241 if (!errno && !*endptr && ullnum <= OFF_MAX)
244 else if (strncmp(buf, "ACPI=", 5) == 0 && isxdigit(buf[5]))
247 ullnum = strtoull(buf+5, &endptr, 16);
248 if (!errno && !*endptr && ullnum <= OFF_MAX)
261 #if defined (__FreeBSD__) || defined (__DragonFly__)
264 /* First try FreeBSD kenv hint.acpi.0.rsdp */
265 a->debug("calling kenv hint.acpi.0.rsdp...");
266 if (kenv(KENV_GET, "hint.acpi.0.rsdp", buf, sizeof(buf)) > 0)
269 ullnum = strtoull(buf, &endptr, 16);
270 if (!errno && !*endptr && ullnum <= OFF_MAX)
274 /* Then try FreeBSD sysctl machdep.acpi_root */
275 a->debug("calling sysctl machdep.acpi_root...");
277 if (sysctlbyname("machdep.acpi_root", &ulnum, &len, NULL, 0) == 0 && ulnum <= OFF_MAX)
282 #if defined(__NetBSD__)
285 /* Try NetBSD sysctl hw.acpi.root */
286 a->debug("calling sysctl hw.acpi.root...");
288 if (sysctlbyname("hw.acpi.root", &ulnum, &len, NULL, 0) == 0 && ulnum <= OFF_MAX)
293 #if defined(__amd64__) || defined(__i386__)
298 /* Scan first kB of Extended BIOS Data Area */
299 a->debug("scanning first kB of EBDA...");
300 map = mmap(NULL, 0x40E + 1024, PROT_READ, MAP_SHARED, a->fd, 0);
301 if (map != MAP_FAILED)
303 for (addr = 0x40E; addr < 0x40E + 1024; addr += 16)
305 if (check_rsdp((struct acpi_rsdp *)((unsigned char *)map + addr)))
311 munmap(map, 0x40E + 1024);
317 /* Scan the main BIOS area below 1 MB */
318 a->debug("scanning BIOS below 1 MB...");
319 map = mmap(NULL, 0x20000, PROT_READ, MAP_SHARED, a->fd, 0xE0000);
320 if (map != MAP_FAILED)
322 for (addr = 0x0; addr < 0x20000; addr += 16)
324 if (check_rsdp((struct acpi_rsdp *)((unsigned char *)map + addr)))
326 rsdp_addr = 0xE0000 + addr;
330 munmap(map, 0x20000);
341 static struct acpi_mcfg *
342 find_mcfg(struct pci_access *a, const char *acpimcfg, const char *efisystab, int use_bsd, int use_x86bios)
344 struct acpi_xsdt *xsdt;
345 struct acpi_rsdt *rsdt;
346 struct acpi_mcfg *mcfg;
347 struct acpi_sdt *sdt;
348 unsigned int i, count;
363 ret = glob(acpimcfg, GLOB_NOCHECK, NULL, &mcfg_glob);
366 a->debug("reading acpi mcfg file: %s...", mcfg_glob.gl_pathv[0]);
367 mcfg_fd = open(mcfg_glob.gl_pathv[0], O_RDONLY);
368 globfree(&mcfg_glob);
371 length = lseek(mcfg_fd, 0, SEEK_END);
372 if (length != (off_t)-1 && length > (off_t)sizeof(*mcfg))
374 lseek(mcfg_fd, 0, SEEK_SET);
375 mcfg = pci_malloc(a, length);
376 if (read(mcfg_fd, mcfg, length) == length &&
377 memcmp(mcfg->sdt.signature, "MCFG", 4) == 0 &&
378 mcfg->sdt.length <= length &&
379 calculate_checksum((u8 *)mcfg, mcfg->sdt.length) == 0)
387 a->debug("failed...");
390 a->debug("glob(%s) failed: %d...", acpimcfg, ret);
393 a->debug("searching for ACPI RSDP...");
394 rsdp_address = find_rsdp_address(a, efisystab, use_bsd, use_x86bios);
397 a->debug("not found...");
400 a->debug("found at 0x%llx...", (unsigned long long)rsdp_address);
402 if (!check_and_parse_rsdp(a->fd, rsdp_address, &rsdt_address, &xsdt_address))
404 a->debug("invalid...");
409 a->debug("searching for ACPI MCFG (XSDT=0x%llx, RSDT=0x%x)...", (unsigned long long)xsdt_address, rsdt_address);
411 xsdt = xsdt_address ? (struct acpi_xsdt *)check_and_map_sdt(a->fd, xsdt_address, "XSDT", &map_addr, &map_length) : NULL;
414 a->debug("via XSDT...");
415 count = get_xsdt_addresses_count(xsdt);
416 for (i = 0; i < count; i++)
418 sdt = check_and_map_sdt(a->fd, xsdt->sdt_addresses[i], "MCFG", &map2_addr, &map2_length);
421 mcfg = pci_malloc(a, sdt->length);
422 memcpy(mcfg, sdt, sdt->length);
423 munmap(map2_addr, map2_length);
427 munmap(map_addr, map_length);
430 a->debug("found...");
435 rsdt = (struct acpi_rsdt *)check_and_map_sdt(a->fd, rsdt_address, "RSDT", &map_addr, &map_length);
438 a->debug("via RSDT...");
439 count = get_rsdt_addresses_count(rsdt);
440 for (i = 0; i < count; i++)
442 sdt = check_and_map_sdt(a->fd, rsdt->sdt_addresses[i], "MCFG", &map2_addr, &map2_length);
445 mcfg = pci_malloc(a, sdt->length);
446 memcpy(mcfg, sdt, sdt->length);
447 munmap(map2_addr, map2_length);
451 munmap(map_addr, map_length);
454 a->debug("found...");
459 a->debug("not found...");
464 get_mcfg_allocation(struct acpi_mcfg *mcfg, unsigned int i, int *domain, u8 *start_bus, u8 *end_bus, off_t *addr, u32 *length)
466 int buses = (int)mcfg->allocations[i].end_bus_number - (int)mcfg->allocations[i].start_bus_number + 1;
469 *domain = mcfg->allocations[i].pci_segment;
471 *start_bus = mcfg->allocations[i].start_bus_number;
473 *end_bus = mcfg->allocations[i].end_bus_number;
475 *addr = mcfg->allocations[i].address;
477 *length = (buses > 0) ? (buses * 32 * 8 * 4096) : 0;
481 parse_next_addrs(const char *addrs, const char **next, int *domain, u8 *start_bus, u8 *end_bus, off_t *addr, u32 *length)
483 unsigned long long ullnum;
484 const char *sep1, *sep2;
489 unsigned long long start_addr;
498 endptr = strchr(addrs, ',');
500 addr_len = endptr - addrs;
502 addr_len = strlen(addrs);
505 *next = endptr ? (endptr+1) : NULL;
507 sep1 = memchr(addrs, ':', addr_len);
511 sep2 = memchr(sep1+1, ':', addr_len - (sep1+1 - addrs));
525 if (!isxdigit(*addrs))
528 num = strtol(addrs, &endptr, 16);
529 if (errno || endptr != sep1 || num < 0 || num > INT_MAX)
536 num = strtol(sep1 ? (sep1+1) : addrs, &endptr, 16);
537 if (errno || num < 0 || num > 0xff)
549 num = strtol(endptr+1, &endptr, 16);
550 if (errno || endptr != sep2 || num < 0 || num > 0xff)
552 buses = num - -buses + 1;
559 if (!isxdigit(*(sep2+1)))
563 ullnum = strtoull(sep2+1, &endptr, 16);
564 if (errno || (ullnum & 3) || ullnum > OFF_MAX)
570 if (endptr == addrs + addr_len)
574 buses = 0xff - -buses + 1;
578 if ((unsigned)buses * 32 * 8 * 4096 > OFF_MAX - start_addr)
581 *length = buses * 32 * 8 * 4096;
585 if (*endptr != '+' || !isxdigit(*(endptr+1)))
588 ullnum = strtoull(endptr+1, &endptr, 16);
589 if (errno || endptr != addrs + addr_len || (ullnum & 3) || ullnum > OFF_MAX || ullnum > 256 * 32 * 8 * 4096)
591 if (ullnum > OFF_MAX - start_addr)
593 if (buses > 0 && ullnum > (unsigned)buses * 32 * 8 * 4096)
595 if (buses <= 0 && ullnum > (0xff - (unsigned)-buses + 1) * 32 * 8 * 4096)
599 if (buses <= 0 && end_bus)
600 *end_bus = -buses + (ullnum + 32 * 8 * 4096 - 1) / (32 * 8 * 4096);
607 validate_addrs(const char *addrs)
613 if (!parse_next_addrs(addrs, &addrs, NULL, NULL, NULL, NULL, NULL))
620 get_bus_addr(struct acpi_mcfg *mcfg, const char *addrs, int domain, u8 bus, off_t *addr, u32 *length)
632 count = get_mcfg_allocations_count(mcfg);
633 for (i = 0; i < count; i++)
635 get_mcfg_allocation(mcfg, i, &cur_domain, &start_bus, &end_bus, &start_addr, &total_length);
636 if (domain == cur_domain && bus >= start_bus && bus <= end_bus)
638 offset = 32*8*4096 * (bus - start_bus);
639 if (offset >= total_length)
641 *addr = start_addr + offset;
642 *length = total_length - offset;
652 if (!parse_next_addrs(addrs, &addrs, &cur_domain, &start_bus, &end_bus, &start_addr, &total_length))
654 if (domain == cur_domain && bus >= start_bus && bus <= end_bus)
656 offset = 32*8*4096 * (bus - start_bus);
657 if (offset >= total_length)
659 *addr = start_addr + offset;
660 *length = total_length - offset;
680 struct acpi_mcfg *mcfg;
681 struct mmap_cache *cache;
685 munmap_reg(struct pci_access *a)
687 struct ecam_aux *aux = a->aux;
688 struct mmap_cache *cache = aux->cache;
693 munmap(cache->map, cache->length + (cache->addr & (pagesize-1)));
699 mmap_reg(struct pci_access *a, int w, int domain, u8 bus, u8 dev, u8 func, int pos, volatile void **reg)
701 struct ecam_aux *aux = a->aux;
702 struct mmap_cache *cache = aux->cache;
709 if (cache && cache->domain == domain && cache->bus == bus && !!cache->w == !!w)
713 length = cache->length;
717 addrs = pci_get_param(a, "ecam.addrs");
718 if (!get_bus_addr(aux->mcfg, addrs, domain, bus, &addr, &length))
721 map = mmap(NULL, length + (addr & (pagesize-1)), w ? PROT_WRITE : PROT_READ, MAP_SHARED, a->fd, addr & ~(pagesize-1));
722 if (map == MAP_FAILED)
726 munmap(cache->map, cache->length + (cache->addr & (pagesize-1)));
728 cache = aux->cache = pci_malloc(a, sizeof(*cache));
732 cache->length = length;
733 cache->domain = domain;
739 * Enhanced Configuration Access Mechanism (ECAM) offset according to:
740 * PCI Express Base Specification, Revision 5.0, Version 1.0, Section 7.2.2, Table 7-1, p. 677
742 offset = ((dev & 0x1f) << 15) | ((func & 0x7) << 12) | (pos & 0xfff);
744 if (offset + 4 > length)
747 *reg = (unsigned char *)map + (addr & (pagesize-1)) + offset;
752 writeb(unsigned char value, volatile void *addr)
754 *(volatile unsigned char *)addr = value;
758 writew(unsigned short value, volatile void *addr)
760 *(volatile unsigned short *)addr = value;
764 writel(unsigned int value, volatile void *addr)
766 *(volatile unsigned int *)addr = value;
770 readb(volatile void *addr)
772 return *(volatile unsigned char *)addr;
775 static unsigned short
776 readw(volatile void *addr)
778 return *(volatile unsigned short *)addr;
782 readl(volatile void *addr)
784 return *(volatile unsigned int *)addr;
788 ecam_config(struct pci_access *a)
790 pci_define_param(a, "devmem.path", PCI_PATH_DEVMEM_DEVICE, "Path to the /dev/mem device");
791 pci_define_param(a, "ecam.acpimcfg", PCI_PATH_ACPI_MCFG, "Path to the ACPI MCFG table");
792 pci_define_param(a, "ecam.efisystab", PCI_PATH_EFI_SYSTAB, "Path to the EFI system table");
793 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
794 pci_define_param(a, "ecam.bsd", "1", "Use BSD kenv or sysctl to find ACPI MCFG table");
796 #if defined(__amd64__) || defined(__i386__)
797 pci_define_param(a, "ecam.x86bios", "1", "Scan x86 BIOS memory for ACPI MCFG table");
799 pci_define_param(a, "ecam.addrs", "", "Physical addresses of memory mapped PCIe ECAM interface"); /* format: [domain:]start_bus[-end_bus]:start_addr[+length],... */
803 ecam_detect(struct pci_access *a)
805 int use_addrs = 1, use_acpimcfg = 1, use_efisystab = 1, use_bsd = 1, use_x86bios = 1;
806 const char *devmem = pci_get_param(a, "devmem.path");
807 const char *acpimcfg = pci_get_param(a, "ecam.acpimcfg");
808 const char *efisystab = pci_get_param(a, "ecam.efisystab");
809 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
810 const char *bsd = pci_get_param(a, "ecam.bsd");
812 #if defined(__amd64__) || defined(__i386__)
813 const char *x86bios = pci_get_param(a, "ecam.x86bios");
815 const char *addrs = pci_get_param(a, "ecam.addrs");
821 a->debug("ecam.addrs was not specified...");
827 ret = glob(acpimcfg, GLOB_NOCHECK, NULL, &mcfg_glob);
830 if (access(mcfg_glob.gl_pathv[0], R_OK))
832 a->debug("cannot access acpimcfg: %s: %s...", mcfg_glob.gl_pathv[0], strerror(errno));
835 globfree(&mcfg_glob);
839 a->debug("glob(%s) failed: %d...", acpimcfg, ret);
846 if (access(efisystab, R_OK))
849 a->debug("cannot access efisystab: %s: %s...", efisystab, strerror(errno));
853 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
854 if (strcmp(bsd, "0") == 0)
856 a->debug("not using BSD kenv/sysctl...");
863 #if defined(__amd64__) || defined(__i386__)
864 if (strcmp(x86bios, "0") == 0)
866 a->debug("not using x86 BIOS...");
873 if (!use_addrs && !use_acpimcfg && !use_efisystab && !use_bsd && !use_x86bios)
875 a->debug("no ecam source provided");
879 if (!validate_addrs(addrs))
881 a->debug("ecam.addrs has invalid format %s", addrs);
885 if (access(devmem, R_OK))
887 a->debug("cannot access physical memory via %s: %s", devmem, strerror(errno));
892 a->debug("using %s with ecam addresses %s", devmem, addrs);
894 a->debug("using %s with%s%s%s%s%s%s", devmem, use_acpimcfg ? " acpimcfg=" : "", use_acpimcfg ? acpimcfg : "", use_efisystab ? " efisystab=" : "", use_efisystab ? efisystab : "", use_bsd ? " bsd" : "", use_x86bios ? " x86bios" : "");
900 ecam_init(struct pci_access *a)
902 const char *devmem = pci_get_param(a, "devmem.path");
903 const char *acpimcfg = pci_get_param(a, "ecam.acpimcfg");
904 const char *efisystab = pci_get_param(a, "ecam.efisystab");
905 #if defined (__FreeBSD__) || defined (__DragonFly__) || defined(__NetBSD__)
906 const char *bsd = pci_get_param(a, "ecam.bsd");
908 #if defined(__amd64__) || defined(__i386__)
909 const char *x86bios = pci_get_param(a, "ecam.x86bios");
911 const char *addrs = pci_get_param(a, "ecam.addrs");
912 struct acpi_mcfg *mcfg = NULL;
913 struct ecam_aux *aux = NULL;
918 volatile void *test_reg;
920 pagesize = sysconf(_SC_PAGESIZE);
922 a->error("Cannot get page size: %s.", strerror(errno));
924 if (!validate_addrs(addrs))
925 a->error("Option ecam.addrs has invalid address format \"%s\".", addrs);
927 a->fd = open(devmem, (a->writeable ? O_RDWR : O_RDONLY) | O_DSYNC);
929 a->error("Cannot open %s: %s.", devmem, strerror(errno));
933 #if defined (__FreeBSD__) || defined (__DragonFly__)
934 if (strcmp(bsd, "0") != 0)
937 #if defined(__amd64__) || defined(__i386__)
938 if (strcmp(x86bios, "0") != 0)
941 mcfg = find_mcfg(a, acpimcfg, efisystab, use_bsd, use_x86bios);
943 a->error("Option ecam.addrs was not specified and ACPI MCFG table cannot be found.");
946 aux = pci_malloc(a, sizeof(*aux));
952 get_mcfg_allocation(mcfg, 0, &test_domain, &test_bus, NULL, NULL, NULL);
954 parse_next_addrs(addrs, NULL, &test_domain, &test_bus, NULL, NULL, NULL);
957 if (!mmap_reg(a, 0, test_domain, test_bus, 0, 0, 0, &test_reg))
958 a->error("Cannot map ecam region: %s.", errno ? strerror(errno) : "Unknown error");
962 ecam_cleanup(struct pci_access *a)
964 struct ecam_aux *aux = a->aux;
970 pci_mfree(aux->mcfg);
978 ecam_scan(struct pci_access *a)
980 const char *addrs = pci_get_param(a, "ecam.addrs");
981 struct ecam_aux *aux = a->aux;
986 segments = pci_malloc(a, 0xFFFF/8);
987 memset(segments, 0, 0xFFFF/8);
991 count = get_mcfg_allocations_count(aux->mcfg);
992 for (i = 0; i < count; i++)
993 segments[aux->mcfg->allocations[i].pci_segment / 32] |= 1 << (aux->mcfg->allocations[i].pci_segment % 32);
999 if (parse_next_addrs(addrs, &addrs, &domain, NULL, NULL, NULL, NULL))
1000 segments[domain / 32] |= 1 << (domain % 32);
1004 for (i = 0; i < 0xFFFF/32; i++)
1008 for (j = 0; j < 32; j++)
1009 if (segments[i] & (1 << j))
1010 pci_generic_scan_domain(a, 32*i + j);
1013 pci_mfree(segments);
1017 ecam_read(struct pci_dev *d, int pos, byte *buf, int len)
1024 if (len != 1 && len != 2 && len != 4)
1025 return pci_generic_block_read(d, pos, buf, len);
1027 if (!mmap_reg(d->access, 0, d->domain, d->bus, d->dev, d->func, pos, ®))
1033 buf[0] = readb(reg);
1036 ((u16 *) buf)[0] = readw(reg);
1039 ((u32 *) buf)[0] = readl(reg);
1047 ecam_write(struct pci_dev *d, int pos, byte *buf, int len)
1054 if (len != 1 && len != 2 && len != 4)
1055 return pci_generic_block_read(d, pos, buf, len);
1057 if (!mmap_reg(d->access, 1, d->domain, d->bus, d->dev, d->func, pos, ®))
1063 writeb(buf[0], reg);
1066 writew(((u16 *) buf)[0], reg);
1069 writel(((u32 *) buf)[0], reg);
1076 struct pci_methods pm_ecam = {
1078 "Raw memory mapped access using PCIe ECAM interface",
1084 pci_generic_fill_info,
1087 NULL, /* read_vpd */
1088 NULL, /* init_dev */
1089 NULL /* cleanup_dev */