summaryrefslogtreecommitdiffstats
path: root/src/scriptfile.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 23:08:53 +0200
committerChristian Brabandt <cb@256bit.org>2023-08-17 23:08:53 +0200
commit008c91537b55835aa91cd8fbe1a139256581da31 (patch)
treee9826ea3e0ab6bddc2d6dbdd8c2caa1b4c71de87 /src/scriptfile.c
parentbfe377b8f2d080e5f85c8cbecf3533456e1d6312 (diff)
patch 9.0.1730: passing multiple patterns to runtime not workingv9.0.1730
Problem: passing multiple patterns to runtime not working Solution: prepend prefix to each argument separately closes: #12617 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Diffstat (limited to 'src/scriptfile.c')
-rw-r--r--src/scriptfile.c52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c
index 8a42db9202..37d57e51e9 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -404,18 +404,19 @@ find_script_callback(char_u *fname, void *cookie)
#endif
/*
- * Find the file "name" in all directories in "path" and invoke
+ * Find the patterns in "name" in all directories in "path" and invoke
* "callback(fname, cookie)".
- * "name" can contain wildcards.
+ * "prefix" is prepended to each pattern in "name".
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
* When "flags" has DIP_DIR: find directories instead of files.
* When "flags" has DIP_ERR: give an error message if there is no match.
*
- * return FAIL when no file could be sourced, OK otherwise.
+ * Return FAIL when no file could be sourced, OK otherwise.
*/
int
do_in_path(
char_u *path,
+ char *prefix,
char_u *name,
int flags,
void (*callback)(char_u *fname, void *ck),
@@ -447,8 +448,12 @@ do_in_path(
if (p_verbose > 10 && name != NULL)
{
verbose_enter();
- smsg(_("Searching for \"%s\" in \"%s\""),
- (char *)name, (char *)path);
+ if (*prefix != NUL)
+ smsg(_("Searching for \"%s\" under \"%s\" in \"%s\""),
+ (char *)name, prefix, (char *)path);
+ else
+ smsg(_("Searching for \"%s\" in \"%s\""),
+ (char *)name, (char *)path);
verbose_leave();
}
@@ -479,9 +484,10 @@ do_in_path(
if (!did_one)
did_one = (cookie == NULL);
}
- else if (buflen + STRLEN(name) + 2 < MAXPATHL)
+ else if (buflen + 2 + STRLEN(prefix) + STRLEN(name) < MAXPATHL)
{
add_pathsep(buf);
+ STRCAT(buf, prefix);
tail = buf + STRLEN(buf);
// Loop over all patterns in "name"
@@ -559,35 +565,17 @@ do_in_path_and_pp(
void *cookie)
{
int done = FAIL;
- char_u *s;
- int len;
- char *start_dir = "pack/*/start/*/%s";
- char *opt_dir = "pack/*/opt/*/%s";
if ((flags & DIP_NORTP) == 0)
- done = do_in_path(path, name, flags, callback, cookie);
+ done = do_in_path(path, "", name, flags, callback, cookie);
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
- {
- len = (int)(STRLEN(start_dir) + STRLEN(name));
- s = alloc(len);
- if (s == NULL)
- return FAIL;
- vim_snprintf((char *)s, len, start_dir, name);
- done = do_in_path(p_pp, s, flags, callback, cookie);
- vim_free(s);
- }
+ done = do_in_path(p_pp, "pack/*/start/*/", name, flags, callback,
+ cookie);
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
- {
- len = (int)(STRLEN(opt_dir) + STRLEN(name));
- s = alloc(len);
- if (s == NULL)
- return FAIL;
- vim_snprintf((char *)s, len, opt_dir, name);
- done = do_in_path(p_pp, s, flags, callback, cookie);
- vim_free(s);
- }
+ done = do_in_path(p_pp, "pack/*/opt/*/", name, flags, callback,
+ cookie);
return done;
}
@@ -899,7 +887,7 @@ add_pack_plugin(char_u *fname, void *cookie)
void
add_pack_start_dirs(void)
{
- do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
+ do_in_path(p_pp, "", (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
add_pack_plugin, &APP_ADD_DIR);
}
@@ -910,7 +898,7 @@ add_pack_start_dirs(void)
load_start_packages(void)
{
did_source_packages = TRUE;
- do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
+ do_in_path(p_pp, "", (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
add_pack_plugin, &APP_LOAD);
}
@@ -957,7 +945,7 @@ ex_packadd(exarg_T *eap)
vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
// The first round don't give a "not found" error, in the second round
// only when nothing was found in the first round.
- res = do_in_path(p_pp, (char_u *)pat,
+ res = do_in_path(p_pp, "", (char_u *)pat,
DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
vim_free(pat);
7 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  pti.c - PTI driver for cJTAG data extration
 *
 *  Copyright (C) Intel 2010
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * The PTI (Parallel Trace Interface) driver directs trace data routed from
 * various parts in the system out through the Intel Penwell PTI port and
 * out of the mobile device for analysis with a debugging tool
 * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
 * compact JTAG, standard.
 */

#include <linux/init.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/console.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/pci.h>
#include <linux/mutex.h>
#include <linux/miscdevice.h>
#include <linux/intel-pti.h>
#include <linux/slab.h>
#include <linux/uaccess.h>

#define DRIVERNAME		"pti"
#define PCINAME			"pciPTI"
#define TTYNAME			"ttyPTI"
#define CHARNAME		"pti"
#define PTITTY_MINOR_START	0
#define PTITTY_MINOR_NUM	2
#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
#define MODEM_BASE_ID		71   /* modem master ID address    */
#define CONTROL_ID		72   /* control master ID address  */
#define CONSOLE_ID		73   /* console master ID address  */
#define OS_BASE_ID		74   /* base OS master ID address  */
#define APP_BASE_ID		80   /* base App master ID address */
#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
#define APERTURE_14		0x3800000 /* offset to first OS write addr */
#define APERTURE_LEN		0x400000  /* address length */

struct pti_tty {
	struct pti_masterchannel *mc;
};

struct pti_dev {
	struct tty_port port[PTITTY_MINOR_NUM];
	unsigned long pti_addr;
	unsigned long aperture_base;
	void __iomem *pti_ioaddr;
	u8 ia_app[MAX_APP_IDS];
	u8 ia_os[MAX_OS_IDS];
	u8 ia_modem[MAX_MODEM_IDS];
};

/*
 * This protects access to ia_app, ia_os, and ia_modem,
 * which keeps track of channels allocated in
 * an aperture write id.
 */
static DEFINE_MUTEX(alloclock);

static const struct pci_device_id pci_ids[] = {
		{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B)},
		{0}
};

static struct tty_driver *pti_tty_driver;
static struct pti_dev *drv_data;

static unsigned int pti_console_channel;
static unsigned int pti_control_channel;

/**
 *  pti_write_to_aperture()- The private write function to PTI HW.
 *
 *  @mc: The 'aperture'. It's part of a write address that holds
 *       a master and channel ID.
 *  @buf: Data being written to the HW that will ultimately be seen
 *        in a debugging tool (Fido, Lauterbach).
 *  @len: Size of buffer.
 *
 *  Since each aperture is specified by a unique
 *  master/channel ID, no two processes will be writing
 *  to the same aperture at the same time so no lock is required. The
 *  PTI-Output agent will send these out in the order that they arrived, and
 *  thus, it will intermix these messages. The debug tool can then later
 *  regroup the appropriate message segments together reconstituting each
 *  message.
 */
static void pti_write_to_aperture(struct pti_masterchannel *mc,
				  u8 *buf,
				  int len)
{
	int dwordcnt;
	int final;
	int i;
	u32 ptiword;
	u32 __iomem *aperture;
	u8 *p = buf;

	/*
	 * calculate the aperture offset from the base using the master and
	 * channel id's.
	 */
	aperture = drv_data->pti_ioaddr + (mc->master << 15)
		+ (mc->channel << 8);

	dwordcnt = len >> 2;
	final = len - (dwordcnt << 2);	    /* final = trailing bytes    */
	if (final == 0 && dwordcnt != 0) {  /* always need a final dword */
		final += 4;
		dwordcnt--;
	}

	for (i = 0; i < dwordcnt; i++) {
		ptiword = be32_to_cpu(*(u32 *)p);
		p += 4;
		iowrite32(ptiword, aperture);
	}

	aperture += PTI_LASTDWORD_DTS;	/* adding DTS signals that is EOM */

	ptiword = 0;
	for (i = 0; i < final; i++)
		ptiword |= *p++ << (24-(8*i));

	iowrite32(ptiword, aperture);
	return;
}

/**
 *  pti_control_frame_built_and_sent()- control frame build and send function.
 *
 *  @mc:          The master / channel structure on which the function
 *                built a control frame.
 *  @thread_name: The thread name associated with the master / channel or
 *                'NULL' if using the 'current' global variable.
 *
 *  To be able to post process the PTI contents on host side, a control frame
 *  is added before sending any PTI content. So the host side knows on
 *  each PTI frame the name of the thread using a dedicated master / channel.
 *  The thread name is retrieved from 'current' global variable if 'thread_name'
 *  is 'NULL', else it is retrieved from 'thread_name' parameter.
 *  This function builds this frame and sends it to a master ID CONTROL_ID.
 *  The overhead is only 32 bytes since the driver only writes to HW
 *  in 32 byte chunks.
 */
static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc,
					     const char *thread_name)
{
	/*
	 * Since we access the comm member in current's task_struct, we only
	 * need to be as large as what 'comm' in that structure is.
	 */
	char comm[TASK_COMM_LEN];
	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
					      .channel = 0};
	const char *thread_name_p;
	const char *control_format = "%3d %3d %s";
	u8 control_frame[CONTROL_FRAME_LEN];

	if (!thread_name) {
		if (!in_interrupt())
			get_task_comm(comm, current);
		else
			strncpy(comm, "Interrupt", TASK_COMM_LEN);

		/* Absolutely ensure our buffer is zero terminated. */
		comm[TASK_COMM_LEN-1] = 0;
		thread_name_p = comm;
	} else {
		thread_name_p = thread_name;
	}

	mccontrol.channel = pti_control_channel;
	pti_control_channel = (pti_control_channel + 1) & 0x7f;

	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
		mc->channel,